Base UI's render prop silently stopped working under redact — <Tooltip.Trigger render={<Button />} /> never opens, same for popovers and menus. No error.
It clones the element with a merged ref:
mergedProps.ref = props.ref;
return React.cloneElement(newElement, mergedProps);
React 19 keeps ref in props (only key/__self/__source are reserved), but redact
follows the React 18 rule and hoists it onto element.ref, so the cloned function
component gets no ref. The trigger element never reaches the tooltip store and the
hover effect bails before attaching its mouseenter listener.
Fix: createElement/cloneElement leave ref in props, and cloneElement skips
it only when config.ref === undefined, like React does.
Summary by CodeRabbit#
Bug Fixes
- Preserved
ref as a regular prop when creating and cloning React elements, aligning with React 19 behavior.
- Prevented cloning without a new ref from unintentionally replacing an existing ref.
- Ensured cloned refs are forwarded correctly through function components to the underlying DOM element.
Tests
- Added coverage for ref retention, cloning behavior, and end-to-end ref forwarding.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
44700401-84ce-4593-bf70-4de6bbbaa3c2📥 Commits
Reviewing files that changed from the base of the PR and between aa8730af30298af691e75b2de73b6510200c2ddc and 77f002077c09a87a5d7734e7fc096abe0db80b8b.
📒 Files selected for processing (3)
.changeset/ref-as-prop.mdpackages/redact/src/react/element.tstests/element-ref-prop.test.tsxIncluded review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.
📝 Walkthrough
Walkthrough#
The React element helpers now preserve refs as regular props.
cloneElementavoids replacing an existing ref withundefined. Tests cover creation, cloning, prop merging, and DOM forwarding.Changes#
React ref prop preservation
packages/redact/src/react/element.ts,.changeset/ref-as-prop.mdcreateElementcopiesrefinto props.cloneElementskips an undefinedref. The changeset documents the patch release.tests/element-ref-prop.test.tsx<span>.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
77f00The ref-as-prop behavior is implemented and covered across the affected element creation, cloning, and DOM-forwarding paths; no actionable merge risk remains.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
refin props forcreateElementandcloneElement.Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share