You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently I migrated an old app (Sveltekit 1/ Svelte 3) to Svelte 5 via the migration scripts. That worked great for the most part, but my app would no longer work correctly. It rendered the page initially but quickly repainted it completely blank. In the console it printed the error "Uncaught TypeError: Illegal Invocation" (see logs).
I found the fix/workaround in a Reddit Thread that had the same issue: a wrapping <body> tag inside the root layout +layout.svelte was causing the issue. Removing this wrapping body element fixed the issue.
The issue occurs both when using slots or snippets. It does not occur when you remove the slot/snippet from the layout.
In my original project it also gave me a hydration_mismatch warning before the Illegal Invocation error, though I wasn't able to reproduce that.
This is a barebones project created with the sv CLI, with the only change being the layout that was added.
If you remove the wrapping body tag in there, everything works fine.
Logs
chunk-TFYL3GQY.js?v=4e242971:2346 Uncaught TypeError: Illegal invocation
in root.svelte
at get_next_sibling (chunk-TFYL3GQY.js?v=4e242971:2346:30)
at Module.sibling (chunk-TFYL3GQY.js?v=4e242971:2394:5)
at _layout (+layout.svelte?t=1734871119624:16:15)
at chunk-DIK5XZVB.js?v=4e242971:283:58
at update_reaction (chunk-TFYL3GQY.js?v=4e242971:1308:23)
at update_effect (chunk-TFYL3GQY.js?v=4e242971:1399:21)
at create_effect (chunk-TFYL3GQY.js?v=4e242971:2474:7)
at branch (chunk-TFYL3GQY.js?v=4e242971:2622:10)
at chunk-DIK5XZVB.js?v=4e242971:277:17
at update_reaction (chunk-TFYL3GQY.js?v=4e242971:1308:23)
get_next_sibling @ chunk-TFYL3GQY.js?v=4e242971:2346
sibling @ chunk-TFYL3GQY.js?v=4e242971:2394
_layout @ +layout.svelte?t=1734871119624:16
(anonymous) @ chunk-DIK5XZVB.js?v=4e242971:283
update_reaction @ chunk-TFYL3GQY.js?v=4e242971:1308
update_effect @ chunk-TFYL3GQY.js?v=4e242971:1399
create_effect @ chunk-TFYL3GQY.js?v=4e242971:2474
branch @ chunk-TFYL3GQY.js?v=4e242971:2622
(anonymous) @ chunk-DIK5XZVB.js?v=4e242971:277
update_reaction @ chunk-TFYL3GQY.js?v=4e242971:1308
update_effect @ chunk-TFYL3GQY.js?v=4e242971:1399
process_effects @ chunk-TFYL3GQY.js?v=4e242971:1548
flush_queued_root_effects @ chunk-TFYL3GQY.js?v=4e242971:1468
process_deferred @ chunk-TFYL3GQY.js?v=4e242971:1505
I am not quite certain if this is a bug, an undocumented breaking change, or something else I am missing.
I could not find any documentation that suggested not using body tags in the root layout like this.
The issue happened after the migration from Svelte 4 to Svelte 5 (though I filed the issue in the Kit repo since it has to do with the layout/routing).
The text was updated successfully, but these errors were encountered:
You cannot have two body tags. There already is one in src/app.html, one of them has to be removed and the browser will automatically remove the one in the +layout. The missing element then causes an error during hydration because an element was expected where there now is none.
(Note that SvelteKit operates on the assumption that %sveltekit.body% in the app.html is inside a body element, so removing the body from there is not really an option.)
Possibly, though the docs are extensive, chances of people missing that would still be high.
Maybe there could be SvelteKit-specific validations that error if a body tag is found anywhere in the components (and if <body> is missing in app.html).
Describe the bug
Recently I migrated an old app (Sveltekit 1/ Svelte 3) to Svelte 5 via the migration scripts. That worked great for the most part, but my app would no longer work correctly. It rendered the page initially but quickly repainted it completely blank. In the console it printed the error "Uncaught TypeError: Illegal Invocation" (see logs).
I found the fix/workaround in a Reddit Thread that had the same issue: a wrapping
<body>
tag inside the root layout+layout.svelte
was causing the issue. Removing this wrapping body element fixed the issue.The issue occurs both when using slots or snippets. It does not occur when you remove the slot/snippet from the layout.
In my original project it also gave me a
hydration_mismatch
warning before the Illegal Invocation error, though I wasn't able to reproduce that.Reproduction
https://github.com/BaumianerNiklas/svelte5-illegal-invocation-repro
This is a barebones project created with the
sv
CLI, with the only change being the layout that was added.If you remove the wrapping body tag in there, everything works fine.
Logs
System Info
Severity
annoyance
Additional Information
I am not quite certain if this is a bug, an undocumented breaking change, or something else I am missing.
I could not find any documentation that suggested not using body tags in the root layout like this.
The issue happened after the migration from Svelte 4 to Svelte 5 (though I filed the issue in the Kit repo since it has to do with the layout/routing).
The text was updated successfully, but these errors were encountered: