-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update hx-swap-oob documentation/examples #2560
Update hx-swap-oob documentation/examples #2560
Conversation
Add <tbody> around returned <tr> in example 2 (hx-swap-oob) since this is required by strict browser engines as described - https://stackoverflow.com/questions/76612680/htmx-hx-swap-oob-adding-a-new-table-row-only-adds-the-tds-and-not-the-wrappin bigskysoftware#1900 bigskysoftware#1198
From my basic tests what I saw was that the element with the
Only the two Based on all these observations IMHO this is not a bug in htmx as others suspected but just a bug in the documentation on how to use hx-swap-oob since it makes no mention or suggestion of the containing element not being inserted. |
I hope that my previous two messages weren't too rambling they were done very late at night/early in the morning for me, I actually thought out a more generalized way of saying what I was trying to say - If I return the following
Then based on the documentation and all the given examples and other behavior of htmx I would expect the result of this action to be:
Based on my tests what actually happens is
Thus Based on some further testing the only As stated previously I do not think this is a bug in htmx, rather it is an omission of a behavior in the documentation. |
Yeah, table stuff is a nightmare, I appreciate you doing this. Would mind adding a note in the documentation about why the tbody is necessary? |
Hey it's been a while since I ran all these tests and htmx 2.0 was also released in the mean time, I'll try to make some time to test again and expand the documentation because I may be wrong but I seem to recall that some time after filing this I ran into an opposite case with oob-swap. |
Sure thing, I'm gonna close this for now, and feel free to re-open if/when you get around to it :) |
Hey just swapped [email protected] into my test code and the issue still exists. Based on my finding the containing tags is are stripped, where the context of what the containing tags are and what the target is also matters examples:
|
So adding @alexpetros please consider re-opening and merging, if you have suggestions on how to document it better I am more than happy to do so, the PR as is makes sure that the example in the documentation works. |
Unfortunately, the table handling is just wonky all around. Probably some of it is our fault, some of it is because tables do not play nice with partial page replacement at all. We have random caveats all around the documentation about it. But, we're happy to have the specific example fixed! If you rebase I'll merge it. |
But should the other examples also be added? |
Taking a look at the recommendations in the oob-swap docs—would most of these be solved by just using a |
Just tested it on firefox 129 with htmx 2.0.2 and no, it would seem that that documentation is also inaccurate:
where The following (not according to the docs):
results in the whole reply being ignored for all |
I'm rebasing and will try to see when I have time to read both pages and maybe update them more. Either way the issue is not just tables and not just elements that
since it would seem all containers are stripped. |
💡 |
Yes, and it's definitely a little bit of trail an error to get a sense of what gets stripped and what doesn't. It's not perfect. My main feeling about this is that some of these details are important, and some of them you don't want to overwhelm the documentation with. Like the oob section is literally called "troublesome tables", which very effectively warns you: "tables will be annoying". So we'd love more precise documentation on this, if you think you can do it without sacrificing the general approachability. |
I see that someone else already got this change merged - a191588 I'll try to have a look at the OOB page. |
someone reported the same issue in #2790 and we had a discussion there. I put up a small documentation update in #2806 that addresses the same core issue. Your documentation is similar but has more detail on the tables situations. So i'm not too fussed which PR wins the day. I also have #2823 addresses some of the confusion around the fact it places the attribute into the final page which is not ideal. I also just added some SVG examples in recently. There is much confusion around this behavior because it is not quite the same as full page load behavior. I notice one issue when you were testing you had : <template>
<TAG hx-swap-oob="#target">
content
</TAG>
</template> And this is missing the format : which i think may default to innerHTML which explains why it was doing inner swaps. There are separate issues at play here. First is that there is a inline swap called Which leads to the second issue at play here which is that many elements have rules when converting them from text into a HTML document that htmx can work with to do DOM replacements with. You have to live by the browsers html parsers rules which is where template, table, span and div wrappers have to come in. The rules are not that complicated but it is still confusing and listing every combination and trying to explain everything to the users of the documentation is probably going to be too much. But maybe your PR may be a good balance of this. Users knowing they can wrap the sensitive content in the proper wrapper is ideal. Finally there is some quirks in the way it has to process things of different content types. often with OOB swaps you have the main response with one type of component and then you have some oob swap content with a different tag type and they do not always mix well which I think is why |
Hey @MichaelWest22 this PR was superseded by #2889 which IMHO is a much better addition to the documentation (though lacking in the department of nifty titles). As for the issue you raised about the missing |
I'm very confused now, I just realized that the documentation does say that I don't mind doing a further clarification on that in #2889 but I don't know what I would need to write now with all these contradictions. |
yeah the |
That is very strange behavior IMHO, because it makes absolutely no sense to use |
I would go re-read the first couple of paragraphs in the oob-swap-oob documentation which you may have missed while going down the very complex rabbit hole. The most common default use case for oob-swap-oob is to just use ="true" where you place this on a element with a id. like: <div id="alerts" hx-swap-oob="true">
Saved!
</div> when there is no css selector falls back to using the id of the tag so this tag magically gets swapped into the page and overwrites the alerts element with just this one simple attribute added. The other alternative swap and css selector options are the other few cases where a more complex solution is required where you want to insert inner html somewhere instead of inline replacing an existing element. |
Add around returned in example 2 (hx-swap-oob) since this is required by strict browser engines as described - https://stackoverflow.com/questions/76612680/htmx-hx-swap-oob-adding-a-new-table-row-only-adds-the-tds-and-not-the-wrappin
Description
This brings the example in the documentation in line with what works in Firefox (126) and Chrome (124), for my enabling/disabling
htmx.config.useTemplateFragments = true;
has no effect but enclosing the hx-swap-oob in the appropriate tags did work.Corresponding issue:
#1900
#1198
Testing
This is documentation but I used the following PHP/HTML to test my theories and based on it there is I think even more that needs to be changed in the documentation but I am unsure of the way to formulate things:
Checklist
master
for website changes,dev
forsource changes)
approved via an issue
* [ ] I ran the test suite locally (Not applicable for a documentation changenpm run test
) and verified that it succeeded