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

oob swap via extension fails if parent had [hx-swap]="outerHTML" #1419

Closed
anpin opened this issue Apr 29, 2023 · 1 comment
Closed

oob swap via extension fails if parent had [hx-swap]="outerHTML" #1419

anpin opened this issue Apr 29, 2023 · 1 comment

Comments

@anpin
Copy link

anpin commented Apr 29, 2023

I'm using htmx 1.9.2 with htmx-signalr and it fails on this line

newElt = parentElt(target).firstChild;
with

023-04-29T12:36:15.320Z] Error: A callback for the method 'component-update' threw error 'TypeError: Cannot read properties of null (reading 'firstChild')'.

If element received via signalr had hx-swap-oob="outerHTML" and some parent of the target had hx-swap="outerHTML"

For example with such layout:

<div hx-ext="signalr" signalr-connect="/hub" > 
 <div id="second-level" hx-swap="outerHTML"> 
   <div id="component" signalr-subscribe="component-update" hx-target="this" > <div/>
  <div/>
<div/>

When extension receives

   <div id="component" signalr-subscribe="component-update" hx-target="this" hx-swap-oob="outerHTML" >Some new content here<div/>

It replaces the content correctly, but then throws above exception after which any further updates would be ignored.

The workaround is to set hx-swap="innerhtml" on the target node in the original layout [1], so call to getSwapSpecification here returns innerhtml.

[1] Workaround

<div hx-ext="signalr" signalr-connect="/hub" > 
 <div id="second-level" hx-swap="outerHTML"> 
   <div id="component" signalr-subscribe="component-update" hx-target="this" hx-swap="innerhtml"> <div/>
  <div/>
<div/>

(Please let me know if the issue should be moved to the extension repo)

@Renerick
Copy link
Collaborator

Yes, hx-signalr is supported by me, not bigskysoftware, please move this issue to the repo, I'll take a look

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

2 participants