Skip to content

refactor(Checkbox): set indeterminate via ref callback instead of layout effect#8122

Draft
adierkens wants to merge 1 commit into
mainfrom
adierkens-checkbox-ref-callback-indeterminate
Draft

refactor(Checkbox): set indeterminate via ref callback instead of layout effect#8122
adierkens wants to merge 1 commit into
mainfrom
adierkens-checkbox-ref-callback-indeterminate

Conversation

@adierkens

Copy link
Copy Markdown
Contributor

Closes #7764

Replaces the useLayoutEffect that imperatively set the DOM .indeterminate property (and the useEffect that set aria-checked) with a single ref callback merged into the forwarded ref via useMergedRefs. The callback runs synchronously during commit, so the timing and behavior are preserved while removing two effects per Checkbox instance.

This is an internal-only refactor with no public API change and is behavior-preserving.

Changelog

New

  • Nothing added.

Changed

  • Checkbox now sets the native .indeterminate DOM property (and the matching aria-checked value) from a ref callback instead of a useLayoutEffect + useEffect, eliminating two effects per instance.
  • Migrated the internal ref from the deprecated useProvidedRefOrCreate to an internal useRef merged with the forwarded ref via useMergedRefs.

Removed

  • The per-instance useLayoutEffect (indeterminate) and useEffect (aria-checked) in Checkbox.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Behavior is unchanged. aria-checked still resolves to true / false / mixed and .indeterminate is applied with the same commit timing as before. Verified locally:

  • Checkbox unit tests: 12/12 pass (including the aria-checked true/false/mixed assertions).
  • Checkbox + CheckboxGroup + useMergedRefs: 31/31 pass.
  • tsc --noEmit: no new errors.
  • ESLint on the changed file: clean. Prettier: clean.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Storybook)
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge
  • (GitHub staff only) Integration tests pass at github/github-ui

…out effect

Replace the useLayoutEffect that imperatively set the DOM `.indeterminate`
property (and the useEffect that set `aria-checked`) with a single ref callback
merged into the forwarded ref via useMergedRefs. The callback runs synchronously
during commit, preserving the previous timing and behavior while removing two
effects per Checkbox instance.

Internal-only refactor; no public API change.

Closes #7764

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: beaceba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. If this doesn't work, you can also use the original workflow here. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Checkbox: replace useLayoutEffect with ref callback for indeterminate prop

1 participant