Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Editor component possible race condition #5

Closed
nvartolomei opened this issue Apr 24, 2016 · 6 comments
Closed

Editor component possible race condition #5

nvartolomei opened this issue Apr 24, 2016 · 6 comments

Comments

@nvartolomei
Copy link

I was wondering if there could be a race condition.

Suppose I try to edit an article, Editor component si being mounted and EDITOR_PAGE_LOADED event is dispatched.

The request is sent to server, but the server didn't respond yet. (1)

Now I go back to homepage, editor component is unmounted, EDITOR_PAGE_UNLOADED is dispatched, the state related to editor component is cleared.

Now I try to edit another article, Editor component is mounted, EDITOR_PAGE_LOADED is dispatched for another article.

The request is sent to server, and server responds instantly. (2)

Reducer for EDITOR_PAGE_LOADED action triggered by second request is called. Everything cool still.

Now, the first request (1) is full-filled, and reducer for EDITOR_PAGE_LOADED action is called, with information from first request, and in the editor I will see the contents for first article I tried to edit, instead of the second one.

Hm?

@vkarpov15
Copy link
Collaborator

Fair point. Will put in a fix tomorrow

@vkarpov15
Copy link
Collaborator

@nvartolomei what do you think about #8?

@nvartolomei
Copy link
Author

Not sure if I like this one, page change makes all requests made through promise middleware obsolete. This is too much, imho. Let's say I have a header that stays the same on all pages, an action from header will be killed in middleware if editor is unloaded?

@vkarpov15
Copy link
Collaborator

You're right, hadn't quite thought of that. Have any other ideas? I'll do some research and see if I can come up with something better today.

@vkarpov15
Copy link
Collaborator

@nvartolomei see what you think of #9 . Slightly different approach based on explicitly cancelling all tracked promises when a route unloads.

@nvartolomei
Copy link
Author

@vkarpov15 looks good to me.

vkarpov15 added a commit that referenced this issue Apr 27, 2016
New approach for handling race condition in #5
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

2 participants