Skip to content

fix(scan): triage sweep across open issues - #437

Merged
aidenybai merged 8 commits into
mainfrom
fix/triage-open-issues
May 2, 2026
Merged

aidenybai merged 8 commits into
mainfrom
fix/triage-open-issues

Conversation

@aidenybai

@aidenybai aidenybai commented May 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Triage pass over the open issues queue. Each commit is atomic and references the issues it closes; this PR description aggregates them.

Issue Title Commit
#287, #336 Module parse failed: Unexpected token (?.()) in old webpack/babel-loader configs chore(scan): lower published bundle target from esnext to es2019
#372 Refused to create a worker from blob: (CSP worker-src 'self') fix(scan): make OffscreenCanvas worker CSP-safe + add opt-out
#402 Incorrect production-env detection in multi-root setups (Next.js dev overlay) fix(scan): correct production-environment detection + scaffold new options
#403 "could of" / "would of" -> "could have" / "would have" in AI prompts fix(scan): use "could have" instead of "could of" in optimize prompts
#415 Cannot select prompt text inside the toolbar bundled into the safeArea commit (text-selection section)
#430 Toolbar overlaps Next.js dev icon feat(scan): add safeArea option + allow text selection inside toolbar
#400, #404 "React Scan prevents React DevTools from working" / Firefox break likely resolved by the #402 fix — both bugs' documented workaround was react-scan/all-environments, which bypassed the same broken production check

What's in each commit

1. fix(scan): use "could have" instead of "could of" in optimize prompts — #403

Pure text fix in optimize.tsx. 4 instances of the same prompt template.

2. chore(scan): lower published bundle target from esnext to es2019 — #287, #336

esbuild was emitting ?., ??, ?.() straight into the published bundles. Older webpack + babel-loader configs without @babel/preset-env for ES2020 fail to parse them. Lowering to target: 'es2019' transpiles those operators down so the same bundles parse in those toolchains without forcing every consumer to add a babel transform.

Verified the published auto.global.js, index.mjs, index.js, and lite/index.mjs contain 0 occurrences of ?. after the rebuild.

3. fix(scan): correct production-environment detection + scaffold new options — #402

getIsProduction() cached true after seeing any single production renderer. The Next.js dev overlay registers a production React build alongside the user's dev React, so React Scan disabled itself.

The fix preserves a permanent false cache once a non-production renderer is observed, but no longer caches true — a later dev renderer can still flip the result, even after the production overlay registered first.

