Skip to content

Commit

Permalink
Update subscription-in-startTransition warning
Browse files Browse the repository at this point in the history
The message now explicitly mentions the useSyncExternalStore API.
  • Loading branch information
acdlite committed Feb 23, 2022
1 parent 97673a6 commit 9e4c304
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
8 changes: 5 additions & 3 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,11 @@ function startTransition(setPending, callback) {
const updatedFibersCount = currentTransition._updatedFibers.size;
if (updatedFibersCount > 10) {
console.warn(
'Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.',
'Detected a large number of updates within a startTransition ' +
'scope. This likely means you have subscribed to an external ' +
'store. To ensure compatibility with concurrent features ' +
'like startTransition, subscriptions should be managed by the ' +
'useSyncExternalStore API.',
);
}
currentTransition._updatedFibers.clear();
Expand Down
8 changes: 5 additions & 3 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,11 @@ function startTransition(setPending, callback) {
const updatedFibersCount = currentTransition._updatedFibers.size;
if (updatedFibersCount > 10) {
console.warn(
'Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.',
'Detected a large number of updates within a startTransition ' +
'scope. This likely means you have subscribed to an external ' +
'store. To ensure compatibility with concurrent features ' +
'like startTransition, subscriptions should be managed by the ' +
'useSyncExternalStore API.',
);
}
currentTransition._updatedFibers.clear();
Expand Down
8 changes: 5 additions & 3 deletions packages/react/src/ReactStartTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export function startTransition(scope: () => void) {
const updatedFibersCount = currentTransition._updatedFibers.size;
if (updatedFibersCount > 10) {
console.warn(
'Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.',
'Detected a large number of updates within a startTransition ' +
'scope. This likely means you have subscribed to an external ' +
'store. To ensure compatibility with concurrent features ' +
'like startTransition, subscriptions should be managed by the ' +
'useSyncExternalStore API.',
);
}
currentTransition._updatedFibers.clear();
Expand Down
16 changes: 10 additions & 6 deletions packages/react/src/__tests__/ReactStartTransition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ describe('ReactStartTransition', () => {
});
}).toWarnDev(
[
'Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.',
'Detected a large number of updates within a startTransition ' +
'scope. This likely means you have subscribed to an external ' +
'store. To ensure compatibility with concurrent features ' +
'like startTransition, subscriptions should be managed by the ' +
'useSyncExternalStore API.',
],
{withoutStack: true},
);
Expand All @@ -80,9 +82,11 @@ describe('ReactStartTransition', () => {
});
}).toWarnDev(
[
'Detected a large number of updates inside startTransition. ' +
'If this is due to a subscription please re-write it to use React provided hooks. ' +
'Otherwise concurrent mode guarantees are off the table.',
'Detected a large number of updates within a startTransition ' +
'scope. This likely means you have subscribed to an external ' +
'store. To ensure compatibility with concurrent features ' +
'like startTransition, subscriptions should be managed by the ' +
'useSyncExternalStore API.',
],
{withoutStack: true},
);
Expand Down

0 comments on commit 9e4c304

Please sign in to comment.