Skip to content

CSR not working with remote functions when preloading is enabledΒ #17221

@connorjan

Description

@connorjan

Describe the bug

In the <script> tag of a +page.svelte file, if you import a remote function and then call it in the script tag, the page will not client-side render (i.e. navigating to a different page, then return back via the client somehow). This only seems to be an issue with data-sveltekit-preload-data="hover". Downgrading to [email protected] seems to resolve the issue. I do not see any errors or warnings.

Reproduction

Navigating to a page from the client containing the following does not work:

<script lang="ts">
  import { test } from "$lib/api/test.remote";

  const myTest = test()
</script>

{await myTest}

Removing data-sveltekit-preload-data="hover" seems to cause everything to start working again.

Additionally, this only seems to occur when calling the remote function within the <script> tag. Doing something like the following does not seem to cause any issue:

<script lang="ts">
  import { test } from "$lib/api/test.remote";
</script>

{await test()}

The contents of test.remote.ts are as follows:

import { query } from "$app/server"

export const test = query(() => {
  return Math.random()
})

Logs

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (4) x64 Intel(R) Core(TM) i5-3340 CPU @ 3.10GHz
    Memory: 5.35 GB / 11.55 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 22.20.0 - /home/connor/.local/share/pnpm/node
    npm: 10.9.3 - /home/connor/.local/share/pnpm/npm
    pnpm: 10.20.0 - /home/connor/.local/share/pnpm/pnpm
    bun: 1.3.2 - /home/connor/.bun/bin/bun
  Browsers:
    Firefox: 145.0.1
    Firefox Developer Edition: 145.0.1
  npmPackages:
    svelte: ^5.43.14 => 5.43.14

Severity

annoyance

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