sveltejs / sveltejs/kit

`__data.json` page invalidation returns corrupted JSON in some rare cases

Open
#15,511 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

awaiting submitter
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

In some cases, specially on slower network devices (also happens simulating slow network in chrome dev tools), the page invalidation call to __data.json contains invalid json making JSON.parse fail.

Image `{"id":239,�"url":240,`
Reproduction

I've only experienced this issue on routes having a streamed promise from a load function.
This issue has been poping up in my sentry issues for almoast a year and kept happening about 10 to 20 times a day for various users. I could never reproduce the issue my self so i put it of as a user issue with their network. Today this exact issue happened to me in my local dev environment which implies it most likely is not a user network issue and made me open this bug report.

Logs
__Local error:__

VM26528:1 Uncaught (in promise) SyntaxError: Expected ',' or '}' after property value in JSON at position 57040 (line 1 column 57041)
    at JSON.parse (<anonymous>)
    at client.js?v=55e50156:2943:23


VM26529:1 Uncaught (in promise) SyntaxError: Expected double-quoted property name in JSON at position 11079 (line 1 column 11080)
    at JSON.parse (<anonymous>)
    at client.js?v=55e50156:2943:23


happening in the `function load_data(url, invalid)` function

__One of the errors reported in Sentry:__

SyntaxError
Unexpected token '�', "�{"type":""... is not valid JSON
System Info
System:
    OS: Windows 11 10.0.26200
    CPU: (24) x64 13th Gen Intel(R) Core(TM) i7-13700KF
    Memory: 28.95 GB / 63.86 GB
  Binaries:
    Node: 22.17.1 - C:\nvm4w\nodejs\node.EXE
    npm: 10.9.2 - C:\nvm4w\nodejs\npm.CMD
  Browsers:
    Chrome: 145.0.7632.160
    Edge: Chromium (145.0.3800.82)
    Internet Explorer: 11.0.26100.7309
  npmPackages:
    @sveltejs/adapter-node: ^5.5.3 => 5.5.3
    @sveltejs/kit: ^2.53.0 => 2.53.0
    svelte: ^5.53.2 => 5.53.2
    vite: ^6.3.0 => 6.4.1
Severity

annoyance

Additional Information

I can't verify it reliably but it seems like its happening more often when more requests to the invalidation endpoint are being issued.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the load_data(url, invalid) function in the generated client.js, using a route with a streamed promise from a load function and Chrome's slow-network simulation. Investigate the invalidation response path and reproduce the malformed __data.json described in the logs. Done means repeated invalidation requests produce valid JSON that no longer fails at JSON.parse.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.