Skip to content

Layout invalidated when referencing missing search param #10504

Closed as not planned

Description

@coryvirok

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.

Activity

  1. coryvirok commented on Aug 8, 2023

    @coryvirok
    ContributorAuthor

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

    #8403

  2. dummdidumm commented on Aug 8, 2023

    @dummdidumm
    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.

  3. coryvirok commented on Aug 8, 2023

    @coryvirok
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions