Skip to content

Commit 99fd4f2

Browse files
sebmarkbageeps1lon
andauthored
[DevTools] Reorder moved filtered Fibers with backing DevToolsInstance (facebook#34104)
Instead, we just continue to collect the unfiltered children. --------- Co-authored-by: Sebastian Sebbie Silbermann <[email protected]>
1 parent 7deda94 commit 99fd4f2

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

packages/react-devtools-shared/src/__tests__/store-test.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ describe('Store', () => {
1717
let act;
1818
let actAsync;
1919
let bridge;
20+
let createDisplayNameFilter;
2021
let getRendererID;
2122
let legacyRender;
23+
let previousComponentFilters;
2224
let store;
2325
let withErrorsOrWarningsIgnored;
2426

@@ -29,6 +31,8 @@ describe('Store', () => {
2931
bridge = global.bridge;
3032
store = global.store;
3133

34+
previousComponentFilters = store.componentFilters;
35+
3236
React = require('react');
3337
ReactDOM = require('react-dom');
3438
ReactDOMClient = require('react-dom/client');
@@ -38,9 +42,14 @@ describe('Store', () => {
3842
actAsync = utils.actAsync;
3943
getRendererID = utils.getRendererID;
4044
legacyRender = utils.legacyRender;
45+
createDisplayNameFilter = utils.createDisplayNameFilter;
4146
withErrorsOrWarningsIgnored = utils.withErrorsOrWarningsIgnored;
4247
});
4348

49+
afterEach(() => {
50+
store.componentFilters = previousComponentFilters;
51+
});
52+
4453
const {render, unmount, createContainer} = getVersionedRenderImplementation();
4554

4655
// @reactVersion >= 18.0
@@ -129,6 +138,72 @@ describe('Store', () => {
129138
`);
130139
});
131140

141+
it('should handle reorder of filtered elements', async () => {
142+
function IgnoreMePassthrough({children}) {
143+
return children;
144+
}
145+
function PassThrough({children}) {
146+
return children;
147+
}
148+
149+
await actAsync(
150+
async () =>
151+
(store.componentFilters = [createDisplayNameFilter('^IgnoreMe', true)]),
152+
);
153+
154+
await act(() => {
155+
render(
156+
<PassThrough key="e" name="e">
157+
<IgnoreMePassthrough key="e1">
158+
<PassThrough name="e-child-one">
159+
<p>e1</p>
160+
</PassThrough>
161+
</IgnoreMePassthrough>
162+
<IgnoreMePassthrough key="e2">
163+
<PassThrough name="e-child-two">
164+
<div>e2</div>
165+
</PassThrough>
166+
</IgnoreMePassthrough>
167+
</PassThrough>,
168+
);
169+
});
170+
171+
expect(store).toMatchInlineSnapshot(`
172+
[root]
173+
▾ <PassThrough key="e">
174+
▾ <PassThrough>
175+
<p>
176+
▾ <PassThrough>
177+
<div>
178+
`);
179+
180+
await act(() => {
181+
render(
182+
<PassThrough key="e" name="e">
183+
<IgnoreMePassthrough key="e2">
184+
<PassThrough name="e-child-two">
185+
<div>e2</div>
186+
</PassThrough>
187+
</IgnoreMePassthrough>
188+
<IgnoreMePassthrough key="e1">
189+
<PassThrough name="e-child-one">
190+
<p>e1</p>
191+
</PassThrough>
192+
</IgnoreMePassthrough>
193+
</PassThrough>,
194+
);
195+
});
196+
197+
expect(store).toMatchInlineSnapshot(`
198+
[root]
199+
▾ <PassThrough key="e">
200+
▾ <PassThrough>
201+
<div>
202+
▾ <PassThrough>
203+
<p>
204+
`);
205+
});
206+
132207
describe('StrictMode compliance', () => {
133208
it('should mark strict root elements as strict', async () => {
134209
const App = () => <Component />;

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,6 +3612,11 @@ export function attach(
36123612
shouldResetChildren = true;
36133613
}
36143614
} else if (prevChild !== null && shouldFilterFiber(nextChild)) {
3615+
// The filtered instance could've reordered.
3616+
if (prevChild !== prevChildAtSameIndex) {
3617+
shouldResetChildren = true;
3618+
}
3619+
36153620
// If this Fiber should be filtered, we need to still update its children.
36163621
// This relies on an alternate since we don't have an Instance with the previous
36173622
// child on it. Ideally, the reconciliation wouldn't need previous Fibers that

0 commit comments

Comments
 (0)