Checkbox: replace useLayoutEffect with ref callback for indeterminate prop
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
Start in packages/react/src/Checkbox/Checkbox.tsx by reading the current useLayoutEffect, useEffect, and forwarded ref handling. Replace the indeterminate effect with the proposed merged ref callback and express aria-checked inline. Done means indeterminate and mixed-state behavior remain correct without the separate effects.
Written by the indexing model from the issue text.
Description
Summary
The Checkbox component currently uses a useLayoutEffect to imperatively set the DOM .indeterminate property on the underlying <input> element. While this works, it can be replaced with a ref callback, which runs synchronously during commit (same timing guarantees as useLayoutEffect) without registering a separate effect.
Current behavior
useLayoutEffect(() => {
if (checkboxRef.current) {
checkboxRef.current.indeterminate = indeterminate || false
}
}, [indeterminate, checked, checkboxRef])
Proposed change
Replace with a ref callback that sets .indeterminate inline:
const setIndeterminate = React.useCallback(
(node: HTMLInputElement | null) => {
if (node) {
node.indeterminate = indeterminate || false
}
},
[indeterminate, checked],
)
// merge with the forwarded ref
const mergedRef = useMergedRef(checkboxRef, setIndeterminate)
Additional cleanup
The useEffect that sets aria-checked can also be replaced with an inline JSX attribute:
'aria-checked': indeterminate ? 'mixed' : undefined
This avoids an unnecessary effect per Checkbox instance.
Motivation
- Ref callbacks are the idiomatic React pattern for imperative DOM properties with no HTML attribute equivalent
- Eliminates a layout effect per Checkbox render, reducing React commit phase work
- Minor but measurable improvement in pages that render many checkboxes (e.g., list views with bulk selection)
References
- Dominant language
- TypeScript
- Stars
- 3.9k
- Forks
- 680
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 56
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from primer/react
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
agentic-workflows
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
[aw] Detection Runs Openagentic-workflows
Difficulty 1/5 Under an hour Newbie friendliness 10/100
-
agentic-workflows
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·