File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
packages/react-devtools-shared/src Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,43 @@ describe('Store', () => {
60
60
expect ( store ) . toMatchSnapshot ( '2: add host nodes' ) ;
61
61
} ) ;
62
62
63
+ // This is a weird and admittedly contrived edge case.
64
+ // It's not the same cause as what's reported on GitHub,
65
+ // but the resulting behavior (owner mounting after descendant) is the same.
66
+ // See https://github.com/facebook/react/issues/21445
67
+ it ( 'should handle when a component mounts before its owner' , ( ) => {
68
+ const promise = Promise . resolve ( ) ;
69
+
70
+ let Dynamic = null ;
71
+ const Owner = ( ) => {
72
+ Dynamic = < Child /> ;
73
+ throw promise ;
74
+ return null ;
75
+ } ;
76
+ const Parent = ( ) => {
77
+ return Dynamic ;
78
+ } ;
79
+ const Child = ( ) => null ;
80
+
81
+ const container = document . createElement ( 'div' ) ;
82
+
83
+ act ( ( ) => ReactDOM . render (
84
+ < >
85
+ < React . Suspense fallback = "Loading..." >
86
+ < Owner />
87
+ </ React . Suspense >
88
+ < Parent />
89
+ </ > ,
90
+ container ,
91
+ ) ) ;
92
+ expect ( store ) . toMatchInlineSnapshot ( `
93
+ [root]
94
+ <Suspense>
95
+ ▾ <Parent>
96
+ <Child>
97
+ ` ) ;
98
+ } ) ;
99
+
63
100
describe ( 'collapseNodesByDefault:false' , ( ) => {
64
101
beforeEach ( ( ) => {
65
102
store . collapseNodesByDefault = false ;
Original file line number Diff line number Diff line change @@ -1753,7 +1753,11 @@ export function attach(
1753
1753
const elementType = getElementTypeForFiber ( fiber ) ;
1754
1754
const { _debugOwner} = fiber ;
1755
1755
1756
- const ownerID = _debugOwner != null ? getFiberIDThrows ( _debugOwner ) : 0 ;
1756
+ // HACK Ideally we would call getFiberIDThrows() for _debugOwner,
1757
+ // but in some edge cases the owner doesn't yet have an ID generated.
1758
+ // Since this is a DEV only field it's probably okay to also just generate if needed here.
1759
+ // See https://github.com/facebook/react/issues/21445
1760
+ const ownerID = _debugOwner != null ? getOrGenerateFiberID ( _debugOwner ) : 0 ;
1757
1761
const parentID = parentFiber ? getFiberIDThrows ( parentFiber ) : 0 ;
1758
1762
1759
1763
const displayNameStringID = getStringID ( displayName ) ;
You can’t perform that action at this time.
0 commit comments