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

feat: trigger oobErrorNoTarget for missing oob swap targets #2985

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

stenehall
Copy link

Description

Currently the parent of an oob-swap will not get an oobErrorNoTarget event when added to the hxOn event trigger.

Given the following code:

<ul hx-ext="ws" ws-connect="/ws" id="hosts" hx-on:htmx:oob-error-no-target="console.log('error triggered')></ul>

And the following message from the server

<tr id="some-id" hx-swap-oob="outerhtml:#none-existing-id">

Nothing will happen. But with this change the console.log will run.

Corresponding issue:

Testing

This was tested manually using a very similar code to the above. I was trying to figure out where a test would fit in hx-swap-oob.js but it wasn't immediately obvious to me. If you think the change is correct I will spend more time on figuring out a test for it.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@scrhartley
Copy link
Contributor

scrhartley commented Oct 27, 2024

For existing projects that were already using this on body as a general error mechanism,
it seems that it will now trigger multiple times due to event bubbling.
Additionally, if the target is body, will it trigger twice, once for the general event and once for the settle target event?

@stenehall
Copy link
Author

For existing projects that were already using this on body as a general error mechanism, it seems that it will now trigger multiple times due to event bubbling. Additionally, if the target is body, will it trigger twice, once for the general event and once for the settle target event?

Good questions. I'm not entirely sure how it will behave in relation to event bubbling nor body. But, I can spend a bit of time creating tests for this. If the general idea seems correct here.

To me the current behavior seems wrong, but the change might be a breaking change.

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

Successfully merging this pull request may close these issues.

2 participants