fresh icon indicating copy to clipboard operation
fresh copied to clipboard

feat: apply `lang` and `bodyClass` set in middleware to template

Open brycedorn opened this issue 3 years ago • 0 comments

Hi again! As followup to #47, setting ctx.lang doesn't appear to do anything as ServerContext is isolated from RenderContext. These changes enable a middleware to apply a lang param (e.g. based on Accept-Language header) that will be rendered in the server-side template (as <html lang={lang}>).

Additionally, I added a bodyClass param that has similar behavior, but instead sets a class on the <body> tag. This enables a middleware to apply the correct theme during SSR via the Sec-CH-Prefers-Color-Scheme client-hint header. This also resolves #473.

This implementation piggybacks on the existing params object, though these values could be passed via a separate method. Let me know what you think!

brycedorn avatar Jul 30 '22 16:07 brycedorn