fix(nuxt): inject Nitro server chunks in SPA builds before upload - #4779
Open
posthog[bot] wants to merge 4 commits into
Open
fix(nuxt): inject Nitro server chunks in SPA builds before upload#4779posthog[bot] wants to merge 4 commits into
posthog[bot] wants to merge 4 commits into
Conversation
A `ssr: false` Nuxt build still produces a Nitro server bundle, but the module skipped the server inject and then uploaded the whole output directory. The CLI failed on the uninjected server chunks, so server exceptions had no symbolication. The upload also carried no release flags, so each deploy made a second release from the checkout directory name. - Decide the server inject from the server directory on disk, not from `nuxt.options.ssr`. - Upload only the injected directories (server and public) instead of the whole output directory. - Pass the configured release name, version, and build to every source map command. Generated-By: PostHog Desktop Task-Id: 5c59904a-3a05-43e0-9c90-71ee91e183fd
Contributor
Author
🦔 PostHog Review reviewed this pull requestFound 0 must fix, 0 should fix, 1 consider. Published 1 finding (view the review). Resolved comments: 1 fixed |
Contributor
Author
|
PostHog Review alpha 🦔 If you find any issues helpful - please reply "valid", "invalid", etc., for evaluation purposes 🙏 |
The close hook ran the server inject, the server upload and the public upload in one try block, so a rejection from either server command jumped to the catch and skipped the public upload. With `deleteAfterUpload: false` the early hook uploads nothing, which makes the close hook the only client sourcemap upload of the build — a server-only failure silently removed client-side symbolication while the build stayed green. - Give the server work and the public upload their own try blocks. - Name the failing directory in each log line. - Cover it with a `failServerUpload` case in tests/sourcemaps-ssr.test.mjs. Generated-By: PostHog Desktop Task-Id: 4f497a0e-0450-45ea-b2ac-20624c0789f5
Member
|
@PostHog/team-error-tracking i can reproduce this locally and looks good to me but i dont know nuxt enough, mind double checking? |
…fixnuxt-upload-source-maps-for-spa-294893
…h deletion modes The close hook uploaded the whole public directory whenever the early upload had not run, which is every build with `deleteAfterUpload: false`. A Nitro preset may nest the server directory inside the public one (`cloudflare-pages` writes `dist/_worker.js` under `dist/`), so that upload walked the server chunks a second time after the server upload had already sent them, and a failing server inject took the public upload down with it. The public upload now always runs in `nitro:build:public-assets`, which happens before Nitro writes the server bundle, so it can never overlap the server tree. The close hook keeps it only as a retry for a failed early upload. Generated-By: PostHog Desktop Task-Id: eacf25cc-c99b-40cb-ac6b-ee6cdd7970d0
dustinbyrne
approved these changes
Sep 4, 2026
dustinbyrne
left a comment
Contributor
There was a problem hiding this comment.
no comments, still worth a look from @PostHog/team-error-tracking
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.
Problem
@posthog/nuxtSPA production build (ssr: false) with source maps enabled loses server-side symbolication, and each deploy adds an unwanted release.ssr: falsebuild still gets a Nitro server bundle. The module skipped the server inject for it, then uploaded the whole.outputdirectory, so the CLI hit server chunks that carry no chunk id and failed. The module catches that error, so the build stays green and the failure is silent.Changes
nuxt.options.ssr, so a SPA server bundle is injected and anuxt generatebuild (no server bundle) is still skipped. This keeps #3005 fixed.--release-name,--release-version, and--buildare now shared by inject and upload.ssr: true.outputssr: false, Nitro server bundle.output→ CLI errornuxt generate, no server bundle.outputPublic source maps keep the existing two-step behaviour: they are uploaded and deleted before Nitro writes its asset manifest (#4275), and the close hook only uploads them when that early upload did not run or failed — without deleting them, because the manifest already lists them.
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Fully autonomous
ssr: falsemeans "no server output". That holds fornuxt generateonly. The disk check covers both builds with one rule..outputupload and adding an inject of the whole output directory. Injecting a preset directory that the module never controls is wider than the defect and can rewrite files the preset already hashed.packages/nuxt/tests/sourcemaps-ssr.test.mjsgains a SPA case with a server bundle, anuxt generatecase, and a release-flag case.node tests/sourcemaps-ssr.test.mjspasses.pnpm lintandpnpm build. Workspace dependencies are not installed in this environment, andtests/nuxt5-consumer.test.mjsfails for the same reason, before and after this change.Created with PostHog Desktop from this inbox report.