Skip to content

Router should ignore clicks from outside the app container #7763

@Rich-Harris

Description

@Rich-Harris

Describe the problem

I had a follow-up thought about #6914. In cases where people are using SvelteKit to generate embeds that sit in a larger application, it's necessary to come up with elaborate workarounds to prevent clicks in the main app nav (for example) being handled by SvelteKit's router.

If we instead only listened for click events coming from inside the part of the app SvelteKit controls, it would be very easy to embed SvelteKit apps elsewhere.

Describe the proposed solution

I'm pretty sure we would just need to replace

addEventListener('click', (event) => {
and other calls to addEventListener(...) with target.addEventListener(...).

The only downside I can see is that links inside src/app.html outside %sveltekit.body% wouldn't trigger the client-side router, but a) you can work around it if you really need to with goto, and b) i would be astonished if anyone was doing that. Technically a breaking change, of course, so we should do this quickly if we intend to do it at all.

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions