-
Notifications
You must be signed in to change notification settings - Fork 333
feat(react-grab): render scan with copyable performance trace #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f187830
b1da6bf
5eded55
875c2a4
320e46b
40899d3
cf7c853
9742048
29d319f
6eb670f
78aa07a
1c8347a
cf358ba
1cc5e35
b35fdb8
a5cb520
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "react-grab": minor | ||
| --- | ||
|
|
||
| Add a render scan that highlights re-rendering components on a canvas overlay, and copies an agent-readable performance trace (per-commit fiber detail with render reasons and source, plus long-animation-frames) to the clipboard when you stop scanning. The toolbar shows a "Copied" pill on stop. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { Geist_Mono, Inter } from "next/font/google"; | |
| import { ThemeProvider } from "next-themes"; | ||
| import { TooltipProvider } from "@/components/ui/tooltip"; | ||
| import "./globals.css"; | ||
| import Script from "next/script"; | ||
|
|
||
| const inter = Inter({ | ||
| variable: "--font-inter", | ||
|
|
@@ -35,8 +36,10 @@ export default function RootLayout({ | |
| suppressHydrationWarning | ||
| className={`${inter.variable} ${geistMono.variable} antialiased`} | ||
| > | ||
| <head> | ||
| <Script src="/script.js" strategy="beforeInteractive" /> | ||
|
vercel[bot] marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| </head> | ||
| <body> | ||
| <script src="/script.js" defer /> | ||
| <ThemeProvider attribute="class" defaultTheme="system" enableSystem> | ||
| <TooltipProvider>{children}</TooltipProvider> | ||
| </ThemeProvider> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { test, expect, type ReactGrabPageObject } from "./fixtures.js"; | ||
| import type { Page } from "@playwright/test"; | ||
|
|
||
| const ATTRIBUTE_NAME = "data-react-grab"; | ||
|
|
||
| const waitForToolbar = async (reactGrab: ReactGrabPageObject) => { | ||
| await expect.poll(() => reactGrab.isToolbarVisible(), { timeout: 2000 }).toBe(true); | ||
| }; | ||
|
|
||
| // The scan button is independent of the overlay/active flow, so it can't go | ||
| // through the shared clickToolbarAction helper (which waits for activation). | ||
| const clickScanButton = async (page: Page) => { | ||
| await page.evaluate((attrName) => { | ||
| const host = document.querySelector(`[${attrName}]`); | ||
| const root = host?.shadowRoot?.querySelector(`[${attrName}]`); | ||
| const button = root?.querySelector<HTMLButtonElement>( | ||
| '[data-react-grab-toolbar-action="scan"]', | ||
| ); | ||
| button?.click(); | ||
| }, ATTRIBUTE_NAME); | ||
| }; | ||
|
|
||
| const isScanCanvasPresent = (page: Page): Promise<boolean> => | ||
| page.evaluate(() => Boolean(document.querySelector("[data-react-grab-scan-canvas]"))); | ||
|
|
||
| const isScanCopiedVisible = (page: Page): Promise<boolean> => | ||
| page.evaluate((attrName) => { | ||
| const host = document.querySelector(`[${attrName}]`); | ||
| const root = host?.shadowRoot?.querySelector(`[${attrName}]`); | ||
| return Boolean(root?.querySelector("[data-react-grab-scan-copied]")); | ||
| }, ATTRIBUTE_NAME); | ||
|
|
||
| test.describe("Render scan", () => { | ||
| test("starts and stops the scan canvas from the toolbar", async ({ reactGrab }) => { | ||
| await waitForToolbar(reactGrab); | ||
|
|
||
| await clickScanButton(reactGrab.page); | ||
| await expect.poll(() => isScanCanvasPresent(reactGrab.page), { timeout: 2000 }).toBe(true); | ||
| expect(await reactGrab.getToolbarActionPressed("scan")).toBe(true); | ||
|
|
||
| await clickScanButton(reactGrab.page); | ||
| await expect.poll(() => isScanCanvasPresent(reactGrab.page), { timeout: 2000 }).toBe(false); | ||
| expect(await reactGrab.getToolbarActionPressed("scan")).toBe(false); | ||
| }); | ||
|
|
||
| test("copies a trace and shows the Copied toast on stop", async ({ reactGrab }) => { | ||
| await waitForToolbar(reactGrab); | ||
|
|
||
| await clickScanButton(reactGrab.page); | ||
| // Force a React commit so the trace is non-empty (no trace -> no toast). | ||
| await reactGrab.page.getByTestId("add-element-button").click(); | ||
|
|
||
| await clickScanButton(reactGrab.page); | ||
| await expect.poll(() => isScanCopiedVisible(reactGrab.page), { timeout: 2000 }).toBe(true); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import type { Component } from "solid-js"; | ||
| import { FADE_DURATION_MS, FEEDBACK_DURATION_MS, PANEL_SHADOW } from "../constants.js"; | ||
| import { IconCheck } from "./icons/icon-check.jsx"; | ||
|
|
||
| interface CopiedPillProps { | ||
| text: string; | ||
| } | ||
|
|
||
| // Static "copied" pill that self-fades on a CSS animation; parent only mounts it. | ||
| export const CopiedPill: Component<CopiedPillProps> = (props) => { | ||
| return ( | ||
| <div | ||
| role="status" | ||
| aria-live="polite" | ||
| class="contain-layout shrink-0 flex items-center gap-0.5 py-1.5 px-2 w-fit h-fit max-w-[280px] rounded-full antialiased bg-[var(--rg-panel-bg)] [font-synthesis:none]" | ||
| style={{ | ||
| filter: `drop-shadow(${PANEL_SHADOW})`, | ||
| animation: `rg-copied-pill-out ${FADE_DURATION_MS}ms ease-out ${FEEDBACK_DURATION_MS - FADE_DURATION_MS}ms forwards`, | ||
| }} | ||
| > | ||
| <IconCheck size={14} aria-hidden="true" class="text-[var(--rg-text-primary-85)] shrink-0" /> | ||
| <span class="text-[var(--rg-text-primary)] text-[13px] leading-4 font-sans font-medium h-fit tabular-nums overflow-hidden text-ellipsis whitespace-nowrap min-w-0"> | ||
| {props.text} | ||
| </span> | ||
| </div> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import type { Component } from "solid-js"; | ||
|
|
||
| interface IconScanProps { | ||
| size?: number; | ||
| class?: string; | ||
| } | ||
|
|
||
| export const IconScan: Component<IconScanProps> = (props) => { | ||
| const size = () => props.size ?? 14; | ||
|
|
||
| return ( | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width={size()} | ||
| height={size()} | ||
| viewBox="0 0 24 24" | ||
| fill="currentColor" | ||
| class={props.class} | ||
| > | ||
| <path | ||
| fill-rule="evenodd" | ||
| clip-rule="evenodd" | ||
| d="M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41L13.7 2.71a2.41 2.41 0 0 0-3.41 0ZM12 7.5a1 1 0 0 1 1 1v3a1 1 0 0 1-2 0v-3a1 1 0 0 1 1-1ZM13.05 15.5a1.05 1.05 0 1 0-2.1 0 1.05 1.05 0 0 0 2.1 0Z" | ||
| /> | ||
| </svg> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import type { Component } from "solid-js"; | ||
|
|
||
| interface IconStopProps { | ||
| size?: number; | ||
| class?: string; | ||
| } | ||
|
|
||
| export const IconStop: Component<IconStopProps> = (props) => { | ||
| const size = () => props.size ?? 14; | ||
|
|
||
| return ( | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width={size()} | ||
| height={size()} | ||
| viewBox="0 0 24 24" | ||
| fill="currentColor" | ||
| class={props.class} | ||
| > | ||
| <rect x="5" y="5" width="14" height="14" rx="3.5" /> | ||
| </svg> | ||
| ); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Gate the
beforeInteractiveReact Grab script to development; loading it unconditionally includes dev instrumentation in production.Prompt for AI agents