Repository navigation
fix(adapter-nextjs): don't enable browser source maps for Crashlytics until upload is supported - #714
Conversation
… until upload is supported With CRASHLYTICS_UPLOAD_MAPPING=true, modifyConfig set productionBrowserSourceMaps: true. Nothing on Cloud Run uploads those maps to Crashlytics or removes them from the image yet, so /_next/static/chunks/*.js.map was served publicly, with the full sourcesContent and an immutable one-year Cache-Control. modifyConfig now ignores CRASHLYTICS_UPLOAD_MAPPING, logs one warning that says why, and never changes productionBrowserSourceMaps, so a user's own setting is kept. A TODO marks where to turn it back on once source maps are uploaded and stripped during the build.
There was a problem hiding this comment.
Code Review
This pull request updates the Next.js adapter to ignore the CRASHLYTICS_UPLOAD_MAPPING environment variable and leave productionBrowserSourceMaps unchanged, logging a warning instead. This prevents the application's source maps from being served publicly from /_next/static since Crashlytics source-map upload is not yet supported on Cloud Run. The feedback suggests dynamically displaying the actual value of CRASHLYTICS_UPLOAD_MAPPING (e.g., '1' or 'true') in the warning message to avoid confusion, along with updating the corresponding test assertions.
| console.warn( | ||
| "[adapter-nextjs] Warning: Ignoring CRASHLYTICS_UPLOAD_MAPPING=true: Crashlytics source-map upload isn't available on Cloud Run yet, and enabling browser source maps would serve the app's source publicly. NextConfig productionBrowserSourceMaps is left unchanged.", | ||
| ); |
There was a problem hiding this comment.
When CRASHLYTICS_UPLOAD_MAPPING is set to "1", the warning message still hardcodes CRASHLYTICS_UPLOAD_MAPPING=true, which can be confusing to users who configured it with "1".\n\nConsider dynamically including the actual value of the environment variable in the warning message to improve clarity.
console.warn(\n "[adapter-nextjs] Warning: Ignoring CRASHLYTICS_UPLOAD_MAPPING=" + process.env.CRASHLYTICS_UPLOAD_MAPPING + ": Crashlytics source-map upload isn't available on Cloud Run yet, and enabling browser source maps would serve the app's source publicly. NextConfig productionBrowserSourceMaps is left unchanged."\n );| const ignoredLogs = (): string[] => | ||
| warnLogs.filter((w) => w.includes("Ignoring CRASHLYTICS_UPLOAD_MAPPING=true")); | ||
|
|
||
| for (const value of ["true", "1"]) { | ||
| process.env.CRASHLYTICS_UPLOAD_MAPPING = value; | ||
| warnLogs = []; | ||
| const result = modifyConfig<NextConfig>(deepFreeze({}), ctx); | ||
| assert.strictEqual(result.productionBrowserSourceMaps, undefined); | ||
| assert.strictEqual(ignoredLogs().length, 1); | ||
| assert.ok(ignoredLogs()[0].includes("would serve the app's source publicly")); | ||
| } |
There was a problem hiding this comment.
Update the test assertions to match the dynamic warning message and verify that the actual value of CRASHLYTICS_UPLOAD_MAPPING is correctly reflected in the logs.
const ignoredLogs = (): string[] =>\n warnLogs.filter((w) => w.includes("Ignoring CRASHLYTICS_UPLOAD_MAPPING"));\n\n for (const value of ["true", "1"]) {\n process.env.CRASHLYTICS_UPLOAD_MAPPING = value;\n warnLogs = [];\n const result = modifyConfig<NextConfig>(deepFreeze({}), ctx);\n assert.strictEqual(result.productionBrowserSourceMaps, undefined);\n assert.strictEqual(ignoredLogs().length, 1);\n assert.ok(ignoredLogs()[0].includes("Ignoring CRASHLYTICS_UPLOAD_MAPPING=" + value));\n assert.ok(ignoredLogs()[0].includes("would serve the app's source publicly"));\n }
Important
Stacked on #713. Merge #713 first, then retarget this PR to
mainbefore merging. GitHub only retargets it automatically if #713's branch is deleted.Problem
With
CRASHLYTICS_UPLOAD_MAPPING=true, the adapter'smodifyConfigsetsproductionBrowserSourceMaps: true. Nothing on Cloud Run uploads those maps to Crashlytics or removes them from the image yet. SoGET /_next/static/chunks/*.js.mapreturns 200 with the fullsourcesContentandCache-Control: public, max-age=31536000, immutable, which publishes the app's client source.Change
modifyConfigno longer turns onproductionBrowserSourceMapsforCRASHLYTICS_UPLOAD_MAPPING. When the env var is set (trueor1), it logs one warning:[adapter-nextjs] Warning: Ignoring CRASHLYTICS_UPLOAD_MAPPING=true: Crashlytics source-map upload isn't available on Cloud Run yet, and enabling browser source maps would serve the app's source publicly. NextConfig productionBrowserSourceMaps is left unchanged.productionBrowserSourceMapssetting (trueorfalse) is never changed.CRASHLYTICS_UPLOAD_MAPPINGrow.productionBrowserSourceMapsstays unset when the env var istrueor1, and that the warning is logged once. It also checks that a user'strueorfalseis kept, with or without the env var, and that nothing is logged when the env var isn't set.Testing
npm testinpackages/@google-cloud/adapter-nextjs, on Node 18.20.8 and Node 22.23.4: 44 passing, 11 pending. The pending ones are theSMOKE_TEST=1suites, the same as on the base branch.npm run buildis clean on both.npm run lint:quietpasses, with no new warnings in the touched files.