Repository navigation
lint: forbid inline mergeRefs calls - #5269
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
cc26880 to
2f21b9b
Compare
2f21b9b to
d9b991f
Compare
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsDateInput (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
Leaving this one for a teammate to land rather than arming auto-merge, and noting why here so it isn't mistaken for neglect. The rule itself is right and the PR is clean. The care is in the landing: a new lint rule doesn't only apply to new code — it fails every open branch that hasn't adopted the pattern yet. So this wants a person watching the first CI cycle after it merges, ready to answer "why did my PR go red" — not a bot arming it overnight. Best paired with #5266/#5267 so the rule and the thing it points people toward land together. Approved and ready whenever someone can babysit it. [Reviewed by Robohands] |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks — the rule is right, and the two PRs under it landed clean.
Correcting my own earlier note: I said the risk was open branches going red. It's main. TouchDateField landed in #5350 after you branched and carries the exact pattern — ref={mergeRefs(ref, inputRef)} at TouchDateField.tsx:1172. Run the rule against main today and that is the only ESLint error in packages/core/src. CI is green here because it last ran on a three-day-old merge base.
One for later, not this PR: Avatar.tsx:651 and Button.tsx:762 build the same unstable callback with a hoisted const, which your test marks valid.
Merge main and move that one line to useMergedRefs — then it's error-clean and I'd land it.
[Reviewed by Robohands]
d9b991f to
12d798a
Compare
Addressed on the refreshed head: rebuilt the rule directly on current main, migrated TouchDateField to useMergedRefs, and all checks pass.
What
Adds
@astryx/no-inline-merge-refsas an error for core and updates the one violation that reachedmainafter this branch was created.The earlier parts of the original stack have landed:
useMergedRefsand fixedText/Heading.The branch is rebuilt directly on current
main, andTouchDateFieldnow usesuseMergedRefsfor the callsite added in #5350.Why enforcement is needed
The unsafe code looks natural:
But
mergeRefs(...)is a callback factory. Calling it during render creates a new ref callback every time, forcing React to detach and reattach an unchanged element. #5266 shows that this can escalate into React error #185 when a ref callback schedules state during commit.Providing
useMergedRefsis not enough by itself: the unsafe utility remains available for non-React composition, and the inline JSX form is easy to reintroduce.There is direct ecosystem precedent. Radix added
scripts/check-composed-refs.mjsafter the same React 19 “Maximum update depth exceeded” failure (radix-ui/primitives#3963). Its guard rejects the same two patterns enforced here.What the rule rejects
What remains valid
The rule follows imported bindings, including aliases, and does not flag an unrelated local function that happens to be named
mergeRefs.The rule applies to core only; lab remains outside this migration's scope.
Validation
mainfails onTouchDateFieldwith exactly one@astryx/no-inline-merge-refserror; the same lint command passes after the fix.DateInputTouch.test.tsx: 134 passed.pnpm lint:strict: passed.pnpm build: passed.pnpm test: passed.