pauldijou / redux-act

An opinionated lib to create actions and reducers for Redux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conflict with hot reload

datenreisender opened this issue · comments

I am using https://github.com/milankinen/livereactload for hot reloading my code during development. And I am using redux-act with serializable actions so I can store reliably export and import my state with the dev tools during development.

Trouble is: When my code get's reloaded, it throws TypeError: Duplicate action type, because actions are added again. Like most hot reloading solutions, livereactload offers a hook to run on reload but those hooks are run after the module is ran, so the error is already thrown and using types.clear() in the hook would be too late.

Any idea how to solve this?

Not really to be honest.

One idea would be to have a new feature to disable all duplicate checks. It would solve the problem of the TypeError for serializable actions. Obviously, you would not disable it in production.

But I think that wouldn't solve the issue for normal actions. I've never used livereactload but if it only reloads the file with the actions, they will have new generated ids but the reducers will still track the old ones... I can't find a way to solve that.

Ping me if you want the API to disable duplicate checks. Otherwise, couldn't find what else to do.

Same here for webpack HMR

Thank you for excellent library @pauldijou. This issue is the only one problem I could think of, otherwise everything works perfectly. Could you please implement the API to disable duplicate checks?

@klis87 This would probably only work for serializable actions. Are you fine with it? I would still find a solution for normal actions...

@pauldijou Hmm, I guess and hope, that nothing needs to be done for normal actions actually, provided that HMR is set is such a way, that changing action forces reducer to be replaced as well - then everything should work as reducer would refer to newly generated action types.

This is how React HMR is working as well. Lets say you added RootComponent to be Hot module replaced, and it imports ChildComponent. If you change ChildComponent, it will be reimported by RootComponent. It is the same for reducers, because reducers need to import actions to get action types, so in theory it should work. It only cannot work for serialize actions right now because it causes duplicated types, which throws error.

Done in 1.3.0. Check new doc for more infos.

Awesome, thanks!