Skip to content
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

hx-swap="morph:outerHTML being treated as innerHTML #8

Closed
Hades32 opened this issue May 1, 2023 · 5 comments
Closed

hx-swap="morph:outerHTML being treated as innerHTML #8

Hades32 opened this issue May 1, 2023 · 5 comments

Comments

@Hades32
Copy link

Hades32 commented May 1, 2023

Hey @1cg,
when I use a hidden inner element to auto-refresh a component, I get infinitely nested elements. It seems like either the target is ignored or the modifier. Any thoughts?

<button
	id="mod-button"
	hx-get=/mod-queue'
	hx-trigger="click"
	hx-target="#root-container"
>
	{/* auto-refresh */}
	<span className="hidden" 
		hx-get="/components/my-button" 
		hx-target="closest button" 
		hx-swap="morph:outerHTML" 
		hx-trigger="every 5s"></span>

When I change it to hx-swap="outerHTML" it works as expected

@mossblaser
Copy link

Can confirm I've encountered this issue too!

@1cg
Copy link
Contributor

1cg commented May 5, 2023

what content is being returned by /components/my-button?

@mossblaser
Copy link

Ah-ha! I suspect I've found the issue here -- and its a simple documentation issue. To use idiomorph with htmx you need to use the version of the library which also includes a htmx extension binding not found in the default JS file on unpkg listed in the README. Instead you need to use: https://unpkg.com/idiomorph/dist/idiomorph-ext.min.js. It would be great to include this detail somewhere in the README since I'm sure plenty of folks will be coming to this repo looking to use this with htmx.

Aside: Unfortunately, htmx does not emit a warning when you hx-ext an undefined extension nor when you use a hx-swap. Instead htmx falls back on using the default swap mode (innerHTML) resulting in the apparently broken behaviour seen in this issue above. Perhaps this unlucky pair of 'sharp edges' are worth of fixing in htmx?

@Skinner927
Copy link

Just to add to @mossblaser 's great answer, you'll want to set hx-ext="morph".

@MichaelWest22
Copy link
Collaborator

I think we can close this issue. The documentation seems to be up to date now. The behavior of doing an innerHTML morph is the fallback when an invalid link to the extension script is used or the hx-ext morph attribute is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants