Skip to content

fix(adapter-nextjs): don't enable browser source maps for Crashlytics until upload is supported - #714

Open
abhis3 wants to merge 1 commit into
feat/adapter-nextjs-image-optimization-offfrom
fix/adapter-nextjs-no-public-sourcemaps
Open

abhis3 wants to merge 1 commit into
feat/adapter-nextjs-image-optimization-offfrom
fix/adapter-nextjs-no-public-sourcemaps

Conversation

@abhis3

@abhis3 abhis3 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Important

Stacked on #713. Merge #713 first, then retarget this PR to main before merging. GitHub only retargets it automatically if #713's branch is deleted.

Problem

With CRASHLYTICS_UPLOAD_MAPPING=true, the adapter's modifyConfig sets productionBrowserSourceMaps: true. Nothing on Cloud Run uploads those maps to Crashlytics or removes them from the image yet. So GET /_next/static/chunks/*.js.map returns 200 with the full sourcesContent and Cache-Control: public, max-age=31536000, immutable, which publishes the app's client source.

Change

  • modifyConfig no longer turns on productionBrowserSourceMaps for CRASHLYTICS_UPLOAD_MAPPING. When the env var is set (true or 1), 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.
  • The app's own productionBrowserSourceMaps setting (true or false) is never changed.
  • A TODO marks where to turn this back on, once source maps are uploaded and stripped during the build.
  • README: updates the "Browser source maps" bullet and the CRASHLYTICS_UPLOAD_MAPPING row.
  • Tests: the Crashlytics test now checks that productionBrowserSourceMaps stays unset when the env var is true or 1, and that the warning is logged once. It also checks that a user's true or false is kept, with or without the env var, and that nothing is logged when the env var isn't set.

Testing

  • npm test in packages/@google-cloud/adapter-nextjs, on Node 18.20.8 and Node 22.23.4: 44 passing, 11 pending. The pending ones are the SMOKE_TEST=1 suites, the same as on the base branch. npm run build is clean on both.
  • npm run lint:quiet passes, with no new warnings in the touched files.

… 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.
@abhis3 abhis3 self-assigned this Nov 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +146 to +148
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.",
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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      );

Comment on lines +265 to +275
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"));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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      }

@abhis3
abhis3 added this pull request to stack #716 November 10, 2026 16:37
@abhis3
abhis3 marked this pull request as ready for review November 10, 2026 21:58

This branch has not been deployed

No deployments
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