Skip to content

Svelte 5 legacy interop bug: Uncaught TypeError: Cannot read properties of undefined (reading 'before') #15423

@echocrow

Description

@echocrow

Describe the bug

Seems like some niche combination of stores and component updates may lead to a runtime error.

We noticed it when we upgraded our site to Svelte 5. Upon page navigation, JS error'd out (see Logs below), blocking other critical runtime code.

This error does not seem to be present in dev mode, but only occurs in build && preview or on e.g. Vercel.

The requirements for this bug seem rather niche. We eventually found a workaround in our case (migrating more components to runes, and moving off of $app/stores). Unsure if a bug fix is worth it in this case(?).

Reproduction

https://stackblitz.com/edit/svelte-5-legacy-nav-update-bug?file=md!README.md

  1. npm run build && npm run preview
    • (the bug is not present in dev!)
    • (in the repro above, this will be run automatically)
  2. open the client console
  3. nagivate to another page
    • (e.g. click any of the header links)
  4. inspect your console
    • Expected: No console errors
    • Actual:
      Uncaught TypeError: Cannot read properties of undefined (reading 'before')
        at L (Doj7iJtn.js:1:839)
         at ks (0.Ck8LqK_p.js:2:3042)
         at 0.Ck8LqK_p.js:2:3658
         at BBycYa5G.js:1:323
         at Ut (C6bb17t1.js:1:8885)
         at ft (C6bb17t1.js:1:9715)
         at Sn (C6bb17t1.js:1:10628)
         at Ht (C6bb17t1.js:1:10041)
      

In some instances this may also block further page navigation (e.g. navigating to a third page).

In this repro, performing any of the following steps seems to bypass this issue:

  • migrate LdJsonScript.svelte to runes
  • migrate meta.ts to runes and relovate into +layout.svelte
  • remove <svelte:head> (i.e. render into regular <body>)

Logs

Uncaught TypeError: Cannot read properties of undefined (reading 'before')
    at L (N6OWQcpE.js:1:841)
    at Rs (0.DYl3NbUt.js:2:3042)
    at 0.DYl3NbUt.js:2:3658
    at CA0ixJbY.js:1:2699
    at Ut (CS1pTN2Y.js:1:8858)
    at ft (CS1pTN2Y.js:1:9688)
    at Rn (CS1pTN2Y.js:1:10601)
    at Ht (CS1pTN2Y.js:1:10014)

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: 18.20.3 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 10.2.3 - /usr/local/bin/npm
  pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
  svelte: ^5.0.0 => 5.20.5

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