Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of runes in SvelteKit load functions #13269

Open
bertie-sektorcert opened this issue Jan 3, 2025 · 1 comment
Open

Use of runes in SvelteKit load functions #13269

bertie-sektorcert opened this issue Jan 3, 2025 · 1 comment
Labels
feature / enhancement New feature or request svelte 5

Comments

@bertie-sektorcert
Copy link

Describe the bug

It doesn't seem like there's a way to use the svelte runes within the +page.ts, +layout.ts, +page.server.ts and +layout.server.ts, and it doesn't seem like there's any documentation. This seem like a major limiting factor in implementing reactivity using the new methods. Attempting to do so gives the following error:

Svelte error: rune_outside_svelte The '$state' rune is only available inside '.svelte' and '.svelte.js/ts' files

Attempting to rename the load files to something like +page.svelte.ts gives the following error:

Files prefixed with + are reserved (saw /+page.svelte.ts)

Reproduction

import type { PageLoad } from './$types';

export const load: PageLoad = () => {
    let x = $state(None)

    return {
        x
    };
};

Logs

No response

System Info

System:
    OS: macOS 15.2
    CPU: (12) arm64 Apple M3 Pro
    Memory: 1.20 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.4.0 - ~/web/node_modules/.bin/node
    npm: 10.9.0 - /opt/homebrew/bin/npm
  Browsers:
    Safari: 18.2
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.3.1
    @sveltejs/kit: ^2.0.0 => 2.8.2
    @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.1
    svelte: ^5.0.0 => 5.2.7
    vite: ^5.0.3 => 5.4.11

Severity

annoyance

Additional Information

No response

@Conduitry Conduitry added the feature / enhancement New feature or request label Jan 3, 2025
@kran6a
Copy link

kran6a commented Jan 8, 2025

You can already use svelte/reactivity classes there. Arrays, primitives and objects cannot be used as of now but Map, Set and Date can be.
I use this to handle live data updates via SSE and reactivity works as expected. Note that I use adapter-static without prerendering nor SSR enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request svelte 5
Projects
None yet
Development

No branches or pull requests

4 participants