Skip to content

Preloading query with page param on hover breaks the app #14827

@aintnewtathis

Description

@aintnewtathis

Describe the bug

I display a simple list of products

//+page.svelte
{#each await getProducts() as product (product.id)}
	<a href="/{product.id}">
              ...
	</a>
{/each}

//data.remote.ts
export const getProducts = query(async () => {
	const products = db.select().from(product);

	return products;
});

that links to /[id] route, +page.svelte has top level await with remote query that gets product by id

//+page.svelte
<script lang="ts">
	import { page } from '$app/state';
	import { getProduct } from './data.remote';
</script>
<pre>{JSON.stringify(await getProduct(page.params.id!), null, 2)}</pre>


//data.remote.ts
export const getProduct = query('unchecked', async (id) => {
	return await db
		.select()
		.from(product)
		.where(eq(product.id, Number(id)));
});

After you hover over more than one link - it fires query with undefined param, on click query payload in Network tab is correct, but it doesn't navigate you to the page. Temporary fixes - data-sveltekit-preload-data="false" or full page reload after navigation.

Reproduction

Added basic code blocks in example.

Logs

getProduct on hover res:
{
    "type": "result",
    "result": "[[]]"
}

getProduct on click res:
{
    "type": "result",
    "result": "[[1],{\"id\":2,\"thumbnail\":3,\"title\":4,\"description\":5,\"size\":6,\"price\":7,\"quantity\":8,\"categoryId\":9,\"createdAt\":10,\"updatedAt\":11},4,\"https://picsum.photos/seed/product4/400\",\"Bluetooth Earbuds\",\"Noise-cancelling wireless earbuds with charging case.\",\"One Size\",7999,150,3,[\"Date\",\"2025-10-22T22:46:42.209Z\"],[\"Date\",\"2025-10-22T22:46:42.209Z\"]]"
}

System Info

System:
    OS: Linux 6.17 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 8600G w/ Radeon 760M Graphics
    Memory: 6.55 GB / 14.74 GB
    Container: Yes
    Shell: 5.3.3 - /usr/bin/bash
  Binaries:
    Node: 22.18.0 - /home/yy/.local/share/mise/installs/node/22.18.0/bin/node
    npm: 10.9.3 - /home/yy/.local/share/mise/installs/node/22.18.0/bin/npm
    pnpm: 10.15.0 - /home/yy/.local/share/mise/installs/node/22.18.0/bin/pnpm
    bun: 1.3.0 - /home/yy/.bun/bin/bun
  Browsers:
    Chromium: 141.0.7390.122
  npmPackages:
    @sveltejs/adapter-auto: ^7.0.0 => 7.0.0
    @sveltejs/adapter-node: ^5.4.0 => 5.4.0
    @sveltejs/kit: ^2.48.0 => 2.48.0
    @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1
    svelte: ^5.42.2 => 5.42.2
    vite: ^7.1.12 => 7.1.12

Severity

serious, but I can work around it

Additional Information

Thanks in advance!

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