sveltejs / sveltejs/kit

Rerunning load function, `searchParams` using `getRequestEvent`

Open
#14,072 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

I'm not sure if this is expected, but when using the event directly from the load function it works as expected; when the url (searchParams) changes, the load function reruns. But when using the event from getRequestEvent, the load function does not.

Reproduction

StackBlitz

code preview
// routes/+page.server.js
import { getRequestEvent } from '$app/server';

export const load = async (event) => {
  const requestEvent = getRequestEvent();

  return {
    event: event.url.searchParams.get('event') ?? '1',
    requestEvent: requestEvent.url.searchParams.get('requestEvent') ?? '1',
  };
};
<!-- routes/+page.svelte -->
<script>
	let { data } = $props();

	let event = $state(1);

	let requestEvent = $state(1);
</script>

<h1>
	event={data.event} 
	<a href="?event={event}" onclick={() => event++}>[set value]</a>
	current={event}
</h1>

<h1>
	requestEvent={data.requestEvent}
	<a href="?requestEvent={requestEvent}" onclick={() => requestEvent++}>[new value]</a>
	current={requestEvent}
</h1>
Logs

System Info
(StackBlitz)

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: ^6.0.1 => 6.0.1 
    @sveltejs/kit: ^2.26.1 => 2.26.1 
    @sveltejs/vite-plugin-svelte: ^6.1.0 => 6.1.0 
    svelte: ^5.37.1 => 5.37.1 
    vite: ^7.0.6 => 7.0.6
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 with the linked StackBlitz reproduction, then inspect routes/+page.server.js and routes/+page.svelte to compare the load dependencies observed through event.url.searchParams and getRequestEvent(). Change each query parameter and verify whether the load data updates consistently; done means the intended rerun behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.