#Rendering different <html> tag in different layouts

10 messages · Page 1 of 1 (latest)

rancid prairie
#

Hello, I'm trying to structure my routes in such away, where __root.tsx is basically only an <Outlet/> and I'm having two different layouts _home.tx and app.tsx which should manage their own <html> element. They need to e.g. set lang attribute and apply proper theming with completely different logic of retrieving the data (one based on URL/fixed values, other from logged in user's data).

However, I'm getting an error Cannot render a sync or defer <script> outside the main document without knowing its order. Try adding async="" or moving it into the root <head> tag. which orginates from OnRendered inside of Router - https://github.com/TanStack/router/blob/98dc05073dcf7490d38f9158833f3df22c005e96/packages/react-router/src/Match.tsx#L155

If I'm reading the comment next to component correctly I probably shouldn't render html tag outside of __root? Is there any way to structure it differently to achieve the same results?

Minimal reproduction (with start for easier setup, but I don't think it changes anything there):

https://github.com/pawelblaszczyk5/different-root-per-layout-reproduction

GitHub

Contribute to pawelblaszczyk5/different-root-per-layout-reproduction development by creating an account on GitHub.

GitHub

🤖 A client-first, server-capable, fully type-safe router and full-stack framework for the web (React and more). - TanStack/router

keen nymph
#

where does the lang come from?

rancid prairie
# keen nymph where does the lang come from?

In one case (home) I’m not sure yet, maybe it’d be state, maybe it’d be url param. In the other (app) it’s from user data which I’ll get via Tanstack DB. Similar with e.g. theme.

rancid prairie
keen nymph
#

it is a possibility yes

sleek cosmos
rancid prairie
sleek cosmos
rancid prairie
#

Sure! I’m on short vacation right now, so I won’t have access to my laptop until Tuesday 😄 I could share something then

rancid prairie