fix(nextjs-config): warn when withPostHogConfig is wrapped by another Next config wrapper#3611
Draft
cat-ph wants to merge 1 commit into
Draft
fix(nextjs-config): warn when withPostHogConfig is wrapped by another Next config wrapper#3611cat-ph wants to merge 1 commit into
cat-ph wants to merge 1 commit into
Conversation
… Next config wrapper
When withPostHogConfig is not the outermost wrapper in next.config (e.g.
withNextIntl(withPostHogConfig(...))), some outer wrappers silently drop
the function-form config that withPostHogConfig returns. The result is
that the webpack/compiler hooks are never installed, no source maps are
generated or uploaded, and no errors or logs surface.
This change registers a process.on('exit') handler that emits a clear
warning if the inner Next.js config function was never invoked while
sourcemaps are enabled, pointing the user to the correct wrapper order.
It also documents the recommended order in the README.
Generated-By: PostHog Code
Task-Id: 689c4895-349a-4139-98c6-4ac93b522ae9
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Contributor
|
Size Change: +1.74 kB (+0.01%) Total Size: 16 MB
ℹ️ View Unchanged
|
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
withPostHogConfigis called but its inner config function is never invoked (the failure mode when another Next.js config wrapper is applied around it and silently drops the function-form return value).withPostHogConfigshould be the outermost wrapper.Context — the bug
User report:
Root cause:
withPostHogConfigreturns a function-form Next.js config ((phase, opts) => Promise<NextConfig>). When another wrapper likewithNextIntl(withPostHogConfig(...))does{ ...result }on it, spreading a function yields{}— silently dropping the PostHog hooks. Next.js itself supports function-form configs, so whenwithPostHogConfigis the outermost wrapper it works correctly.Approach
This PR implements the "warn + document" mitigation discussed in chat. A complementary follow-up would be to make
withPostHogConfigpreserve the input shape (return an object when given an object) so it composes correctly as an inner wrapper too — that would be the full fix. This PR is intentionally smaller-scope: it makes the silent failure loud.What the warning looks like
Test plan
pnpm lintpassespnpm test:unitpasses (3 new tests, all green)pnpm buildpasses (CJS + ESM bundles + declaration files)withNextIntl(withPostHogConfig(...))to confirm the warning fires at the end ofnext buildNotes / open questions
process.on('exit')so the warning surfaces at the very end ofnext build. That's late, butnext buildexits cleanly so it does still show up. Earlier detection would require a timer-based heuristic that's noisier.withPostHogConfigis essentially only called once per process.Generated-By: PostHog Code
Task-Id: 689c4895-349a-4139-98c6-4ac93b522ae9