Adds a unit-test matrix that mocks bippy's getRDTHook / detectReactBuildType:

  • empty renderers → null (don't know yet)
  • all production → true
  • mixed → false
  • production-then-dev (regression guard) → flips to false
  • dev-then-anything → stays false (cache)

Also adds safeArea and useOffscreenCanvasWorker to the Options interface plus runtime validation; wiring is in commit 5.

4. fix(scan): make OffscreenCanvas worker CSP-safe + add opt-out — #372

  • New useOffscreenCanvasWorker: false Options field skips the worker entirely for users on a strict CSP.
  • The catch block suppresses CSP failures unless _debug: 'verbose' is set, so the console isn't spammed for a fallback that's working as designed.
  • Verbose-mode users still get the original console.warn for genuine non-CSP failures.

5. feat(scan): add safeArea option + allow text selection inside toolbar — #430, #415

safeArea (#430) — toolbar viewport insets. Accepts number | { top?, right?, bottom?, left? }. Default 24. Refactors the SAFE_AREA constant out of widget positioning math (calculatePosition, calculateNewSizeAndPosition, WindowDimensions, collapsed-corner positioning, max-size CSS) into a getSafeArea() helper that resolves per-edge from options at runtime. Module-init defaults still use the constant — options haven't been set yet at that point. parseSafeAreaOption is a standalone utility with a unit-test matrix covering arrays, NaN, negative numbers, partial objects, and non-objects.

Toolbar text selection (#415) — the toolbar root has select-none (so dragging the bar doesn't start a text selection) and its onPointerDown handler calls e.preventDefault() (which suppresses focus and selection on every click). Together they made the AI-prompt <pre> impossible to highlight. Fix:

  • New TOOLBAR_INTERACTIVE_SELECTOR constant (single source of truth) lists elements that bypass drag and accept native focus/selection. Used from both the JSX and the CSS.
  • handleDrag bails — without preventDefault() — when the pointerdown lands on button, a, input, textarea, select, pre, [contenteditable], [data-react-scan-selectable].
  • Flat CSS selectors (no nesting) so the rule applies in older Firefox/Safari that lack native CSS nesting.

defaultWidgetConfig is preserved as a deprecated alias of getDefaultWidgetConfig() for one minor version.

What I deliberately didn't fix

Test plan

Local verification:

  • pnpm --filter react-scan typecheck — passes
  • pnpm --filter react-scan test — 177/177 passing (was 161; +16 new tests for getIsProduction and parseSafeAreaOption regression matrices)
  • pnpm --filter react-scan build — succeeds, all entries
  • All published bundles (auto.global.js, index.mjs, index.js, lite/index.mjs) contain 0 occurrences of ?.

Suggested manual checks for reviewer:

  • Drop react-scan into a Next.js 15 dev project — toolbar should now appear (was suppressed by Incorrect production enviroment detection #402)
  • Open the AI optimize panel from a notification, try to select prompt text and copy — should work
  • scan({ safeArea: { right: 96, bottom: 96 } }) — toolbar should sit further from the bottom-right corner
  • Strict-CSP page (worker-src 'self') without console warnings — outlines should still render via main thread

Note

Medium Risk
Touches core environment gating, outline rendering initialization, and toolbar positioning/drag behavior; regressions could disable scan or break overlays in some apps, though changes are guarded with new unit tests and fallbacks.

Overview
Fixes production-environment detection by changing getIsProduction() to return null until a renderer is registered, never cache true, and cache false permanently once any non-production renderer is seen (plus a new regression test matrix).

Adds new scan() options: safeArea (numeric or per-edge insets) to keep the toolbar away from viewport edges/other overlays, and useOffscreenCanvasWorker to opt out of blob-worker outline rendering for strict CSP; worker init failures now fall back silently unless _debug: 'verbose'.

Refactors widget sizing/positioning (including RTL and collapsed states) to use runtime safe-area insets, updates drag handling and CSS so text inputs/<pre> content inside the toolbar can be selected/focused, and lowers published browser bundle targets to es2019 for older tooling compatibility.

Reviewed by Cursor Bugbot for commit 22b8f46. Bugbot is set up for automated code reviews on this repo. Configure here.

aidenybai added 5 commits May 1, 2026 07:13
Older webpack/babel-loader configs without @babel/preset-env for ES2020
fail to parse the optional chaining (\`?.\`) and nullish coalescing (\`??\`)
that esbuild emits at \`target: esnext\`. Targeting es2019 transpiles
those operators down so the same bundles parse in those toolchains
without forcing every consumer to add a babel transform.

Verified the published \`auto.global.js\`, \`index.mjs\`, \`index.js\`, and
\`lite/index.mjs\` contain 0 occurrences of \`?.\` after the rebuild.

Closes #287, #336.
…tions

Production-environment detection (#402)
---------------------------------------
\`getIsProduction()\` cached \`true\` as soon as any single registered
React renderer reported a production build. Modern dev tooling commonly
mounts multiple roots from different React copies — the Next.js dev
overlay ships a production React build alongside the user's dev React,
and the extra production renderer was enough to disable React Scan
entirely.

The fix preserves a permanent \`false\` cache once a non-production
renderer is observed, but no longer caches \`true\` — a later dev
renderer can still flip the result, even after the production overlay
registered first.

Adds a unit-test matrix that mocks bippy's \`getRDTHook\` /
\`detectReactBuildType\` to lock the contract:
- empty renderers -> null (don't know yet)
- all production -> true
- mixed -> false
- production-then-dev (regression guard) -> flips to false
- dev-then-anything -> stays false (cache)

This likely also resolves #404 / #400 where the documented workaround is
\`react-scan/all-environments\`, which bypassed the same broken check.

New Options scaffolding
-----------------------
Adds \`safeArea\` and \`useOffscreenCanvasWorker\` to the Options
interface, plus runtime validation. The actual wiring is in the
follow-up commit.
A Content-Security-Policy of \`worker-src 'self'\` rejects the blob:
worker React Scan creates for OffscreenCanvas rendering. The fallback
to main-thread rendering already worked, but the failure path
\`console.warn\`'d on every page load.

Changes:
- \`useOffscreenCanvasWorker: false\` (new Options field) lets users
  with strict CSP skip the attempt entirely.
- The catch block now suppresses CSP-style failures unless the user
  set \`_debug: 'verbose'\`, so the console isn't spammed for a fallback
  that's working as designed.

Closes #372.
safeArea (#430)
---------------
Other dev overlays (most notably the Next.js dev indicator) sit in
the same screen corners as the React Scan toolbar. The expanded
toolbar and collapsed bookmark would overlap them with no way for
the user to inset the toolbar.

Adds an \`Options.safeArea\` field that accepts either:
- a single number (insets all four edges, default 24)
- a per-edge \`{ top?, right?, bottom?, left? }\` object

Refactors the hard-coded \`SAFE_AREA\` constant out of widget
positioning math (\`calculatePosition\`,
\`calculateNewSizeAndPosition\`, \`WindowDimensions\`,
collapsed-corner positioning, max-size CSS) to read from a new
\`getSafeArea()\` helper that resolves per-edge from options at
runtime.

Module-init defaults still use the raw \`SAFE_AREA\` constant —
options haven't been set yet at that point, and reading them
through \`ReactScanInternals.options.value\` from a top-level
module would create a load-bearing optional chain through a
circular import.

\`defaultWidgetConfig\` is preserved as a deprecated alias of
\`getDefaultWidgetConfig()\` for one minor version.

\`parseSafeAreaOption\` is split out as a standalone utility (one
function per file per AGENTS.md) with a unit-test matrix covering
arrays, NaN, negative numbers, partial objects, and non-objects.

Toolbar text selection (#415)
-----------------------------
The toolbar root has \`select-none\` (so dragging the bar doesn't
start a text selection), and its root \`onPointerDown\` handler
calls \`e.preventDefault()\` (which suppresses focus and selection
on every click). Together those two made the AI-prompt \`<pre>\`
text impossible to highlight or copy.

Fix:
- New \`TOOLBAR_INTERACTIVE_SELECTOR\` constant lists the elements
  that should bypass drag and accept native focus/selection. Used
  from both the JSX (drag handler bail-out) and the CSS
  (\`user-select: text\` re-enable). Single source of truth.
- \`handleDrag\` now bails — without calling \`preventDefault()\` —
  when the pointerdown lands on a button, link, input, textarea,
  select, pre, contenteditable, or \`[data-react-scan-selectable]\`.
- Flat CSS selectors (no nesting) so the rule applies in older
  Firefox/Safari that lack native CSS nesting.

Note: this is a small behavior change for button clicks — the
original code called \`preventDefault()\` even on button hits;
buttons now receive native focus on pointerdown.
@vercel

vercel Bot commented May 1, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
react-scan Ready Ready Preview, Comment May 1, 2026 2:57pm

@pkg-pr-new

pkg-pr-new Bot commented May 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/react-scan@437

commit: 22b8f46

\`safe-area.ts\` and \`parse-safe-area-option.ts\` each defined their own
copy of the same two predicates. If validation logic ever diverged
(e.g. one gets a bugfix the other doesn't), runtime behavior would
silently differ between option validation at \`scan()\` time and the
\`getSafeArea()\` read path.

Extracts both into their own files in \`web/utils/\` (one utility per
file per AGENTS.md) and imports them from both consumers.

Addresses Cursor Bugbot review on #437.
The predicate accepts \`value >= 0\`, which includes zero, but the
\`isFinitePositive\` name implies strictly > 0 (the standard math
meaning of "positive"). The error messages already correctly say
"non-negative number". Renames the helper file + export to match
the actual semantics so a future caller doesn't rely on the misleading
name to exclude zero.

Addresses Cursor Bugbot review on #437.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 and found 1 potential issue.

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 8cd91fb. Configure here.

Comment thread packages/scan/src/web/widget/helpers.ts Resolved
The pre-asymmetric \`SAFE_AREA\` constant masked a longstanding bug in
the RTL positioning math. \`calculatePosition\` used
\`x = -leftBound\` for right corners and \`x = -rightBound\` for left
corners — fine when both bounds embed the same number, but wrong when
\`safeArea.left !== safeArea.right\`.

In RTL the toolbar is right-anchored (\`position: fixed\` with both
\`left:0\` and \`right:0\` plus an explicit width pins to inline-end),
so a translateX(-N) leaves an N-pixel gap on the *physical* right
edge. To inset physical right by \`safeArea.right\` and physical left
by \`safeArea.left\`, the corner offsets must be:
- right corners: \`-safeArea.right\`
- left corners: \`-(windowWidth - width - safeArea.left)\`

Same fix applied to the bound clamping in \`calculateNewSizeAndPosition\`.
With symmetric values these collapse to the original
\`-leftBound\` / \`-rightBound\` so behavior is unchanged for users
who don't set \`safeArea\`.

Addresses Cursor Bugbot review on #437.

This branch was successfully deployed

1 active deployment
Preview — 22b8f462 Deployed May 1, 2026 by vercel[bot]
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