Grid: render resize handle as component#77888
Conversation
|
Size Change: 0 B Total Size: 7.87 MB ℹ️ View Unchanged
|
|
Flaky tests detected in 599413b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/25225576538
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Let us merge this to unblock other PRs. |
Next time, I'll add you as a reviewer. Sorry about that. |
No, no worries at all. Thank you for the fix. |
|
Thanks for the quick fix & merge! |
What?
Convert
renderResizeHandleon<DashboardGrid>(and the internal<ResizeHandle>/<GridItem>shapes) from a function render prop to aReact.ComponentType< ResizeHandleRenderProps >. The internal invocation now passes the merged ref via a JSX prop (<RenderResizeHandle ref={ ... } />) instead of as an argument to a function call.This unblocks lint on
trunk. PR #77811 introduced the render-prop function, and the recenteslint-plugin-react-hooksv7 upgrade (#69962) activatedreact-hooks/refs, which flags passing a ref to a function during render.Why?
CI is currently red on trunk because
packages/grid/src/resize-handle.tsx:55violates the newreact-hooks/refsrule:Adding the file to
tools/eslint/suppressions.jsonwould match the convention used by the v7 upgrade for pre-existing violations, but the underlying issue is that passing a callback ref as a function argument during render is exactly the pattern the rule is designed to discourage. Refs propagated via JSXref={ ... }go through React's commit phase, which is the supported path; refs read inside a function call during render can tear.The render-prop function shape also forced consumers to wrap their handle in an inline arrow (
( props ) => <X { ...props } />). AComponentTypeprop accepts the component directly.How?
packages/grid/src/types.ts: change the type ofrenderResizeHandlefrom( props: ResizeHandleRenderProps ) => React.ReactNodetoReact.ComponentType< ResizeHandleRenderProps >inResizeHandleProps,GridItemProps, andBaseDashboardGridProps. Update the surrounding JSDoc.packages/grid/src/resize-handle.tsx: replace the function call with a JSX render. A local PascalCase alias (RenderResizeHandle) is needed because JSX requires the component identifier to start with an uppercase letter.packages/grid/src/stories/index.story.tsx: pass theCustomResizeHandlecomponent directly instead of wrapping it in an arrow function.packages/grid/README.md: update the props table, the "Custom resize handle" example, and the props-received table to reflect the component-based API.tools/eslint/suppressions.jsonis intentionally untouched; the fix removes the violation at the source.Testing
npm installnpx eslint --suppressions-location tools/eslint/suppressions.json packages/grid/src/. Expect exit code 0; the previousreact-hooks/refsfailure onresize-handle.tsx:55is gone and no new suppression was added.npx tsc --noEmit -p packages/grid/tsconfig.json. Expect exit code 0.npm run storybook:dev, navigate to Grid / Custom Resize Handle. The custom corner-stroke SVG handle should render at the bottom-right of each tile, drag-resizing should commit a new layout viaonChangeLayout, andisResizingshould flip the handle's opacity during the gesture.git diff trunk -- tools/eslint/suppressions.jsonis empty.Follow-ups