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

fix: trigger again when window listener already handled #10611

Merged
merged 4 commits into from
Feb 23, 2024

Conversation

xxkl1
Copy link
Contributor

@xxkl1 xxkl1 commented Feb 22, 2024

fixes #10271

the window case was not handle when query listener had handled.

why test ok in before pr #10307?

because window in event.composedPath() at jsdom is

// run in jsdom
const l = event.composedPath()
// log window in l is
Object [Window] {
  ...
}

but other case is

// run in jsdom
console.log(window)
// ->
Object [global] {
 ...
}

so event.composedPath().indexOf(window) is away equal -1.
the following code will skips the event handle and makes the test pass.

const handler_idx = path.indexOf(handler_element);
if (handler_idx === -1) {
// handle_idx can theoretically be -1 (happened in some JSDOM testing scenarios with an event listener on the window object)
// so guard against that, too, and assume that everything was handled at this point.
return;
}

it seems to be jsdom's bug, there is no way to test this case in jsdom.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Feb 22, 2024

🦋 Changeset detected

Latest commit: 7039ae1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

// This is the fallback document listener but the event was already handled
// -> ignore, but set handle_at to document so that we're resetting the event
// @ts-ignore
if (at_idx !== -1 && (handler_element === document || handler_element === window)) {
Copy link
Contributor

@trueadm trueadm Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just occurred to me that we should probably be using the ownerDocument from the target element because of iframes rather than the global document object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On first look I thought "yeah makes sense", but on second look: The fallback event listener is set to document, too - should that one be using container_target.ownerDocument, too? Either way, this sounds like something we can talk about separately.

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dummdidumm dummdidumm merged commit fc6666b into sveltejs:main Feb 23, 2024
6 of 8 checks passed
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.

Svelte 5: onkeydown event triggers more often than it should
3 participants