https://htmx.org logo
Join Discord
Powered by
# htmx-general
  • g

    great-gold-37694

    02/07/2023, 10:43 PM
    🙏
  • g

    great-gold-37694

    02/07/2023, 11:52 PM
    That did the trick after working out how my htmx code itself was borked 😅
  • t

    thankful-addition-60522

    02/08/2023, 8:36 AM
    how do i import htmx via esbuild?
  • s

    stocky-dentist-80693

    02/08/2023, 9:25 AM
    This works for me:
    Copy code
    import 'htmx.org/dist/htmx.js';
    const htmx = window.htmx;
  • t

    thankful-addition-60522

    02/08/2023, 9:45 AM
    thanks, but where
    htmx
    var goes?
  • t

    thankful-addition-60522

    02/08/2023, 9:45 AM
    it's not like it references the import, right?
  • s

    stocky-dentist-80693

    02/08/2023, 9:48 AM
    To be honest, I have no idea. I think it's just the combination of how htmx is exported + how esbuild interprets it. I think I tried to
    import htmx from 'htmx.org/dist/htmx.js
    , and reference that var, but it didn't work.
  • t

    thankful-addition-60522

    02/08/2023, 10:00 AM
    yeah, same
  • g

    gorgeous-ocean-41861

    02/08/2023, 10:39 AM
    Hey folks, I’m having some trouble getting an async handler working with the
    wsConfigSend
    event in the ws extension (use case: to encrypt a message before it’s sent to the server for end-to-end encryption). It looks like the handler is called but not awaited. I tried awaiting the function in the handler declaration but that didn’t work. I then tried preventing the default event and using the
    event.detail.socketWrapper
    to manually send the message but it doesn’t even look like that’s being triggered. (From my tests, it looks like the handler is being garbage collected very soon after it’s run, even before it hits an await statement inside it.) (I’m using Alpine.js to add the handler.) Any ideas?
    Copy code
    html
    <div 
      id='chat'
      hx-ext='ws'
      ws-connect='/chat.socket'
      x-data='{ showPlaceholder: true }'
      @htmx:ws-config-send='encryptMessage'
    >
    …
    </div>
    Copy code
    js
    async function encryptMessage (event) {
      const parameters = event.detail.parameters
      const ourPrivateKey = localStorage.getItem('secret')
      const encryptedMessage = await encryptMessageForDomain(parameters.text, ourPrivateKey, parameters.domain)
      event.detail.parameters['text'] = encryptedMessage
    }
  • r

    ripe-action-67367

    02/08/2023, 10:54 AM
    Yes, htmx does not use promises, so it is not possible to make async event handler unfortunately. As for collected socketWrapper, I'll take a look at that one
  • g

    gorgeous-ocean-41861

    02/08/2023, 11:00 AM
    @ripe-action-67367 Ah, I didn’t realise that. Do you know if promise support is on the roadmap? (And thanks for looking into it, appreciate it.) 🙂
  • r

    ripe-action-67367

    02/08/2023, 11:00 AM
    for htmx 2.0 most likely
  • g

    gorgeous-ocean-41861

    02/08/2023, 11:01 AM
    @ripe-action-67367 Cool, thanks. I’ll read up on 2.0 🙂
  • r

    ripe-action-67367

    02/08/2023, 11:01 AM
    Actually, I don't think it is possible to await for event handlers
  • r

    ripe-action-67367

    02/08/2023, 11:02 AM
    htmx uses standard html custom events dispatcher, which, as far as I know, has no way to await for event listeners
  • g

    gorgeous-ocean-41861

    02/08/2023, 11:09 AM
    Right, you can’t, basic example, onclick='await something()' but I’m still seeing different behaviour when adding an asynchronous handler (where the handler is being garbage collected before completing). I’ll have a think about how best to pause the send event so that an asynchronous transformation can be applied to the message contents. At the very least, I need it to implement end-to-end encryption 🙂
  • g

    gorgeous-ocean-41861

    02/08/2023, 11:11 AM
    (Maybe the issue is that the configuration method should be a separate attribute that is awaited instead of a standard event handler. In any case, I’ll have a play. Thanks again.)
  • r

    ripe-action-67367

    02/08/2023, 11:12 AM
    A quick repro showed, that it's not garbage collected. It's just a bug on the extension side. The wrapper is not correctly initialized. I'll have a fix later
  • r

    ripe-action-67367

    02/08/2023, 11:16 AM
    As for GC, I don't think it is the case, since the wrapper is referenced in event object, which is referenced in event handler arguments, which is captured in the async continuation closure. It would be a V8 bug if it was the case
  • g

    gorgeous-ocean-41861

    02/08/2023, 11:22 AM
    Cool, thanks (so I guess I should be able to cancel the event, create my own message, and use the socket wrapper to send it).
  • r

    ripe-action-67367

    02/08/2023, 11:27 AM
    Yes, that was the intention
  • g

    gorgeous-ocean-41861

    02/08/2023, 2:21 PM
    Does anyone know what version of Node is supported by htmx? I’m trying to run npm install and it’s failing for me both on Node latest (19.6.0) and on Node LTS (18.14.0). Looks like node-sass is the culprit. Stack traces: https://github.com/bigskysoftware/htmx/issues/1243#issuecomment-1422668704
  • g

    gorgeous-ocean-41861

    02/08/2023, 2:36 PM
    Right, to answer my own question (went backwards from 18 until I found it)… it’s Node 15. Will open an issue and a pull request to add the supported engine to package.json.
  • g

    gorgeous-ocean-41861

    02/08/2023, 3:00 PM
    (Sadly, npm apparently doesn’t warn of version mismatch until after attempting to install dependencies so
    engines
    declarations had no effect so I didn’t include it but at least documented the Python 2 requirement in a PR.)
  • g

    gorgeous-ocean-41861

    02/08/2023, 3:06 PM
    @ripe-action-67367 I’ve got htmx up and running with all tests passing. Should I write a failing test and have a go at fixing the undefined
    socketWrapper
    methods or would you rather I left it to you?
  • r

    ripe-action-67367

    02/08/2023, 3:08 PM
    If you got time, please do. The relevant part is at src/ext/ws.js:179.
  • g

    gorgeous-ocean-41861

    02/08/2023, 3:08 PM
    Thanks, I’ll have a look at it now then. Appreciate the pointer 🙂
  • r

    ripe-action-67367

    02/08/2023, 3:59 PM
    Also, this https://discord.com/channels/725789699527933952/725789747212976259/999997871367651329
  • g

    gorgeous-ocean-41861

    02/08/2023, 4:05 PM
    Haha, indeed 🙂
  • g

    gorgeous-ocean-41861

    02/08/2023, 4:34 PM
    Right, it was scope (of course), and a tiny typo. Would love a code review when you get a moment, @ripe-action-67367 🙂 https://github.com/bigskysoftware/htmx/pull/1247
1...101310141015...1146Latest