sveltejs / sveltejs/kit

In SSR consecutive `query.batch` is called on the client

Open
#15,826 2 comments 0 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
{#each await getLiveLessons() as lesson (lesson.id)}
  <!-- all `query.batch` remote functions: -->
  {@const cls = await getLiveLessonClass(lesson.classId)}
  {@const teacher = await getTeacher(lesson.teacherId)}
  {@const students = await getLiveLessonStudentCenter(lesson.classId)}
{/each}

When the page is accessed, non-first query.batch calls inside the each loop are re-fetched from the client.

In this case, they are getTeacher and getLiveLessonStudentCenter.

The results are all baked in the server rendered HTML:

{
  const h = (window.__svelte ??= {}).h ??= new Map();

  for (const [k, v] of [
    ["q5s0im/getLiveLessons/","[[1,8,14,20],{\"id\":2,\"classId\":3,\"teacherId\":4,\"startTime\":5,\"endTime\":6,\"cancel\":7},\"l1\",\"c1\",\"t1\",[\"Date\",\"2026-05-12T09:59:31.010Z\"],[\"Date\",\"2026-05-12T10:59:31.010Z\"],false,{\"id\":9,\"classId\":10,\"teacherId\":11,\"startTime\":12,\"endTime\":13,\"cancel\":7},\"l2\",\"c2\",\"t2\",[\"Date\",\"2026-05-12T11:29:31.010Z\"],[\"Date\",\"2026-05-12T12:29:31.010Z\"],{\"id\":15,\"classId\":16,\"teacherId\":4,\"startTime\":17,\"endTime\":18,\"cancel\":19},\"l3\",\"c3\",[\"Date\",\"2026-05-12T12:59:31.010Z\"],[\"Date\",\"2026-05-12T13:59:31.010Z\"],true,{\"id\":21,\"classId\":3,\"teacherId\":22,\"startTime\":23,\"endTime\":24,\"cancel\":7},\"l4\",\"t3\",[\"Date\",\"2026-05-12T14:59:31.010Z\"],[\"Date\",\"2026-05-12T15:59:31.010Z\"]]"],
    ["q5s0im/getLiveLessonClass/WyJjMSJd","[{\"classId\":1,\"className\":2,\"subject\":3},\"c1\",\"수학 기초반\",\"수학\"]"],
    ["q5s0im/getLiveLessonClass/WyJjMiJd","[{\"classId\":1,\"className\":2,\"subject\":3},\"c2\",\"영어 심화반\",\"영어\"]"],
    ["q5s0im/getLiveLessonClass/WyJjMyJd","[{\"classId\":1,\"className\":2,\"subject\":3},\"c3\",\"과학 탐구반\",\"과학\"]"],
    ["q5s0im/getTeacher/WyJ0MSJd","[{\"teacherId\":1,\"name\":2},\"t1\",\"김민준\"]"],
    ["q5s0im/getTeacher/WyJ0MyJd","[{\"teacherId\":1,\"name\":2},\"t3\",\"박지호\"]"],
    ["q5s0im/getTeacher/WyJ0MiJd","[{\"teacherId\":1,\"name\":2},\"t2\",\"이서연\"]"],
    ["q5s0im/getLiveLessonStudentCenter/WyJjMSJd","[{\"classId\":1,\"studentCount\":2,\"centerName\":3},\"c1\",12,\"강남센터\"]"],
    ["q5s0im/getLiveLessonStudentCenter/WyJjMyJd","[{\"classId\":1,\"studentCount\":2,\"centerName\":3},\"c3\",15,\"송파센터\"]"],
    ["q5s0im/getLiveLessonStudentCenter/WyJjMiJd","[{\"classId\":1,\"studentCount\":2,\"centerName\":3},\"c2\",8,\"서초센터\"]"]
  ]) {
    h.set(k, v);
  }
}

cc @Yeonho-Lee

Reproduction

https://github.com/hyunbinseo/svelte-kit-templates/tree/svelte-kit-15826

System Info
System:
  OS: Windows 11 10.0.26200
  CPU: (8) x64 Intel(R) Core(TM) Ultra 7 258V
  Memory: 4.78 GB / 31.48 GB
Binaries:
  Node: 24.15.0 - C:\Users\hyunb\AppData\Local\fnm_multishells\19996_1778584201985\node.EXE
  npm: 11.12.1 - C:\Users\hyunb\AppData\Local\fnm_multishells\19996_1778584201985\npm.CMD
  pnpm: 10.33.2 - C:\Users\hyunb\AppData\Local\fnm_multishells\19996_1778584201985\pnpm.CMD
  Deno: 2.4.0 - C:\Users\hyunb\.deno\bin\deno.EXE
Browsers:
  Chrome: 148.0.7778.96
  Edge: Chromium (140.0.3485.54)
  Firefox: 150.0.2 - C:\Program Files\Mozilla Firefox\firefox.exe
npmPackages:
  @sveltejs/adapter-auto: ^7.0.1 => 7.0.1
  @sveltejs/kit: ^2.59.1 => 2.59.1
  @sveltejs/vite-plugin-svelte: ^7.1.2 => 7.1.2
  svelte: ^5.55.5 => 5.55.5
  vite: ^8.0.12 => 8.0.12
Severity

annoyance

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 by reproducing the issue with the linked svelte-kit-15826 template, then compare the server-rendered query.batch data with browser network requests during hydration. The fix is complete when consecutive query.batch calls already represented in the SSR HTML are not redundantly fetched by the client.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, full-stack
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.