mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[fail] reset IsThisRendererActing correctly (#16042)
* [fail] reset IsThisRendererActing correctly I missed this in https://github.com/facebook/react/pull/16039. I'd pointed at the wrong previous state, corrupting it in further use. This PR fixes that, and adds a test to make sure it doesn't happen again. * warn for unacted effects only in strict mode
This commit is contained in:
@@ -37,6 +37,21 @@ it("doesn't warn when you use the right act + renderer: test", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('resets correctly across renderers', () => {
|
||||
function Effecty() {
|
||||
React.useEffect(() => {}, []);
|
||||
return null;
|
||||
}
|
||||
TestUtils.act(() => {
|
||||
TestRenderer.act(() => {});
|
||||
expect(() => {
|
||||
TestRenderer.create(<Effecty />);
|
||||
}).toWarnDev(["It looks like you're using the wrong act()"], {
|
||||
withoutStack: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('warns when using createRoot() + .render', () => {
|
||||
const root = ReactDOM.unstable_createRoot(document.createElement('div'));
|
||||
expect(() => {
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ function act(callback: () => Thenable) {
|
||||
actingUpdatesScopeDepth++;
|
||||
if (__DEV__) {
|
||||
previousIsSomeRendererActing = IsSomeRendererActing.current;
|
||||
previousIsThisRendererActing = IsSomeRendererActing.current;
|
||||
previousIsThisRendererActing = IsThisRendererActing.current;
|
||||
IsSomeRendererActing.current = true;
|
||||
IsThisRendererActing.current = true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -620,7 +620,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
actingUpdatesScopeDepth++;
|
||||
if (__DEV__) {
|
||||
previousIsSomeRendererActing = IsSomeRendererActing.current;
|
||||
previousIsThisRendererActing = IsSomeRendererActing.current;
|
||||
previousIsThisRendererActing = IsThisRendererActing.current;
|
||||
IsSomeRendererActing.current = true;
|
||||
IsThisRendererActing.current = true;
|
||||
}
|
||||
|
||||
+1
-4
@@ -2454,10 +2454,7 @@ export function warnIfNotCurrentlyActingEffectsInDEV(fiber: Fiber): void {
|
||||
if (__DEV__) {
|
||||
if (
|
||||
warnsIfNotActing === true &&
|
||||
(fiber.mode & StrictMode ||
|
||||
fiber.mode & ProfileMode ||
|
||||
fiber.mode & BatchedMode ||
|
||||
fiber.mode & ConcurrentMode) &&
|
||||
(fiber.mode & StrictMode) !== NoMode &&
|
||||
IsSomeRendererActing.current === false &&
|
||||
IsThisRendererActing.current === false
|
||||
) {
|
||||
|
||||
@@ -72,7 +72,7 @@ function act(callback: () => Thenable) {
|
||||
actingUpdatesScopeDepth++;
|
||||
if (__DEV__) {
|
||||
previousIsSomeRendererActing = IsSomeRendererActing.current;
|
||||
previousIsThisRendererActing = IsSomeRendererActing.current;
|
||||
previousIsThisRendererActing = IsThisRendererActing.current;
|
||||
IsSomeRendererActing.current = true;
|
||||
IsThisRendererActing.current = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user