Skip to content

Commit ead2460

Browse files
committed
Disable legacy context
This enables the `disableLegacyContext` flag for web and React Native.
1 parent eb33bd7 commit ead2460

6 files changed

+41
-17
lines changed

packages/react-dom/src/__tests__/ReactComponentLifeCycle-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ describe('ReactComponentLifeCycle', () => {
11121112
});
11131113

11141114
if (!require('shared/ReactFeatureFlags').disableModulePatternComponents) {
1115+
// @gate !disableLegacyContext
11151116
it('calls effects on module-pattern component', async () => {
11161117
const log = [];
11171118

packages/react-dom/src/__tests__/ReactErrorBoundaries-test.internal.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,6 @@ describe('ReactErrorBoundaries', () => {
880880
});
881881

882882
// @gate !disableModulePatternComponents
883-
// @gate !disableLegacyContext
884883
it('renders an error state if module-style context provider throws in componentWillMount', async () => {
885884
function BrokenComponentWillMountWithContext() {
886885
return {
@@ -901,23 +900,31 @@ describe('ReactErrorBoundaries', () => {
901900

902901
const container = document.createElement('div');
903902
const root = ReactDOMClient.createRoot(container);
904-
await expect(
905-
async () =>
906-
await act(async () => {
907-
root.render(
908-
<ErrorBoundary>
909-
<BrokenComponentWillMountWithContext />
910-
</ErrorBoundary>,
911-
);
912-
}),
913-
).toErrorDev(
903+
904+
await expect(async () => {
905+
await act(() => {
906+
root.render(
907+
<ErrorBoundary>
908+
<BrokenComponentWillMountWithContext />
909+
</ErrorBoundary>,
910+
);
911+
});
912+
}).toErrorDev([
914913
'Warning: The <BrokenComponentWillMountWithContext /> component appears to be a function component that ' +
915914
'returns a class instance. ' +
916915
'Change BrokenComponentWillMountWithContext to a class that extends React.Component instead. ' +
917916
"If you can't use a class try assigning the prototype on the function as a workaround. " +
918917
'`BrokenComponentWillMountWithContext.prototype = React.Component.prototype`. ' +
919918
"Don't use an arrow function since it cannot be called with `new` by React.",
920-
);
919+
...gate(flags =>
920+
flags.disableLegacyContext
921+
? [
922+
'Warning: BrokenComponentWillMountWithContext uses the legacy childContextTypes API which is no longer supported. Use React.createContext() instead.',
923+
'Warning: BrokenComponentWillMountWithContext uses the legacy childContextTypes API which is no longer supported. Use React.createContext() instead.',
924+
]
925+
: [],
926+
),
927+
]);
921928

922929
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
923930
});

packages/react-dom/src/__tests__/ReactLegacyErrorBoundaries-test.internal.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -859,14 +859,22 @@ describe('ReactLegacyErrorBoundaries', () => {
859859
</ErrorBoundary>,
860860
container,
861861
),
862-
).toErrorDev(
862+
).toErrorDev([
863863
'Warning: The <BrokenComponentWillMountWithContext /> component appears to be a function component that ' +
864864
'returns a class instance. ' +
865865
'Change BrokenComponentWillMountWithContext to a class that extends React.Component instead. ' +
866866
"If you can't use a class try assigning the prototype on the function as a workaround. " +
867867
'`BrokenComponentWillMountWithContext.prototype = React.Component.prototype`. ' +
868868
"Don't use an arrow function since it cannot be called with `new` by React.",
869-
);
869+
...gate(flags =>
870+
flags.disableLegacyContext
871+
? [
872+
'Warning: BrokenComponentWillMountWithContext uses the legacy childContextTypes API which is no longer supported. Use React.createContext() instead.',
873+
'Warning: BrokenComponentWillMountWithContext uses the legacy childContextTypes API which is no longer supported. Use React.createContext() instead.',
874+
]
875+
: [],
876+
),
877+
]);
870878
expect(container.firstChild.textContent).toBe('Caught an error: Hello.');
871879
});
872880
}

packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js

+8
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,14 @@ describe('ReactIncrementalErrorHandling', () => {
17821782
"If you can't use a class try assigning the prototype on the function as a workaround. " +
17831783
'`Provider.prototype = React.Component.prototype`. ' +
17841784
"Don't use an arrow function since it cannot be called with `new` by React.",
1785+
...gate(flags =>
1786+
flags.disableLegacyContext
1787+
? [
1788+
'Warning: Provider uses the legacy childContextTypes API which is no longer supported. Use React.createContext() instead.',
1789+
'Warning: Provider uses the legacy childContextTypes API which is no longer supported. Use React.createContext() instead.',
1790+
]
1791+
: [],
1792+
),
17851793
]);
17861794
});
17871795

packages/shared/ReactFeatureFlags.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ export const transitionLaneExpirationMs = 5000;
140140
// -----------------------------------------------------------------------------
141141
const __NEXT_MAJOR__ = __EXPERIMENTAL__;
142142

143-
// Not ready to break experimental yet.
144-
export const disableLegacyContext = false;
143+
// Removes legacy style context
144+
export const disableLegacyContext = __NEXT_MAJOR__;
145145

146146
// Not ready to break experimental yet.
147147
// Disable javascript: URL strings in href for XSS protection.

packages/shared/forks/ReactFeatureFlags.test-renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const disableIEWorkarounds = true;
3333
export const enableScopeAPI = false;
3434
export const enableCreateEventHandleAPI = false;
3535
export const enableSuspenseCallback = false;
36-
export const disableLegacyContext = false;
3736
export const enableTrustedTypesIntegration = false;
3837
export const disableTextareaChildren = false;
3938
export const disableModulePatternComponents = false;
@@ -100,6 +99,7 @@ export const disableStringRefs = __NEXT_MAJOR__;
10099
export const enableReactTestRendererWarning = false;
101100
export const enableBigIntSupport = __NEXT_MAJOR__;
102101
export const disableLegacyMode = __NEXT_MAJOR__;
102+
export const disableLegacyContext = __NEXT_MAJOR__;
103103

104104
// Flow magic to verify the exports of this file match the original version.
105105
((((null: any): ExportsType): FeatureFlagsType): ExportsType);

0 commit comments

Comments
 (0)