-
Notifications
You must be signed in to change notification settings - Fork 49.2k
Add test for duplicate events with nested dispatch #8566
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
Conversation
Thanks for the PR @Andarist, and for the write up in #8559. I'm wondering if we can safely just get rid of this whole dev-only abstraction. We use it elsewhere (like for |
It dispatches a fake event so that errors originating in user code are on the top of the stack and "break on uncaught exceptions" works. I think that's the main reason. |
Hm, its in fact kinda weird that It seems that it should always (regardless the env) use this one -
Maybe that should be fixed too? |
We can update that call in As for using |
So I've pushed out the new version. It might seem that it contains some unnecessary changes, but:
Also - the test's comment might not be the best, but cannot express it better atm |
ReactErrorUtils.invokeGuardedCallback('foo', callback, 'arg', true); | ||
expect(callback).toHaveBeenCalledTimes(1); | ||
expect(callback2).toHaveBeenCalledTimes(1); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this test fail if you revert the changes in ReactErrorUtils
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But test file would need to stay as in my PR so the ordering issue is solved by resetModules
CicrcleCI didnt pass on 1 container out of 4, but aint sure why, as locally I do not have any problems and 3 containers passed the tests just fine. Did you start using Circle recently? I dont recall it being used before. |
@aweary However it didnt pass on some of the containers (similarly like before). After that I've rebased my branch which forced another build - and the same thing again. Do you have any idea why this might happen? My changes were really minor and I dont see why this is happening. |
(You should be able to rebase to fix this?) |
I've done that, but 1 container is still failing. I think it's connected with ongoing fiber development and the fact I've added a test case. From what we can see overall in https://circleci.com/gh/facebook/react/760#tests/containers/2 Just a wild idea (cause im not aware how the things are developed atm) - should i run |
Yes, exactly! Sorry it's not documented. |
Rebased + ammended with |
@@ -71,5 +72,15 @@ describe('ReactErrorUtils', () => { | |||
__DEV__ = true; | |||
global.process = oldProcess; | |||
}); | |||
|
|||
it('shouldn\'t call the callback again while executing synchronously induced other call in development', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to write a test for observable behavior instead? That is, write a test that relies on ReactDOM
and React
, but not on ReactErrorUtils
itself. Otherwise, it's hard to tell what exactly this is fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, should the new one be located in the same file or should I move it somewhere else? gonna prepare better test later 2day
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReactDOM-test
might be an okay place to put it.
Ok, so I've changed the test (removed old one too), so it should clearly indicate what's it testing against. I had few issues with understanding how should I handle it and if any of you could clarify things a little bit it would be great. First of all it is totally unclear for me how to cause an event, there are numerous ways to do so and had no idea which to chose, finally just have chosen the one which gave me my expected results, but I had to test a few. Anyway - not much of a problem, but overally such things could be described somewhere (or maybe ive just didnt find this?) Also when during my experiments I've put: beforeEach(() => {
jest.resetModules();
ReactDOM = require('ReactDOM');
}); it has stopped to work and I have no idea why, wasted some time on this one as in But the biggest obstacle Ive met is that I think that code during testing is going through some other path than in the latest React. There are some fiber-called things in the call stack which are absent in production code. I think this might be responsible for the different behaviour that I have wanted to debug - but ultimately failed. It might (or not) be relevant for your guys though. The problem was that the real life situation was acting like this before the fix - handler1 > handler1 > handler2. But during tests it was handler1 > handler1 > handler1 > handler1 > ..., so effectively it created an endless loop. My fix is working for both scenarios, but I was curious about this difference so I wanted to investigate. I THINK its caused by some logic connected to If somebody is interested I have a call stack for this endless loop which I can post here later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aweary That being said v15 branch wont ever have this fix from #8961 as its fiber-related heavily. Dont know how you guys approach this kind of situations and if you diverge things for 2 different major releases. Also the test could be incorporated into the v16 to ensure regression wont happen here in the future. Let me know what I should do about this PR, i.e I can split this into 2 commits - 1st for v15 fix, 2nd for test, so only the latter can be cherry-picked for master, while both could be merged to v15 line. |
Yeah definitely, I'll re-open if you can just remove the changes to |
@aweary I've moved unsubscribe logic to the start of the event's callback here. I think it wont harm anything as tests are passing and it serves as additional guard - the only reason that the other refactor has fixed this issue is the fact that With this line moved to the callback, it stays double guarded by different event types + by clean up logic moved. Also it will ensure that cleaning up will actually happen in case of an error and we wont end up with stale listener. Possibly even with such stale listener we might end up with other bugs, when some other code would dispatch new event with the same name and depth. I need to check this though and possibly write tests for such case. |
@aweary ping ;) this is a silly PR really, but would like to have it stop hanging as open in my PR tab, I understand though if you are too busy right now |
…d ref) of the same type within a handler calling an original handler too (fixes facebook#8559)
@Andarist I think we can just merge this since it's just adding additional test coverage now. Thanks for this, sorry about the huge delay 😄 |
No problem, sorry that i forgot to adjust commit message while rebasing |
Still have tests to write, but they should be pretty straightforward after PR aproval.
Also had no idea where I should put
once
utility function, so its place in the PR for now is just a temporary.This PR is just a proposal of a fix, the thing I've come with to tackle this problem, I'm open to change the code appropriately if somebody comes up with the better idea how to solve this.
cc @aweary