Skip to content

[kit 2.1.0] Runtime error when onNavigate callback returns a function #11600

@f-elix

Description

@f-elix

Describe the bug

When an onNavigate callback returns a function, a runtime error occurs:

ReferenceError: callbacks is not defined

The problem comes from #11547, specifically this line: https://github.com/sveltejs/kit/pull/11547/files#diff-6bc786c5d82299b5eed36bb073cd7e3c8347af2951019da2b5dff1d5e3bad611R1289.

Its preceded by a @ts-ignore, thats probably why it was missed during the refactor.

Reproduction

Go to https://stackblitz.com/edit/sveltejs-kit-template-default-jsehy7?description=The%20default%20SvelteKit%20template,%20generated%20with%20create-svelte&file=src%2Froutes%2F%2Blayout.svelte&title=SvelteKit%20Default%20Template and navigate by clicking a link. The error will appear in the console.

Logs

No response

System Info

System:
    OS: macOS 12.7.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 390.63 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 20.6.0 - ~/.nvm/versions/node/v20.6.0/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v20.6.0/bin/npm
    pnpm: 8.7.4 - ~/.nvm/versions/node/v20.6.0/bin/pnpm
    bun: 1.0.0 - ~/.nvm/versions/node/v20.6.0/bin/bun
  Browsers:
    Brave Browser: 116.1.57.53
    Chrome: 120.0.6099.199
    Safari: 17.1.2
  npmPackages:
    @sveltejs/adapter-vercel: 4.0.4 => 4.0.4 
    @sveltejs/kit: 2.3.0 => 2.3.0 
    @sveltejs/vite-plugin-svelte: 3.0.1 => 3.0.1 
    svelte: 4.2.8 => 4.2.8

Severity

blocking all usage of SvelteKit

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