Skip to content

Commit e3fc255

Browse files
committed
Fix collections wrapped in suspense updating incorrectly
1 parent b3e955f commit e3fc255

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

packages/@react-aria/collections/src/CollectionBuilder.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {forwardRefType, Key, Node} from '@react-types/shared';
1919
import {Hidden} from './Hidden';
2020
import React, {createContext, ForwardedRef, forwardRef, JSX, ReactElement, ReactNode, useCallback, useContext, useMemo, useRef, useState} from 'react';
2121
import {useIsSSR} from '@react-aria/ssr';
22-
import {useLayoutEffect} from '@react-aria/utils';
2322
import {useSyncExternalStore as useSyncExternalStoreShim} from 'use-sync-external-store/shim/index.js';
2423

2524
const ShallowRenderContext = createContext(false);
@@ -114,14 +113,6 @@ function useCollectionDocument<T extends object, C extends BaseCollection<T>>(cr
114113
return document.getCollection();
115114
}, [document]);
116115
let collection = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
117-
useLayoutEffect(() => {
118-
document.isMounted = true;
119-
return () => {
120-
// Mark unmounted so we can skip all of the collection updates caused by
121-
// React calling removeChild on every item in the collection.
122-
document.isMounted = false;
123-
};
124-
}, [document]);
125116
return {collection, document};
126117
}
127118

packages/@react-aria/collections/src/Document.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class BaseNode<T> {
179179
}
180180

181181
removeChild(child: ElementNode<T>): void {
182-
if (child.parentNode !== this || !this.ownerDocument.isMounted) {
182+
if (child.parentNode !== this) {
183183
return;
184184
}
185185

@@ -411,7 +411,6 @@ export class Document<T, C extends BaseCollection<T> = BaseCollection<T>> extend
411411
isSSR = false;
412412
nodeId = 0;
413413
nodesByProps: WeakMap<object, ElementNode<T>> = new WeakMap<object, ElementNode<T>>();
414-
isMounted = true;
415414
private collection: C;
416415
private nextCollection: C | null = null;
417416
private subscriptions: Set<() => void> = new Set();
@@ -426,7 +425,7 @@ export class Document<T, C extends BaseCollection<T> = BaseCollection<T>> extend
426425
}
427426

428427
get isConnected(): boolean {
429-
return this.isMounted;
428+
return true;
430429
}
431430

432431
createElement(type: string): ElementNode<T> {

0 commit comments

Comments
 (0)