Skip to content

Svelte 5: replaceState("/", {}) error #12477

@OTheNonE

Description

@OTheNonE

Describe the bug

When running the following code in src/routes/+page.svelte:

<script lang="ts">
    import { replaceState } from "$app/navigation";

    $effect(() => {
        replaceState("/", {})
    })

</script>

I get a error when calling the replaceState function due to Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$set') in $effect

Reproduction

  1. Create a sveltekit project using npm create svelte@latest (selected typescript and svelte 5).
  2. Add the following code to src/routes/+page.svelte:
<script lang="ts">
    import { replaceState } from "$app/navigation";

    $effect(() => {
        replaceState("/", {})
    })

</script>

Logs

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '$set')

	in $effect

    at replaceState (http://localhost:5173/node_modules/@sveltejs/kit/src/runtime/client/client.js?v=2d8c9736:1913:7)
    at $effect (http://localhost:5173/src/routes/+page.svelte?t=1721223477430:21:3)
    at update_reaction (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1249:23)
    at update_effect (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1367:21)
    at flush_queued_effects (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1421:7)
    at flush_queued_root_effects (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1408:9)
    at flush_sync (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1528:7)
    at flush_sync (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1533:7)
    at mount (http://localhost:5173/node_modules/.vite/deps/chunk-KL3U4IVS.js?v=2d8c9736:822:10)
    at new Svelte4Component (http://localhost:5173/node_modules/.vite/deps/chunk-KL3U4IVS.js?v=2d8c9736:1012:70)TypeError: Cannot read properties of undefined (reading '$set')

	in $effect

    at replaceState (http://localhost:5173/node_modules/@sveltejs/kit/src/runtime/client/client.js?v=2d8c9736:1913:7)
    at $effect (http://localhost:5173/src/routes/+page.svelte?t=1721223477430:21:3)
    at update_reaction (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1249:23)
    at update_effect (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1367:21)
    at flush_queued_effects (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1421:7)
    at flush_queued_root_effects (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1408:9)
    at flush_sync (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1528:7)
    at flush_sync (http://localhost:5173/node_modules/.vite/deps/chunk-CZZRJ74Z.js?v=2d8c9736:1533:7)
    at mount (http://localhost:5173/node_modules/.vite/deps/chunk-KL3U4IVS.js?v=2d8c9736:822:10)
    at new Svelte4Component (http://localhost:5173/node_modules/.vite/deps/chunk-KL3U4IVS.js?v=2d8c9736:1012:70)

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700KF
    Memory: 50.55 GB / 63.82 GB
  Binaries:
    Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (126.0.2592.102)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    svelte: ^5.0.0-next.1 => 5.0.0-next.189

Severity

annoyance

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