Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Guard against legacy context being not supported in DevTools fixture
Legacy context was removed from experimental builds so the default setup would hide important fixtures.

Now it just assumes that any crash within the tree rendering legacy context is due to legacy context not being supported.

I didn't remove since this fixture can be used with older versions of React where we would want to check if legacy
context still works.
  • Loading branch information
eps1lon committed Mar 20, 2024
commit 061be1c8bafcbae0c9f7c2ea1f23322f043689a5
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,46 @@ class ModernClassContextConsumerWithUpdates extends Component<any> {
}
}

type LegacyContextState = {
supportsLegacyContext: boolean,
};
class LegacyContext extends React.Component {
state: LegacyContextState = {supportsLegacyContext: true};

static getDerivedStateFromError(error: any): LegacyContextState {
return {supportsLegacyContext: false};
}

componentDidCatch(error: any, info: any) {
console.info(
'Assuming legacy context is not supported in this React version due to: ',
error,
info,
);
}

render(): React.Node {
if (!this.state.supportsLegacyContext) {
return <p>This version of React does not support legacy context.</p>;
}

return (
<React.Fragment>
<LegacyContextProvider>
<LegacyContextConsumer />
</LegacyContextProvider>
<LegacyContextProviderWithUpdates />
</React.Fragment>
);
}
}

export default function Contexts(): React.Node {
return (
<div>
<h1>Contexts</h1>
<ul>
<LegacyContextProvider>
<LegacyContextConsumer />
</LegacyContextProvider>
<LegacyContextProviderWithUpdates />
<LegacyContext />
<ModernContext.Provider value={contextData}>
<ModernContext.Consumer>
{(value: $FlowFixMe) =>
Expand Down