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

    green-activity-6102

    10/07/2022, 5:04 PM
    ive just realized this is a lot more complicated if i want to actually mind all of the other
    hx-
    attributes during my manual swap... i can do a simple innerHTML replacement but that may not be what the srcElement specified
  • g

    green-activity-6102

    10/07/2022, 5:40 PM
    would be handy in the internalAPI
    swap()
    function was on the public API πŸ˜„
  • m

    mysterious-toddler-20573

    10/07/2022, 5:53 PM
    πŸ˜‘
  • g

    green-activity-6102

    10/07/2022, 6:49 PM
    the plot thickens... because the HTML being swapped in also has
    hx-
    attrs, it needs to be processed after it's swapped.. this is turning out to be more complicated than i had hoped
  • g

    green-activity-6102

    10/07/2022, 6:49 PM
    i got the swap working, but then the control is dead after the swap
  • m

    mysterious-toddler-20573

    10/07/2022, 7:04 PM
    I believe if you return the swapped elements they should be processed
  • g

    green-activity-6102

    10/07/2022, 7:08 PM
    ohh interesting, let me check that
  • g

    green-activity-6102

    10/07/2022, 7:10 PM
    that doesnt appear to be true when using the
    onEvent
    extension hook
  • g

    green-activity-6102

    10/07/2022, 7:11 PM
    maybe i should be using
    handleSwap
    πŸ€”
  • g

    green-activity-6102

    10/07/2022, 7:24 PM
    nah nevermind that doesnt work because i dont get the original target selector -- only the first target element
  • g

    green-activity-6102

    10/07/2022, 7:24 PM
    i got it working using
    onEvent
    and calling
    process
    on the swapped node after i swap it πŸ‘
  • s

    square-oyster-36295

    10/07/2022, 8:30 PM
    Hi, does anyone here have experience with how to effectively use HTMX to dynamically replace the content by an Ajax request, but with the fact that the replaced HTML also contains ? I have the feeling from using HTMX in the past that HTMX removes tags from the replaced HTML, what is big problem for our use-cases. We also need to ensure that hx-boost or other content replacement functions updates the and add , or tags for CSS styles. Is here someone with recommendations related to this?
  • m

    mysterious-toddler-20573

    10/07/2022, 9:34 PM
    script tags in the content will be executed
  • m

    mysterious-toddler-20573

    10/07/2022, 9:35 PM
    merging the head tag entirely, including scripts, etc. doesn't currently work. I'd like to make it work at some point, but it's a ways off.
  • m

    mysterious-toddler-20573

    10/07/2022, 9:35 PM
    sorry πŸ˜‘
  • m

    most-flag-2080

    10/07/2022, 10:02 PM
    Hotwire is laying the bricks
  • m

    most-flag-2080

    10/07/2022, 10:02 PM
    follow the lead
  • s

    square-oyster-36295

    10/07/2022, 10:02 PM
    Thank you for your response @mysterious-toddler-20573. We want to prepare some plugins for the Astro framework for nice integration with HTMX. This functionality is absolutely critical. What do you see as the biggest risk/problem for implementing CSS/JS integration in ? One of the possible implementations that came to my mind is to implement an HTMX extension, which would check, as part of the content replacement, whether there are any , or tags in the new HTML (retrieved by Ajax) that have not yet been inserted in our page and if not, create these tags at the end of the HTML and add them to the DOM. In order to be able to effectively verify whether the given script (either inline or external via the src attribute) has already been inserted into the HTML, we would add some special HTML element with the ID "htmx-extras" as the last element in the . What do you think about this solution?
  • s

    square-oyster-36295

    10/07/2022, 10:13 PM
    Thank you for your reaction @most-flag-2080. We researched HTMX, Unpoly and HotWire, and we like HTMX the most. Unpoly is very powerful, but the data is very large. However, all of these frameworks have their strengths and weaknesses, and unfortunately, not one of them is universal enough.
  • s

    square-oyster-36295

    10/07/2022, 10:15 PM
    In the next few weeks, I will try to implement in them as extensions what we basically lack.
  • m

    mysterious-toddler-20573

    10/07/2022, 10:29 PM
    If you hook into the
    htmx:afterRequest
    event: https://htmx.org/events/#htmx:afterRequest you can grab the xhr, get the content out and have a go at the header. @most-flag-2080 is right in this case: Turbolinks I believe has been doing this for a long time. The boost functionality was added to htmx as an afterthought, I was more focused on making HTML more expressive and it felt too "magical" to me, so I kept it simple and effectively said "load all your JS up front or inline (w/ hyperscript. for example").
  • m

    mysterious-toddler-20573

    10/07/2022, 10:30 PM
    I started buckling under when I added support for the title tag, and I've accepted that at some point I'll need to do a full header merge, but I have been putting it off
  • s

    square-oyster-36295

    10/07/2022, 10:57 PM
    I understand you @mysterious-toddler-20573. This is no longer a trivial task and will have its limits. It will not be possible to capture all situations perfectly. But I can imagine it as real. The newly discovered and tags (in loaded HTML by Ajax requests) for external styles could be inserted into the HTML before adding/replacing the HTML from the Ajax request. So, after replacing HTML, the content will be styled straight away and will not flicker. Scripts (both inline and external via the src attribute) would in turn be inserted in some clever way at the end of the HTML. Of course, in order to prevent the same JavaScript from being inserted and executed repeatedly, it would be possible to use some data attribute in the tag to set whether this javascript should be inserted and therefore interpreted again, even if it has already been inserted once before. To avoid solving this problem, Unpoly guides people to use
    up.compiler()
    (https://unpoly.com/up.compiler), which is quite an elegant way, but it also has certain limits for large projects, especially due to the impossibility of using lazy-loading techniques effectively. If we were not concerned with performance, of course we would load all the styles and JavaScripts for the entire website/application directly on the homepage, but this is not a suitable way.
  • m

    mysterious-toddler-20573

    10/07/2022, 11:01 PM
    Yep, the problem is interesting. I think we could do a "merge" where we compare the old and new content, probably w/ a dumb O(n^2) algorithm, merge in the new styles and scripts, remove the old ones
    b
    • 2
    • 2
  • m

    mysterious-toddler-20573

    10/07/2022, 11:02 PM
    throw in a few events for people to hook into on add/remove (to maybe filter, or de-init javascript) and I think it'd be pretty clean and not a ton of code
  • m

    mysterious-toddler-20573

    10/07/2022, 11:02 PM
    happy to help with it, I like implementing it as an extension in htmx 1 and looking on integrating it into the core for htmx 2 (2023, unfortunately)
  • s

    square-oyster-36295

    10/07/2022, 11:17 PM
    @mysterious-toddler-20573 - thank you very much for the consultation. In the coming weeks, during the implementation of one of our projects, I will try to prepare a functional proof-of-concept and I will consult it with you.
  • m

    mysterious-toddler-20573

    10/07/2022, 11:28 PM
    Thinking on it I wonder if it would dovetail with the idiomorph work, which implements morphing w proper node removal etc
  • b

    broad-baker-92644

    10/08/2022, 4:34 AM
    I’m using htmx to update a div in a datatable. It’s kind working but I have to refresh the page the see the update. I googled the problem. It seems I need to use htmx.process function. But I couldn’t figure out where to put it. Has anyone had the same issue before?
  • b

    brainy-ice-92385

    10/08/2022, 6:53 AM
    Yep the problem is interesting I think
1...847848849...1146Latest