Skip to content

Dedupe legacy context warnings #30299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ function initModules() {
};
}

const {resetModules, itRenders, clientRenderOnBadMarkup} =
ReactDOMServerIntegrationUtils(initModules);
const {resetModules, itRenders} = ReactDOMServerIntegrationUtils(initModules);

function formatValue(val) {
if (val === null) {
Expand Down Expand Up @@ -105,7 +104,7 @@ describe('ReactDOMServerIntegrationLegacyContextDisabled', () => {
<RegularFn />
</span>
</LegacyProvider>,
render === clientRenderOnBadMarkup ? 4 : 3,
3,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The different number of warnings originates from this PR, but didn't have a reason there. I assume it was just updated to make the test pass?

https://github.com/facebook/react/pull/28448/files#diff-e378a74630afcd49e831e7376016c653c5dcf045308d7a9142a1eb912f603bfbR108

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On hydration mismatch we retry with client rendering in the new root so you got the warning again since it wasn't deduped.

That we now have the same count with good and bad markup shows that it's properly deduped 👍🏻

I'll add a comment to the original PR. There were a bunch of PR with the same pattern back then so I just forgot to mention it in each one.

);
expect(e.textContent).toBe('{}undefinedundefined');
expect(lifecycleContextLog).toEqual([]);
Expand Down
10 changes: 8 additions & 2 deletions packages/react-reconciler/src/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ let didWarnAboutLegacyLifecyclesAndDerivedState;
let didWarnAboutUndefinedDerivedState;
let didWarnAboutDirectlyAssigningPropsToState;
let didWarnAboutContextTypeAndContextTypes;
let didWarnAboutContextTypes;
let didWarnAboutChildContextTypes;
let didWarnAboutInvalidateContextType;
let didWarnOnInvalidCallback;

Expand All @@ -93,6 +95,8 @@ if (__DEV__) {
didWarnAboutDirectlyAssigningPropsToState = new Set<string>();
didWarnAboutUndefinedDerivedState = new Set<string>();
didWarnAboutContextTypeAndContextTypes = new Set<string>();
didWarnAboutContextTypes = new Set<mixed>();
didWarnAboutChildContextTypes = new Set<mixed>();
didWarnAboutInvalidateContextType = new Set<string>();
didWarnOnInvalidCallback = new Set<string>();

Expand Down Expand Up @@ -385,14 +389,16 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
}

if (disableLegacyContext) {
if (ctor.childContextTypes) {
if (ctor.childContextTypes && !didWarnAboutChildContextTypes.has(ctor)) {
didWarnAboutChildContextTypes.add(ctor);
console.error(
'%s uses the legacy childContextTypes API which was removed in React 19. ' +
'Use React.createContext() instead.',
name,
);
}
if (ctor.contextTypes) {
if (ctor.contextTypes && !didWarnAboutContextTypes.has(ctor)) {
didWarnAboutContextTypes.add(ctor);
console.error(
'%s uses the legacy contextTypes API which was removed in React 19. ' +
'Use React.createContext() with static contextType instead.',
Expand Down
10 changes: 8 additions & 2 deletions packages/react-server/src/ReactFizzClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ let didWarnAboutLegacyLifecyclesAndDerivedState;
let didWarnAboutUndefinedDerivedState;
let didWarnAboutDirectlyAssigningPropsToState;
let didWarnAboutContextTypeAndContextTypes;
let didWarnAboutContextTypes;
let didWarnAboutChildContextTypes;
let didWarnAboutInvalidateContextType;
let didWarnOnInvalidCallback;

Expand All @@ -36,6 +38,8 @@ if (__DEV__) {
didWarnAboutDirectlyAssigningPropsToState = new Set<string>();
didWarnAboutUndefinedDerivedState = new Set<string>();
didWarnAboutContextTypeAndContextTypes = new Set<mixed>();
didWarnAboutContextTypes = new Set<mixed>();
didWarnAboutChildContextTypes = new Set<mixed>();
didWarnAboutInvalidateContextType = new Set<mixed>();
didWarnOnInvalidCallback = new Set<string>();
}
Expand Down Expand Up @@ -362,14 +366,16 @@ function checkClassInstance(instance: any, ctor: any, newProps: any) {
}

if (disableLegacyContext) {
if (ctor.childContextTypes) {
if (ctor.childContextTypes && !didWarnAboutChildContextTypes.has(ctor)) {
didWarnAboutChildContextTypes.add(ctor);
console.error(
'%s uses the legacy childContextTypes API which was removed in React 19. ' +
'Use React.createContext() instead.',
name,
);
}
if (ctor.contextTypes) {
if (ctor.contextTypes && !didWarnAboutContextTypes.has(ctor)) {
didWarnAboutContextTypes.add(ctor);
console.error(
'%s uses the legacy contextTypes API which was removed in React 19. ' +
'Use React.createContext() with static contextType instead.',
Expand Down
Loading