Skip to content

Route with no content is not torn down properly on navigation #2302

@OliverHGray

Description

@OliverHGray

Describe the bug

I have a route that when it is mounted it modifies some state and immediately redirects using goto. As result this route does not contain any html, it is purely for redirecting to the next page on the client.

The issue is that the code on the redirect page does not get torn down properly after the redirect, and as result can modify the state even though it is not active.

This only occurs in the built version and not the dev version.

Interestingly it only seems to remain active "once", in that if a store changes for a second time nothing will happen.

Reproduction

https://github.com/OliverHGray/sveltekit-empty-route-issue

To reproduce:

  1. Clone repo
  2. npm i
  3. npm run build
  4. npm run preview
  5. Navigate to app localhost:3000
  6. (You will immediately be redirected to page2)
  7. Click on the button

Expected: Nothing is printed in the console as all page2 does is update the store

Actual: The updated string is printed in the console as the code from the index route is still active.

Logs

No response

System Info

Don't think this is applicable as this issue happens if I build it locally or on GHA and running on all browsers I've tested it on.

Severity

annoyance

Additional Information

Just an annoyance, as I say adding some dummy content to the page will fix it.

Also would like to say this bug took absolutely forever to find!

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-edge-caseSvelteKit cannot be used in an uncommon way

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions