Skip to content

afterNavigate callbacks do not get removed when returning a function in onNavigate #13240

Closed
@Elia872

Description

@Elia872

Describe the bug

When returning a function from an onNavigate callback in a parent layout, a child afterNavigate does not get removed during a page change.

Reproduction

https://github.com/Elia872/kit-afternav-error

navigate by clicking links back and forth from /a and /b, and see how in the console each time the number of logs increases. Also see the "after navigate was called" in /b, it should be false, but the code in /a's afterNavigate changes it to true.

Logs

No response

System Info

System:
    OS: Linux 6.8 Linux Mint 22 (Wilma)
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
    Memory: 19.20 GB / 31.23 GB
    Container: Yes
    Shell: 3.7.1 - /usr/bin/fish
  Binaries:
    Node: 20.16.0 - ~/.local/share/pnpm/node
    npm: 10.8.1 - ~/.local/share/pnpm/npm
    pnpm: 9.15.1 - ~/.local/share/pnpm/pnpm
    bun: 1.1.18 - ~/.bun/bin/bun
    Watchman: 4.9.0 - /usr/bin/watchman
  Browsers:
    Chrome: 131.0.6778.139
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.3.1
    @sveltejs/kit: ^2.0.0 => 2.15.0
    @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.4
    svelte: ^5.0.0 => 5.16.0
    vite: ^5.4.11 => 5.4.11

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions