Skip to content

cloud: force-dynamic layout so GTM_ID env is read at runtime#271

Merged
keysersoft merged 1 commit into
mainfrom
keysersoft/cookie-banner-force-dynamic
May 28, 2026
Merged

cloud: force-dynamic layout so GTM_ID env is read at runtime#271
keysersoft merged 1 commit into
mainfrom
keysersoft/cookie-banner-force-dynamic

Conversation

@keysersoft
Copy link
Copy Markdown
Contributor

Follow-up to #269. Without export const dynamic = 'force-dynamic' Next.js statically prerendered the layout in CI (where GTM_ID is empty), so the GTM script never appeared in the served HTML on the cloud droplet despite the runtime env being set. Forcing dynamic rendering keeps the single-image goal intact: the droplet's env activates GTM, self-hosted leaves it empty.

Without this, Next.js statically prerenders the layout during `next build`
and bakes in whatever GTM_ID was set in CI (empty). The cloud droplet's
runtime env never gets a chance to set it, so the GTM script never renders.

Forcing dynamic rendering keeps a single Docker image usable for both
flavors: GTM_ID on the cloud droplet activates the banner, self-hosted
containers leave it unset and ship nothing.

Tradeoff: static optimization is lost for /, /login, /forgot-password,
etc. Acceptable for an admin app — most pages already SSR per request.
@keysersoft keysersoft requested a review from mirkopoloni as a code owner May 28, 2026 10:10
@keysersoft keysersoft merged commit fd92830 into main May 28, 2026
8 checks passed
@keysersoft keysersoft deleted the keysersoft/cookie-banner-force-dynamic branch May 28, 2026 10:11
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.

1 participant