sveltejs / sveltejs/kit

Nested remote query functions in each loop freeze page when quickly refreshing query

Open
#15,083 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

Hi, I ran into a bug where my page using remote query functions would just freeze. In the dev tools I can see that ram usage is exploding. This happens when you

  • have an each loop driven by a remote function
  • use another remote function inside the loop's items
  • Call .refresh twice quickly after each other, even though they are awaited. In my real app I'm listening to websocket events and when I receive an event or the user clicks refresh, I call query.refresh. Therefore, I can't ensure that this does not happen multiple times. Debouncing could help, but it still is a bug ;-)
Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-bng3t2tw?file=src%2Froutes%2F%2Bpage.svelte

Please note that hmr is disabled in this reproduction, because otherwise we run into #15066, which has a similar outcome (page freeze).

Logs

no errors, the page just freezes.

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: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^7.0.0 => 7.0.0 
    @sveltejs/kit: ^2.49.2 => 2.49.2 
    @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1 
    svelte: ^5.46.0 => 5.46.0 
    vite: ^7.3.0 => 7.3.0
Severity

serious, but I can work around it

Additional Information

No response

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 with the StackBlitz reproduction in src/routes/+page.svelte and reproduce the freeze by refreshing the query twice quickly with nested remote query functions in an each loop. Trace the remote-function refresh behavior and verify that repeated awaited refreshes no longer cause memory growth or freeze the page.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.