Skip to content
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

Flush act() only on exiting outermost call #15519

Closed
wants to merge 10 commits into from

Conversation

threepointone
Copy link
Contributor

Just starting this PR up to discuss the changes. The actual code changes aren't major. The big (breaking?) change is that nested acts won't work anymore.

@acdlite acdlite mentioned this pull request Apr 27, 2019
9 tasks
@sizebot
Copy link

sizebot commented Apr 27, 2019

Details of bundled changes.

Comparing: c530639...8f88e96

react-noop-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-noop-renderer.development.js +1.2% +1.2% 35.15 KB 35.56 KB 8.71 KB 8.81 KB NODE_DEV
react-noop-renderer.production.min.js 🔺+0.5% 🔺+1.1% 10.49 KB 10.53 KB 3.45 KB 3.49 KB NODE_PROD
react-noop-renderer-persistent.development.js +1.2% +1.2% 35.26 KB 35.67 KB 8.72 KB 8.83 KB NODE_DEV
react-noop-renderer-persistent.production.min.js 🔺+0.5% 🔺+1.2% 10.51 KB 10.56 KB 3.46 KB 3.5 KB NODE_PROD
react-noop-renderer-server.development.js 0.0% -0.1% 1.83 KB 1.83 KB 877 B 876 B NODE_DEV
react-noop-renderer-server.production.min.js 0.0% -0.2% 813 B 813 B 491 B 490 B NODE_PROD

Generated by 🚫 dangerJS

@threepointone threepointone marked this pull request as ready for review May 15, 2019 12:29
@acdlite
Copy link
Collaborator

acdlite commented May 15, 2019

Will wait for #15591 to land before reviewing (or I can review now if you base this one on top of that one)

@@ -119,6 +118,13 @@ function act(callback: () => Thenable) {
called = true;
result.then(
() => {
if (actingUpdatesScopeDepth !== 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any scenario where actingUpdatesScopeDepth would decrement twice, and this would be less than 1? Maybe should change to actingUpdatesScopeDepth < 1 just in case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rather, actingUpdatesScopeDepth > 1

@@ -285,14 +285,13 @@ describe('ReactTestUtils.act()', () => {
return ctr;
}
const el = document.createElement('div');
act(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you move this to a separate act? I would expect moving the assertion outside act is sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the effect wouldn't flush effects until the act exits, only after which the timeout in the component would start, failing the assertion. hence, 2 act()s.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you remove the await then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't?

// a flash of "0" followed by "1"

// now you probably wouldn't write a test like this for your app
// you'd await act(async () => { ReactDOM.render(<App/> })
Copy link
Collaborator

Choose a reason for hiding this comment

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

So then why did you write it this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

like mentioned, just wanted to make sure the intermediate state was what I'd expected.

expect(div.innerHTML).toBe('0');
expect(ctr).toBe(1);

await act(async () => {}); // #just-react-things
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you remove the await from the earlier act?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to specifically test the intermediate sync state. this test is named badly (and frankly on looking at it now, it doesn't seem super useful).

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not clear to me at all what behavior you're actually trying to test. More comments could help.

@threepointone
Copy link
Contributor Author

so many merge conflicts, so I redid it here #15682

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants