Skip to content

Commit

Permalink
Disable legacy mode in Modern www builds
Browse files Browse the repository at this point in the history
These already don't expose the entry points to create legacy roots.
  • Loading branch information
sebmarkbage committed Apr 3, 2024
1 parent 30225e9 commit 4ffb70f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/react-dom/src/__tests__/findDOMNodeFB-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ReactDOM = require('react-dom');
const StrictMode = React.StrictMode;

describe('findDOMNode', () => {
// @gate www
// @gate www && !disableLegacyMode
it('findDOMNode should return null if passed null', () => {
expect(ReactDOM.findDOMNode(null)).toBe(null);
});
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('findDOMNode', () => {
expect(b.tagName).toBe('SPAN');
});

// @gate www
// @gate www && !disableLegacyMode
it('findDOMNode should reject random objects', () => {
expect(function () {
ReactDOM.findDOMNode({foo: 'bar'});
Expand Down
60 changes: 38 additions & 22 deletions packages/react-reconciler/src/__tests__/ReactScope-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ describe('ReactScope', () => {
});

// @gate www
it('DO_NOT_USE_queryAllNodes() works as intended', () => {
it('DO_NOT_USE_queryAllNodes() works as intended', async () => {
const testScopeQuery = (type, props) => true;
const TestScope = React.unstable_Scope;
const scopeRef = React.createRef();
Expand All @@ -417,20 +417,25 @@ describe('ReactScope', () => {
);
}

const renderer = ReactTestRenderer.create(<Test toggle={true} />, {
createNodeMock: element => {
return element;
},
});
let renderer;
await act(
() =>
(renderer = ReactTestRenderer.create(<Test toggle={true} />, {
createNodeMock: element => {
return element;
},
unstable_isConcurrent: true,
})),
);
let nodes = scopeRef.current.DO_NOT_USE_queryAllNodes(testScopeQuery);
expect(nodes).toEqual([divRef.current, spanRef.current, aRef.current]);
renderer.update(<Test toggle={false} />);
await act(() => renderer.update(<Test toggle={false} />));
nodes = scopeRef.current.DO_NOT_USE_queryAllNodes(testScopeQuery);
expect(nodes).toEqual([aRef.current, divRef.current, spanRef.current]);
});

// @gate www
it('DO_NOT_USE_queryFirstNode() works as intended', () => {
it('DO_NOT_USE_queryFirstNode() works as intended', async () => {
const testScopeQuery = (type, props) => true;
const TestScope = React.unstable_Scope;
const scopeRef = React.createRef();
Expand All @@ -454,20 +459,26 @@ describe('ReactScope', () => {
);
}

const renderer = ReactTestRenderer.create(<Test toggle={true} />, {
createNodeMock: element => {
return element;
},
});
let renderer;
await act(
() =>
(renderer = ReactTestRenderer.create(<Test toggle={true} />, {
createNodeMock: element => {
return element;
},
unstable_isConcurrent: true,
})),
);
let node = scopeRef.current.DO_NOT_USE_queryFirstNode(testScopeQuery);
expect(node).toEqual(divRef.current);
renderer.update(<Test toggle={false} />);
await act(() => renderer.update(<Test toggle={false} />));

node = scopeRef.current.DO_NOT_USE_queryFirstNode(testScopeQuery);
expect(node).toEqual(aRef.current);
});

// @gate www
it('containsNode() works as intended', () => {
it('containsNode() works as intended', async () => {
const TestScope = React.unstable_Scope;
const scopeRef = React.createRef();
const divRef = React.createRef();
Expand Down Expand Up @@ -500,23 +511,28 @@ describe('ReactScope', () => {
);
}

const renderer = ReactTestRenderer.create(<Test toggle={true} />, {
createNodeMock: element => {
return element;
},
});
let renderer;
await act(
() =>
(renderer = ReactTestRenderer.create(<Test toggle={true} />, {
createNodeMock: element => {
return element;
},
unstable_isConcurrent: true,
})),
);
expect(scopeRef.current.containsNode(divRef.current)).toBe(true);
expect(scopeRef.current.containsNode(spanRef.current)).toBe(true);
expect(scopeRef.current.containsNode(aRef.current)).toBe(true);
expect(scopeRef.current.containsNode(outerSpan.current)).toBe(false);
expect(scopeRef.current.containsNode(emRef.current)).toBe(false);
renderer.update(<Test toggle={false} />);
await act(() => renderer.update(<Test toggle={false} />));
expect(scopeRef.current.containsNode(divRef.current)).toBe(true);
expect(scopeRef.current.containsNode(spanRef.current)).toBe(true);
expect(scopeRef.current.containsNode(aRef.current)).toBe(true);
expect(scopeRef.current.containsNode(outerSpan.current)).toBe(false);
expect(scopeRef.current.containsNode(emRef.current)).toBe(true);
renderer.update(<Test toggle={true} />);
await act(() => renderer.update(<Test toggle={true} />));
expect(scopeRef.current.containsNode(emRef.current)).toBe(false);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const useModernStrictMode = true;
// because JSX is an extremely hot path.
export const disableStringRefs = false;

export const disableLegacyMode = false;
export const disableLegacyMode = __EXPERIMENTAL__;

export const disableDOMTestUtils = false;

Expand Down

0 comments on commit 4ffb70f

Please sign in to comment.