Skip to content

feat: add ?grab=1 query-flag loader integrations for Vite and Next.js#466

Open
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1781119395-flag-loader
Open

feat: add ?grab=1 query-flag loader integrations for Vite and Next.js#466
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
devin/1781119395-flag-loader

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds opt-in loader integrations so React Grab can be enabled in any environment, including production, via a URL flag instead of being hardcoded to dev builds.

New entry points on the react-grab package:

  • react-grab/vitereactGrab() Vite plugin that uses transformIndexHtml to prepend an inline loader snippet into <head>.
  • react-grab/next<ReactGrab /> component (plain inline <script>, works in both App router layout.tsx and Pages router _document.tsx).

Both render the same tiny inline snippet (createFlagLoaderSnippet in packages/react-grab/src/utils/create-flag-loader-snippet.ts):

flag = searchParams.get("grab")
if (flag is "1"/"true")  sessionStorage["react-grab:flag-enabled"] = "true"
if (flag is "0"/"false") remove it
if enabled -> inject <script src="https://unpkg.com/react-grab/dist/index.global.js">

sessionStorage persistence keeps React Grab active across navigations/reloads within the tab session after visiting once with ?grab=1; ?grab=0 turns it off.

Shared options: flag (query param name, default "grab"), src (script URL), enabled (set false to skip injection entirely).

Other changes:

  • Added ./vite and ./next exports + build entries (cjs/esm + dts), changeset, README docs.
  • skills/react-grab/SKILL.md whitespace change is from pnpm format (oxfmt).

Link to Devin session: https://app.devin.ai/sessions/5f712600fa3f47d4acc0965a2f1ac873
Requested by: @aidenybai


Note

Low Risk
Additive integrations and docs; optional third-party script load only when users opt in via URL flag, with no changes to core grab runtime behavior.

Overview
Adds opt-in production loading for React Grab via URL query flags (?grab=1 / ?grab=true), with sessionStorage persistence for the tab session and ?grab=0 to disable.

New package entry points react-grab/vite (reactGrab() plugin) and react-grab/next (<ReactGrab />) both inject the same inline loader from createFlagLoaderSnippet, which only fetches the global bundle when the flag is active. Shared options: flag, src, enabled. The Vite plugin can also turn on build.sourcemap by default (unless already set or sourcemap: false).

Build exports and README docs for the query-flag loader are included; skills/react-grab/SKILL.md has a minor formatting-only tweak.

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


Summary by cubic

Adds an opt-in flag loader for react-grab via react-grab/vite and react-grab/next, so ?grab=1 can enable React Grab in any environment, including production. The flag persists for the tab session and ?grab=0 turns it off.

  • New Features

    • react-grab/vite: Vite plugin that prepends an inline loader script via transformIndexHtml, and enables build sourcemaps by default unless you already set them (sourcemap: false to opt out).
    • react-grab/next: <ReactGrab /> component that injects the same inline script (works in App and Pages routers).
    • Loader behavior: reads ?grab=1/true or ?grab=0/false, persists to sessionStorage, and conditionally injects <script src="https://unpkg.com/react-grab/dist/index.global.js" crossorigin="anonymous">.
    • Options: flag (default "grab"), src (override script URL), enabled (set false to skip), plus Vite-only sourcemap (default true).
    • Added ./vite and ./next exports with build entries and docs updates.
  • Migration

    • For Next.js, set productionBrowserSourceMaps: true in next.config.ts.

Written for commit f173ecb. Summary will update on new commits.

Review in cubic

devin-ai-integration Bot and others added 2 commits June 10, 2026 19:23
Co-Authored-By: Aiden Bai <aiden.bai05@gmail.com>
Co-Authored-By: Aiden Bai <aiden.bai05@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
react-grab-storybook Ready Ready Preview, Comment Jun 10, 2026 7:43pm
react-grab-website Ready Ready Preview, Comment Jun 10, 2026 7:43pm

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@react-grab/cli@466
npm i https://pkg.pr.new/grab@466
npm i https://pkg.pr.new/react-grab@466

commit: f173ecb

@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 7be5799. Configure here.

script.src = ${src};
script.crossOrigin = "anonymous";
document.head.appendChild(script);
} catch (error) {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Query flag ignored on client navigations

Medium Severity

The loader reads window.location.search only when the inline snippet runs (typically the first full HTML load). Client-side route changes that add or remove ?grab=1 / ?grab=0 do not re-run that logic, so enabling or disabling via the query flag can fail until a full reload even though the docs say ?grab=0 turns React Grab off.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7be5799. Configure here.

…ourcemap config

Co-Authored-By: Aiden Bai <aiden.bai05@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Tested end-to-end — all scenarios passed, CI fully green.

Test 1: Vite plugin — dev server (e2e-app) — PASS
  • No flag: __REACT_GRAB__ undefined, no loader script
  • ?grab=1: unpkg script appended, react-grab initialized ("React Grab v0.1.44" banner)
  • Overlay UI renders (label NestedCard.button on hover)
  • Plain URL after ?grab=1: still loads via sessionStorage
  • ?grab=0: flag cleared, absent on subsequent loads

Vite dev overlay

Note: synthetic Ctrl+C doesn't fire in browser automation, so overlay was demonstrated via __REACT_GRAB__.activate() + hover; script loading/init verified directly.

Test 2: Vite plugin — production build — PASS
  • Inline snippet present in built dist/index.html head
  • Preview + ?grab=1 loads react-grab in the prod build
  • With the sourcemap commit, .js.map files are emitted by default

Vite prod preview

Test 3: Next.js <ReactGrab /> (apps/website) — PASS
  • No flag: nothing loaded
  • ?grab=1: /script.js appended (custom src option), toolbar visible

Next.js toolbar

Sourcemaps: the Vite plugin now enables build.sourcemap unless already set (sourcemap: false to opt out); README documents productionBrowserSourceMaps: true for Next.js.

Session

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