docker: forward NEXT_PUBLIC_POSTHOG_TOKEN into the build stage#21
Merged
Conversation
Docker silently drops --build-arg values without a matching ARG declaration, so the PostHog token never reached next build and was never inlined into the client bundles — posthog.init() guard stayed undefined in prod.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PostHog wasn't loading on prod (www.buildcanada.com). Root cause: the Dockerfile's builder stage never declared
ARG NEXT_PUBLIC_POSTHOG_TOKEN, and Docker silently drops--build-argvalues without a matchingARG. The token therefore never reachednext build, so it was never inlined into the client bundles — theposthog.init()guard ininstrumentation-client.tsevaluatedundefinedin the browser and init never ran.Verified against the deployed bundles: the compiled init is still a runtime
process.envlookup (empty polyfill in the browser) and nophc_token string exists anywhere in the chunks, whileNEXT_PUBLIC_SITE_URL(which does have an ARG) took effect on the same rebuild.Changes
ARG NEXT_PUBLIC_POSTHOG_TOKEN+ENVforwarding in the builder stage so the deploy's existing--build-argactually reachesnext build.Testing
After this merges and prod rebuilds (with
--build-arg NEXT_PUBLIC_POSTHOG_TOKEN=phc_...passed):phc_token should appear inlined in the instrumentation chunkposthog.__loaded === truein the prod console, events visible in PostHog