Skip to content

Turn prerendering back on - #49

Merged
pierosavi merged 9 commits into
mainfrom
prerender-i18n
Sep 30, 2026
Merged

pierosavi merged 9 commits into
mainfrom
prerender-i18n

Conversation

@pierosavi

@pierosavi pierosavi commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Closes OHF-Device-Database/backlog-items#169.

PR #39 switched the whole site to server rendering because prerendering broke translations: at build time there is no request URL to read the locale from, so every prerendered page came out in English. This PR prerenders the four content pages again, one static file per locale, and keeps everything else server-rendered.

What is prerendered now

Route Rendering Why
/about, /how-it-works, /editorial-stance, /imprint (+ /de/..., /fr/..., all 31 locales) prerendered pure content, no API or query params
/, /browse, /devices/[id] server need the device API at request time
/surveys server active edition comes from ?survey=
/404, /robots.txt, /config.js server read the request URL or runtime env

How it works

  • Pages moved to src/pages/[...locale]/. The optional [...locale] segment is the language prefix. /about is English (no prefix), /de/about is German. Prerendered pages list their locales via getStaticPaths (localeStaticPaths in src/utilities/locale.ts), so the build writes one HTML file per locale.
  • Middleware hands the URL to Paraglide. Paraglide reads the locale from the request URL, which works both at request time and at build time . One workaround: Astro's build-time request warns when its headers are read and Paraglide reads Sec-Fetch-Dest, so at build time we pass a bare new Request(context.url) instead.
  • Invalid prefixes 404. /en/about, /foo/about, /de/nonexistent render the localized 404 page.
  • Runtime env vs. static files. Prerendered pages are frozen at build time, so they can't read NOINDEX or CSR_API_AUTHORITY from the container's env. Two consequences:
    • The client-side API authority is served by a new server-rendered /config.js endpoint instead of being inlined into the HTML. src/io/index.ts reads it per call instead of at module load.
    • Prerendered pages carry no robots meta tag or X-Robots-Tag header. robots.txt (server-rendered, reads the runtime NOINDEX) remains the crawl gate for preview deploys.
  • build.format: "file" + trailingSlash: "never". Prerendered pages are written as about.html, not about/index.html. With the directory layout Netlify redirected every /about link to /about/. /about/ now redirects to /about on both Netlify and the node target.

Things to keep in mind

  • A new prerendered page needs export const getStaticPaths = localeStaticPaths;. A page that needs the API or query params needs export const prerender = false;.
  • Prerendered pages must only emit relative URLs (localizeHref("/about")), never absolute ones: there is no real origin at build time.
  • Astro.cache.set() was dropped from the prerendered pages, static files don't need it.

@netlify

netlify Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for device-database-preview ready!

Name Link
🔨 Latest commit 833a689
🔍 Latest deploy log https://app.netlify.com/projects/device-database-preview/deploys/6abd2ab40585b1000853f07c
😎 Deploy Preview https://deploy-preview-49--device-database-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pierosavi pierosavi changed the title Move astro components to locale subfolders, remove cache, add getStat… Turn prerendering back on Sep 17, 2026
@pierosavi
pierosavi marked this pull request as ready for review September 30, 2026 11:19
@pierosavi
pierosavi requested review from PhilipTrauner and a balanced review from Copilot September 30, 2026 11:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread src/utilities/cache.ts Outdated
Comment thread src/middleware.ts
Comment thread src/pages/config.js.ts
@pierosavi
pierosavi merged commit 3f66239 into main Sep 30, 2026
7 checks passed
@pierosavi
pierosavi deleted the prerender-i18n branch September 30, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

turn pre-rendering back on

3 participants