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

Old reducers still re-run #993

Closed
Siyfion opened this issue Dec 5, 2016 · 7 comments
Closed

Old reducers still re-run #993

Siyfion opened this issue Dec 5, 2016 · 7 comments

Comments

@Siyfion
Copy link
Contributor

Siyfion commented Dec 5, 2016

I think this might be related to #960 or potentially #930 but it's not the same as either.

I believe that the issue is caused by "old" reducers still being re-run even though they are marked as old, causing a "double" (or more) firing of the event.

Symptoms:

I have a component that is created when the user navigates to a particular route, if I delete an item on that page the reducer fires once and updates the query's previous result and removed the deleted item from the results set.
If I leave that route (unmounting the component) and re-enter it again, upon deletion the reducer will fire twice, attempting to remove the result twice. As I hadn't originally foreseen the item never being there, the _.findIndex call returned -1 on the second trigger then removed a second item (one that actually hadn't been deleted!).

I've mentioned this to @helfer and he suggested making an issue here..

@helfer
Copy link
Contributor

helfer commented Dec 13, 2016

@Siyfion can you test if this is fixed now?

@Siyfion
Copy link
Contributor Author

Siyfion commented Dec 13, 2016

@helfer Just tested with apollo-client v0.5.19 and no... This isn't fixed.

@helfer
Copy link
Contributor

helfer commented Dec 13, 2016

@Siyfion okay, in that case I will need a bit more information, ideally a minimal reproduction or a failing test case.

@Siyfion
Copy link
Contributor Author

Siyfion commented Dec 15, 2016

@helfer I don't really know how best to provide a reproduction, but a simple component like: https://gist.github.com/Siyfion/fa29549a77111f017efd9413ff32c04b

And a simple toggle switch that removes / adds the component with each click is enough to demonstrate the issue. For each additional X times the component is created the reducer function will run X times (when triggered).

@SachaG
Copy link

SachaG commented Dec 15, 2016

I can confirm I'm running into the same issue. I have a list of posts on my homepage, and inserting posts into it works fine.

But if I go to another page (which unmounts the post list), come back, and try inserting again, I get a Encountered two children with the same key React error because the new document was inserted twice. And if I got back and forth 5 extra times, I'll now have 5 extra documents in my list (and thus 5 errors).

If you want to test it out you can pull the latest version of Nova: https://github.com/TelescopeJS/Telescope/tree/apollo

@helfer
Copy link
Contributor

helfer commented Dec 17, 2016

Should be fixed in 0.5.22.

@helfer helfer closed this as completed Dec 17, 2016
@SachaG
Copy link

SachaG commented Dec 18, 2016

Awesome, thanks so much!

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

No branches or pull requests

3 participants