Skip to content

False-positive Placing %sveltekit.body% directly inside <body> is not recommended warning #14357

@MathiasWP

Description

@MathiasWP

Describe the bug

I get this warning in my browser console:

Image

But my app.html looks like this:

Image

And when i check the DOM there is only one <body> element in the markup as expected.

Reproduction

I created a minimal repro for triggering this warning with something that should not trigger this warning: https://github.com/MathiasWP/sveltekit-false-positive-body-inside-body-warning

Code:

// +page.svelte
<script lang="ts">
	import Button from './Button.svelte';
</script>

<Button>
	<div>
		<button>Hello world</button>
	</div>
</Button>
// Button.svelte
<script lang="ts">
	import type { Snippet } from 'svelte';

	interface Props {
		// Can be any type of named snippet, just used children for convenience
		children: Snippet;
	}

	const { children }: Props = $props();
</script>

<button>{@render children()}</button>

Logs

(index):24 Placing %sveltekit.body% directly inside <body> is not recommended, as your app may break for users who have certain browser extensions installed.

Consider wrapping it in an element:

<div style="display: contents">
  %sveltekit.body%
</div>
(anonymous)	@	(index):24
Promise.then		
(anonymous)	@	(index):23

System Info

System:
    OS: macOS 15.6.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 99.08 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 10.9.2 - /usr/local/bin/npm
    pnpm: 10.13.1 - ~/Library/pnpm/pnpm
    bun: 1.2.17 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 138.1.80.113
    Chrome: 139.0.7258.155
    Safari: 18.6
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.1.0 
    @sveltejs/kit: ^2.22.0 => 2.37.0 
    @sveltejs/vite-plugin-svelte: ^6.0.0 => 6.1.3 
    svelte: ^5.0.0 => 5.38.6 
    vite: ^7.0.4 => 7.1.3

Severity

annoyance

Additional Information

Kinda confusing warning, ended up spending a lot of time scratching my head not finding anything that should have caused this

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