Skip to content

Layout invalidated when referencing missing search param #10504

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

Closed
coryvirok opened this issue Aug 8, 2023 · 3 comments
Closed

Layout invalidated when referencing missing search param #10504

coryvirok opened this issue Aug 8, 2023 · 3 comments

Comments

@coryvirok
Copy link
Contributor

Describe the bug

I have a layout that loads some data based on a search param. If the search param is not provided, I expect the layout to not be re-run on navigation to child routes. However, it appears that the layout will be re-run on every child route change, despite the search param never being provided.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-dkhony?file=src%2Froutes%2F%2Blayout.server.js

Logs

No response

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.20.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.6.10 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/kit: ^1.20.4 => 1.22.4 
    svelte: ^4.0.5 => 4.1.2 
    vite: ^4.4.2 => 4.4.9

Severity

blocking an upgrade

Additional Information

Something else to note is that I'm using a wildcard route.

@coryvirok
Copy link
Contributor Author

Possibly the same/related? Although I'm seeing the invalidation happen even when there is no searchParams.

#8403

@dummdidumm
Copy link
Member

It's indeed a duplicate of #8403, closing in favor of that. Your use case is the same: You listen to searchParams, which means as soon as anything happens with the URL the layout is rerun, which you don't want. #8403 would solve that.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2023
@coryvirok
Copy link
Contributor Author

Got it and thanks for the info.

Here's the docs that need to be updated to match the behavior: https://kit.svelte.dev/docs/load#rerunning-load-functions-when-do-load-functions-rerun

"It references a property of url (such as url.pathname or url.search) whose value has changed."

In my case the search param is not set, which means the value of url.searchParams hasn't changed, even though url.pathname has.

coryvirok added a commit to coryvirok/kit that referenced this issue Aug 8, 2023
Based on the conversations here:
- sveltejs#10504
- sveltejs#8403

Any changes to the URL will cause any `load` functions that access `url.searchParams` to be rerun even if the search portion of the URL has not changed (or indeed if there are no search params in the URL.)
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

No branches or pull requests

2 participants