Skip to content

fix(cli): harden ported wizard codemods against real-world project shapes - #2565

Open
sentry-junior[bot] wants to merge 1 commit into
feat/cli-wizard-sveltekit-remix-react-routerfrom
feat/cli-wizard-port-review-fixes
Open

sentry-junior[bot] wants to merge 1 commit into
feat/cli-wizard-sveltekit-remix-react-routerfrom
feat/cli-wizard-port-review-fixes

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Stacked on #2526. It fixes the Warden and Bugbot findings on that PR where the fix changes the wizard's behaviour relative to upstream getsentry/sentry-wizard (v9.1.0).

Behaviour changes vs upstream sentry-wizard

  • React Router handleError (function export, error-only params): binds request from the handler's parameters, adding { request } when needed. Upstream used request unbound, so the handler threw. (CC6-JTR)
  • React Router handleError (const or arrow export): Sentry.captureException now goes first in the body, as it already did for function exports, so an early return no longer skips it. (6BK-CX9)
  • React Router handleError (named second parameter): the guard reads args.request / context.request from the existing parameter instead of assuming a destructured request.
  • React Router vite.config: sentryReactRouter(…, <env>) gets the defineConfig callback's own parameter. If there is none, it adds config. A destructured one (({ mode })) is renamed to config and destructured again in the body. Upstream always passed config. (NTK-WRA)
  • React Router start script: keeps the project's own command and adds NODE_ENV=production NODE_OPTIONS='--import ./instrument.server.mjs' in front of it. Upstream replaced any start script without NODE_OPTIONS with react-router-serve ./build/server/index.js. A default project gets the same command as before. (55R-DRR)
  • React Router NODE_OPTIONS merge: an unquoted value ends at the first whitespace, as in a shell. The import is merged in before any command (e.g. pm2), and sibling variables like PORT=3000 stay separate. Upstream allowlisted commands and absorbed the following tokens. (QRC-596)
  • Remix root export { ErrorBoundary }: the existing boundary is found and instrumented. Upstream added a duplicate ErrorBoundary. (X9W-F69)
  • Remix root export const ErrorBoundary: arrow and function-expression boundaries are instrumented, and an expression body becomes a block body. Upstream left them unchanged. (SFV-22K)
  • Remix root capture: captureRemixErrorBoundaryError(<name>) goes right after the useRouteError() read and uses the boundary's own binding (e.g. routeError). Upstream used error before the last statement. (UWP-WMX)
  • Remix root, boundary not resolvable (e.g. export const ErrorBoundary = withX(…)): the wizard warns with the line to add. Upstream skipped it silently.
  • Remix handleError: wraps the existing handler as a whole (Sentry.wrapHandleErrorWithSentry(<original>)), which keeps async, parameters, expression bodies and handlers built elsewhere. Upstream copied the body into a fixed non-async arrow, or threw on expression bodies. (7JW-LJX, 484-EKL)
  • Remix example page: also writes app/routes/api.sentry-example-api.(ts|js), the route the page's button fetches. Upstream never created it, so the button got a 404. (HTF-GHR)
  • Remix custom Express server: the instrumentation import is relative to the server file (../instrumentation.server.mjs from server/index.ts). Upstream always used ./. (QPF-CJ8)
  • SvelteKit Svelte 5 example page: isConnected uses $state(true), so the connectivity warning and the disabled button update. (XYK-TL6)

Product calls

  • The start script keeps the user's command. For a default react-router-serve ./build/server/index.js project, the result matches the React Router manual setup docs.
  • The Remix handleError output is the Sentry.wrapHandleErrorWithSentry(...) form from the Remix manual setup docs, wrapped around the user's own handler.
  • The Remix example API route uses the same loader shape as the React Router wizard's route, at the path the Remix example page already fetches.

via @BYK.

--

View Session [Sentry]

…apes

React Router:
- handleError: report before the handler's own code runs, for both function
  and const exports, and bind `request` from the handler's own parameters.
- vite: pass the defineConfig callback's own config env to sentryReactRouter.
- package.json: keep the project's start command and merge NODE_OPTIONS with
  shell semantics instead of replacing the command.

Remix:
- root: find `export { ErrorBoundary }` and `export const ErrorBoundary`
  boundaries, and capture under the name useRouteError is bound to.
- handleError: wrap the whole existing handler so async and params survive.
- example page: create the /api/sentry-example-api route it fetches.
- custom Express servers: import the instrumentation file relative to the
  server file.

SvelteKit:
- Svelte 5 example page: make isConnected reactive with $state.
@sentry-junior
sentry-junior Bot requested a review from BYK November 27, 2026 17:20
@sentry-junior
sentry-junior Bot added this pull request to stack #2566 November 27, 2026 17:20
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 27, 2026 5:20pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 27, 2026 5:20pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 27, 2026

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cfcf361. Configure here.

fn.body = b.blockStatement([destructure, b.returnStatement(fn.body)]);
}
return configEnv.name;
}

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.

Vite config param shadows existing bindings

High Severity

ensureConfigEnvParam always names the defineConfig callback parameter config when the existing parameter is missing or destructured. That collides with an existing config binding in the callback or outer scope, so the rewritten file can be a syntax error (config declared twice) or silently read Vite's ConfigEnv instead of the user's object.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cfcf361. Configure here.

]),
capture("error"),
);
return false;

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.

Typed useRouteError duplicates error binding

Medium Severity

captureErrorInBoundary only treats a bare useRouteError() call as the existing read. A TypeScript assertion or non-null assertion around that call is missed, so the wizard inserts a second const error = useRouteError() into boundaries that already bind error, which is a duplicate declaration.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cfcf361. Configure here.

Comment on lines +113 to +116

fn.params[0] = configEnv;
const destructure = b.variableDeclaration("const", [
b.variableDeclarator(firstParam, configEnv),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Defaulted destructured defineConfig parameters produce invalid Vite config

For a valid callback such as ({ mode } = {}) => ({ plugins: [] }), the codemod uses the defaulted parameter as a const binding and writes invalid JavaScript, leaving the project's Vite config unusable.

Evidence
  • addReactRouterPluginToViteConfig extracts object-returning defineConfig callbacks and passes their first parameter to ensureConfigEnvParam.
  • That helper handles identifiers and missing parameters, but passes any other parameter shape—including an AssignmentPattern from ({ mode } = {})—as the const declarator id. This generates an invalid binding such as const { mode } = {} = config.
  • instrumentViteConfig generates code and writes it directly to vite.config.ts or vite.config.js; it does not reparse or validate the generated file before writing.

Identified by Warden · code-review · NYZ-8Q9

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — cfcf3610 Deployed Nov 27, 2026 by vercel[bot]
Preview – sentry-local — cfcf3610 Deployed Nov 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant