How to async-load locale and inject it into <html lang>? #2166
Unanswered
YanAnghelp
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I need the
langattribute on<html>to reflect the authenticated user's locale preference (stored in Redis/DB), resolved per-request during SSR. This is extremely important to me.What I've considered
1. Middleware
createMiddlewareruns for every request — including API routes and potentially static assets depending on the deployment target. Running a Redis/DB lookup unconditionally on non-page requests is not acceptable.Path-based filtering (skip
/api/*, skip paths with file extensions) works but relies on conventions that feel fragile rather than architecturally guaranteed.2. Cookie (current approach)
Reading a
localecookie synchronously in thedocumentfunction works and has zero overhead. The limitation: cookies can be stale across devices. If the user changes their locale on Device A, Device B's cookie won't update until the next login or an explicit refresh.For
<html lang>this may be acceptable — but I'd like to understand if there's a better option.3.
createAsyncinside thedocumentfunctionThe
documentprop in<StartServer>is a SolidJS component rendered during SSR, so it should be able to usecreateAsync/cache:Questions:
What I'm looking for
Is there an officially supported pattern for resolving async server data in entry-server.tsx's document shell, with the guarantee that it only runs for HTML page renders (not API routes, not static assets)?
Or is the intended pattern to pre-populate event.locals from the route load function and read it synchronously in document?
Beta Was this translation helpful? Give feedback.
All reactions