Skip to content

fix(useId): prevent FinalizationRegistry entry leak in useId#9853

Open
reidbarber wants to merge 3 commits intomainfrom
fix-useid-leak
Open

fix(useId): prevent FinalizationRegistry entry leak in useId#9853
reidbarber wants to merge 3 commits intomainfrom
fix-useid-leak

Conversation

@reidbarber
Copy link
Copy Markdown
Member

Closes #9852

Fixes useId so FinalizationRegistry entries do not accumulate on every re-render. Previously, they would until the component was unmounted.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Unit test should cover.

🧢 Your Project:

@reidbarber reidbarber changed the title Fix useid leak fix(useId): avoid FinalizationRegistry entry leak in useId Mar 27, 2026
@reidbarber reidbarber changed the title fix(useId): avoid FinalizationRegistry entry leak in useId fix(useId): prevent FinalizationRegistry entry leak in useId Mar 27, 2026
@rspbot
Copy link
Copy Markdown

rspbot commented Mar 27, 2026

@rspbot
Copy link
Copy Markdown

rspbot commented Mar 27, 2026

## API Changes

react-aria-components

/react-aria-components:I18nProviderProps

-I18nProviderProps {
-  children: ReactNode
-  locale?: string
-}

/react-aria-components:Locale

-Locale {
-  direction: Direction
-  locale: string
-}

/react-aria-components:Filter

-Filter {
-  contains: (string, string) => boolean
-  endsWith: (string, string) => boolean
-  startsWith: (string, string) => boolean
-}

/react-aria-components:CollectionProps

-CollectionProps <T> {
-  addIdAndValue?: boolean
-  children?: ReactNode | (T) => ReactNode
-  dependencies?: ReadonlyArray<any>
-  idScope?: Key
-  items?: Iterable<T>
-}

/react-aria-components:Placement

-Placement {
-  P: undefined
-}

/react-aria-components:VisuallyHiddenProps

-VisuallyHiddenProps {
-  children?: ReactNode
-  className?: string | undefined
-  elementType?: string | JSXElementConstructor<any> = 'div'
-  id?: string | undefined
-  isFocusable?: boolean
-  role?: AriaRole | undefined
-  style?: CSSProperties | undefined
-  tabIndex?: number | undefined
-}

/react-aria-components:ListDataOptions

-ListDataOptions <T> {
-  filter?: (T, string) => boolean
-  getKey?: (T) => Key
-  initialFilterText?: string
-  initialItems?: Array<T>
-  initialSelectedKeys?: 'all' | Iterable<Key>
-}

/react-aria-components:TreeDataOptions

-TreeDataOptions <T extends {}> {
-  getChildren?: ({}) => Array<{}>
-  getKey?: ({}) => Key
-  initialItems?: Array<{}>
-  initialSelectedKeys?: Iterable<Key>
-}

/react-aria-components:AsyncListOptions

-AsyncListOptions <C, T> {
-  getKey?: (T) => Key
-  initialFilterText?: string
-  initialSelectedKeys?: Iterable<Key>
-  initialSortDescriptor?: SortDescriptor
-  load: AsyncListLoadFunction<T, C>
-  sort?: AsyncListLoadFunction<T, C, (AsyncListLoadOptions<T, C> & {
-    sortDescriptor: SortDescriptor
-})>
-}

/react-aria-components:AsyncListLoadFunction

-AsyncListLoadFunction {
-  A: undefined
-}

/react-aria-components:AsyncListLoadOptions

-AsyncListLoadOptions <C, T> {
-  cursor?: C
-  filterText?: string
-  items: Array<T>
-  loadingState?: LoadingState
-  selectedKeys: Selection
-  signal: AbortSignal
-  sortDescriptor?: SortDescriptor
-}

/react-aria-components:AsyncListStateUpdate

-AsyncListStateUpdate <C, T> {
-  cursor?: C
-  filterText?: string
-  items: Iterable<T>
-  selectedKeys?: Iterable<Key>
-  sortDescriptor?: SortDescriptor
-}

@react-spectrum/s2

/@react-spectrum/s2:ComboBoxSection

 ComboBoxSection <T extends {}> {
   aria-label?: string
   children?: ReactNode | (T) => ReactElement
-  className?: string = 'react-aria-ListBoxSection'
+  className?: string
   dependencies?: ReadonlyArray<any>
   id?: Key
   items?: Iterable<T>
-  render?: DOMRenderFunction<keyof React.JSX.IntrinsicElements, undefined>
   style?: CSSProperties
   value?: T
 }

/@react-spectrum/s2:ComboBoxSectionProps

 ComboBoxSectionProps <T extends {}> {
   aria-label?: string
   children?: ReactNode | (T) => ReactElement
-  className?: string = 'react-aria-ListBoxSection'
+  className?: string
   dependencies?: ReadonlyArray<any>
   id?: Key
   items?: Iterable<T>
-  render?: DOMRenderFunction<keyof React.JSX.IntrinsicElements, undefined>
   style?: CSSProperties
   value?: T
 }

/@react-spectrum/s2:SortDirection

-SortDirection {
-  S: undefined
-}

/@react-spectrum/s2:ListOptions

-ListOptions <T> {
-  filter?: (T, string) => boolean
-  getKey?: (T) => Key
-  initialFilterText?: string
-  initialItems?: Array<T>
-  initialSelectedKeys?: 'all' | Iterable<Key>
-}

/@react-spectrum/s2:TreeOptions

-TreeOptions <T extends {}> {
-  getChildren?: ({}) => Array<{}>
-  getKey?: ({}) => Key
-  initialItems?: Array<{}>
-  initialSelectedKeys?: Iterable<Key>
-}

/@react-spectrum/s2:AsyncListOptions

-AsyncListOptions <C, T> {
-  getKey?: (T) => Key
-  initialFilterText?: string
-  initialSelectedKeys?: Iterable<Key>
-  initialSortDescriptor?: SortDescriptor
-  load: AsyncListLoadFunction<T, C>
-  sort?: AsyncListLoadFunction<T, C, (AsyncListLoadOptions<T, C> & {
-    sortDescriptor: SortDescriptor
-})>
-}

/@react-spectrum/s2:AsyncListLoadFunction

-AsyncListLoadFunction {
-  A: undefined
-}

/@react-spectrum/s2:AsyncListLoadOptions

-AsyncListLoadOptions <C, T> {
-  cursor?: C
-  filterText?: string
-  items: Array<T>
-  loadingState?: LoadingState
-  selectedKeys: Selection
-  signal: AbortSignal
-  sortDescriptor?: SortDescriptor
-}

/@react-spectrum/s2:AsyncListStateUpdate

-AsyncListStateUpdate <C, T> {
-  cursor?: C
-  filterText?: string
-  items: Iterable<T>
-  selectedKeys?: Iterable<Key>
-  sortDescriptor?: SortDescriptor
-}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useId leaks FinalizationRegistry entries on every re-render

3 participants