Skip to content

[field] Fix max update depth loop when using <React.Activity> - #3931

Merged
atomiks merged 4 commits into
mui:masterfrom
atomiks:atomiks/field-labelable-loop
Feb 11, 2026
Merged

atomiks merged 4 commits into
mui:masterfrom
atomiks:atomiks/field-labelable-loop

Conversation

@atomiks

@atomiks atomiks commented Feb 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3928

A "maximum update depth exceeded" error can occur when:

  • Using <React.Activity> inside a Field (valid)
  • Nesting multiple controls (not part of a group) inside a single Field (invalid)

@atomiks atomiks added the component: field Changes related to the field component. label Feb 2, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 2, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3931
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3931
    

commit: 6a950de

@mui-bot

mui-bot commented Feb 2, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+660B(+0.16%) 🔺+260B(+0.19%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Feb 2, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 6a950de
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/698c6055dd80500008a179b6
😎 Deploy Preview https://deploy-preview-3931--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the atomiks/field-labelable-loop branch 3 times, most recently from 2894c2c to 9d39be4 Compare February 2, 2026 08:03
@atomiks
atomiks force-pushed the atomiks/field-labelable-loop branch from 9d39be4 to a79f19b Compare February 2, 2026 08:26
@atomiks atomiks changed the title [field] Warn when multiple controls are nested within <Field.Root> [field] Fix max update depth loop when using <React.Activity> Feb 2, 2026
@atomiks
atomiks force-pushed the atomiks/field-labelable-loop branch 4 times, most recently from 613578d to 9886e3f Compare February 2, 2026 20:49
@atomiks
atomiks marked this pull request as ready for review February 2, 2026 20:53
@greptile-apps

greptile-apps Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR fixes a "maximum update depth exceeded" error that occurred when using <React.Activity> inside a Field or when nesting multiple controls in a single Field.

Key Changes:

  • Replaced direct setControlId state updates with a registration-based system using registerControlId
  • Each control now registers with a unique symbol as a source identifier, enabling stable tracking across unmount/remount cycles
  • Microtask scheduling for unregistrations prevents render loops when components unmount and remount (like with React 19's <Activity>)
  • Added dev-mode error to detect invalid usage of multiple controls within a single <Field.Root>
  • Comprehensive test coverage including React 19 Activity component scenarios

Technical Implementation:

  • LabelableProvider maintains a Map<symbol, string | null> of control registrations
  • Registration triggers immediate state flush, unregistration uses microtask scheduling
  • useRefWithInit creates stable symbol references that persist across effect runs
  • Cleanup uses separate useEffect (not useIsoLayoutEffect) to avoid timing issues

Documentation Updates:

  • Clarified <Field.Item> is for individual checkbox/radio items
  • Clarified <Fieldset.Root> is for shared labels across multiple controls

Confidence Score: 4/5

  • This PR is safe to merge with minor considerations - the core fix is sound but the logic complexity warrants careful testing
  • The registration-based control ID system elegantly solves the render loop issue, comprehensive tests cover edge cases including React 19 Activity component, and the separation of registration (layout effect) from cleanup (effect) prevents timing issues. Score is 4 rather than 5 due to implementation complexity and the subtle microtask scheduling logic that could be challenging to debug if issues arise
  • Pay close attention to packages/react/src/labelable-provider/LabelableProvider.tsx due to the complex registration and flush logic with microtask scheduling

Important Files Changed

Filename Overview
packages/react/src/labelable-provider/LabelableProvider.tsx Replaced direct state updates with registration-based system using symbols to track control IDs, preventing render loops with React.Activity
packages/react/src/labelable-provider/useLabelableId.ts Updated to use registration-based control ID system with symbol-based tracking for stable references across unmount/remount cycles
packages/react/src/checkbox/root/CheckboxRoot.tsx Migrated from setControlId to registerControlId with symbol-based registration to prevent infinite render loops
packages/react/src/field/root/FieldRoot.test.tsx Added comprehensive tests for multiple control detection, control ID updates, and React 19 Activity component compatibility

@atomiks
atomiks force-pushed the atomiks/field-labelable-loop branch 2 times, most recently from 49bae50 to 4179f87 Compare February 4, 2026 05:56
@atomiks
atomiks force-pushed the atomiks/field-labelable-loop branch from fa2631f to 81fa0b4 Compare February 11, 2026 10:49
@atomiks atomiks added the type: bug It doesn't behave as expected. label Feb 11, 2026
@atomiks
atomiks force-pushed the atomiks/field-labelable-loop branch from 81fa0b4 to 793a317 Compare February 11, 2026 10:54
@atomiks
atomiks force-pushed the atomiks/field-labelable-loop branch from 793a317 to 0b24439 Compare February 11, 2026 10:54
@atomiks
atomiks merged commit 1c073cd into mui:master Feb 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: field Changes related to the field component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[field] Wrapping Select and Checkbox under one <Field.Root> causes update loop

3 participants