Require %sveltekit.body%
to not be a direct child of <body>
?
#7585
Replies: 12 comments 9 replies
-
What if we make this a custom element (not sure about the name) ? like <body>
<svelte>%sveltekit.body%</svelte>
</body> and somehow force the styling for this to be |
Beta Was this translation helpful? Give feedback.
-
I'm for adding a comment above the div linking to that sentence. <!-- do not remove this div element unless you are abolutely sure you don't need it. Read here why it matters: ... -->
<div>
... All people getting that app will from now on see that comment and think twice before removing it. Additionally, if we really want to, we could make this a warning at build time. I'm against throwing an error. |
Beta Was this translation helpful? Give feedback.
-
Isn't it possible to wrap the generated HTML in a div with |
Beta Was this translation helpful? Give feedback.
-
I've ran into trouble with the containing I would prefer that the Another thing to consider: There may also be other times where the I think a warning would be a good compromise, but am mainly commenting to just to share my opinion. |
Beta Was this translation helpful? Give feedback.
-
I would prefer to see the framework find a way to use the body directly. I'm kind of allergic to unjustified element depth, ok in the case of svelte alone but since sveltekit is in charge of rendering the whole page, the body must be directly accessible. I do understand that this issue is tricky to handle but I would rather have my content placed in the body and not support any client owned overlay than having the page content reside in the div. maybe the warning/rule could be disabled from configuration. this could be seen as a feature and not a bug. |
Beta Was this translation helpful? Give feedback.
-
I maybe have a different use case. I have my pages split into two sections: (site) and (app). Each has a different layout - but I want it to function like that main app.html at the root. Literally, I want no body tag in app.html, because I want to put the body tags in (site)/+layout.svelte and (app)/+layout.svelte Unfortunately, this isn't how svelte kit expects to be used, so.... |
Beta Was this translation helpful? Give feedback.
-
Is there a way to silence this warning?
The web is also a messed-up environment with thousands of unnecessary wrappers. (I don't argue whether they're necessary in common cases, but definitely they're not for every single use-case) P.S. btw no offense, svelte is still IMO the best among this messed-up environment |
Beta Was this translation helpful? Give feedback.
-
I saw |
Beta Was this translation helpful? Give feedback.
-
For what it is worth: I'm getting this warning when I'm using app.html as suggested.
The chrome[brave] DevTools console error
I'm running this locally with |
Beta Was this translation helpful? Give feedback.
-
Couldn't the issue be fixed by prefixing and suffixing comment, instead of wrapping div? That would enable svelte to only replace its own code without erasing 3rd party code from body while keeping support for selectors like |
Beta Was this translation helpful? Give feedback.
-
I don't understand while display needs to be |
Beta Was this translation helpful? Give feedback.
-
It helps CSS with partially ignoring the DIV. Imagine you apply |
Beta Was this translation helpful? Give feedback.
-
The default
src/app.html
looks like this:The reason for that is articulated in the docs:
Understandably, a lot of people miss that, and assume that the wrapping
<div>
is unnecessary. Since it looks redundant and adds some minor inconvenience for styling (you need to adddisplay: contents
or otherwise make it possible forheight: 100%
elements in your components to work as expected), some people remove it altogether.I ran into an example of the problems that this can cause the other day when working on #7507 — if the Vite error overlay exists on the page before hydration occurs, the overlay is destroyed, because it's (understandably) appended to the
<body>
. Much worse, this sort of thing can happen in production because of various browser extensions, and when that happens you'll be lucky to find out about it, much less in a manner that leads to a successful diagnosis.The web is a hostile environment. User agents, rather than app developers, are ultimately responsible for how stuff gets rendered. A web framework should protect against this sort of thing from happening.
I therefore propose that we require
%sveltekit.body%
to be in a wrapper element, to guard against people inadvertently making their apps fragile. The problems caused by the wrapper element are easily worked around (if we addeddisplay: contents
by default then probably no-one would even encounter them; pay no heed to the caveats on caniuse.com as they don't apply to this usage), and we'd have the opportunity to explain to people, via an error message, why the wrapper is required.What do people think? Would this create problems that can't easily be worked around?
Beta Was this translation helpful? Give feedback.
All reactions