Skip to content

Conversation

seo-rii
Copy link

@seo-rii seo-rii commented Aug 25, 2025

Export event object of PopStateEvent into navigation handler callback if navigation is popstate.

Closes #13169.


Please don't delete this checklist! 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

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

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Aug 25, 2025

🦋 Changeset detected

Latest commit: 3b65197

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

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

@svelte-docs-bot
Copy link

@eltigerchino eltigerchino added the feature / enhancement New feature or request label Aug 25, 2025
@eltigerchino
Copy link
Member

I'm wondering if it's worth exposing the entire event object instead of an individual property here. This would help us avoid this issue again if a new property is added.

@Rich-Harris
Copy link
Member

yeah we definitely shouldn't just add hasUAVisualTransition. navigation.event seems reasonable (and we can presumably even narrow the event type on navigation.type), though is it weird that the type of Navigation['event'] isn't NavigationEvent?

@seo-rii seo-rii changed the title feat: export hasUAVisualTransition of popStateEvent feat: export event of PopStateEvent for navigation handler Aug 27, 2025
@seo-rii
Copy link
Author

seo-rii commented Aug 28, 2025

@eltigerchino It seems more reasonable, so I've updated PR to expose entire event object.

@Rich-Harris
Copy link
Member

Thank you. I think this is closer but still not quite ready to merge:

  • The generic approach doesn't appear to give us any type safety benefits — if I refer to navigation.event inside a block like if (navigation.type === 'popstate') it should be typed as PopStateEvent. We need to use discriminated unions
  • We should add event: PointerEvent to navigations with type: 'link'

@seo-rii seo-rii changed the title feat: export event of PopStateEvent for navigation handler feat: expose event for navigation handler when navigation is popstate or link Aug 29, 2025
@seo-rii
Copy link
Author

seo-rii commented Aug 29, 2025

  • Sorry. I misunderstood that typescript could infer generic from fields.
  • I kept delta/event to other navigation types as undefined to avoid breaking changes.
  • I've added MouseEvent since link click event is click.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent view transition when browser hasUAVisualTransition
3 participants