Skip to content

{@render ...} inside <svelte:head> causes "invalid_snippet_arguments" error #15753

New issue

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

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

Already on GitHub? # to your account

Closed
NextLegacy opened this issue Apr 12, 2025 · 3 comments · Fixed by #15755
Closed

{@render ...} inside <svelte:head> causes "invalid_snippet_arguments" error #15753

NextLegacy opened this issue Apr 12, 2025 · 3 comments · Fixed by #15755
Assignees
Labels

Comments

@NextLegacy
Copy link

Describe the bug

Using the {@render} directive within a <svelte:head> tag results in a "Svelte error: invalid_snippet_arguments".
This issue started occurring with version svelte@5.26.0. The code was working in previous versions.

Reproduction

  1. Run npx sv create my-app
  2. Replace the contents of src/routes/+page.svelte with the following:
{#snippet abc()}
    <p>
     abc
    </p>
{/snippet}

<svelte:head>
    {@render abc()}
</svelte:head>
  1. Run npm install && npm run dev

Logs

Svelte error: invalid_snippet_arguments
A snippet function was passed invalid arguments. Snippets should only be instantiated via `{@render ...}`
https://svelte.dev/e/invalid_snippet_arguments
    at invalid_snippet_arguments (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:29:17)
    at Module.validate_snippet_args (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:114:54)
    at abc (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:11:24)
    at eval (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:23:3)
    at Module.head (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:130:2)
    at _page (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:21:24)
    at children (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:66:5)
    at _layout (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:19:2)
    at Root (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:61:3)
    at render (eval at runInlinedModule (file:///C:/Users/NextLegacy/Desktop/New%20folder/my-app/node_modules/vite/dist/node/module-runner.js:1049:11), <anonymous>:94:2)

System Info

System:
  OS: Windows 11 10.0.26100
  CPU: (28) x64 Intel(R) Core(TM) i7-14700K
  Memory: 6.92 GB / 31.75 GB
Binaries:
  Node: 22.13.0 - C:\Program Files\nodejs\node.EXE
  npm: 11.0.0 - C:\Program Files\nodejs\npm.CMD
  pnpm: 10.6.3 - ~\AppData\Local\pnpm\pnpm.EXE
  bun: 1.1.42 - ~\.bun\bin\bun.EXE
Browsers:
  Edge: Chromium (133.0.3065.69)
  Internet Explorer: 11.0.26100.1882

Severity

blocking an upgrade

@Ocean-OS
Copy link
Contributor

This reproduction doesn't seem to have any issues, could you please make a REPL reproduction that demonstrates the issue?

@NextLegacy
Copy link
Author

I couldn't reproduce the issue in the Svelte Playground either, but I was able to reproduce it using SvelteLab:
https://www.sveltelab.dev/5819y119sc28v1w

Additionally, I've created a minimal GitHub repository that demonstrates the issue using the exact steps mentioned above:
https://github.com/NextLegacy/svelte-issue-15753

It's also worth mentioning that the error only occurs in development environments, production builds don't seem to be affected.

@paoloricciuti
Copy link
Member

The issue is that the validate snippet function on the server is checking for instance of Payload but inside the head we pass Payload.head which is just an object

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants