lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
631 stars 52 forks source link

A fast refresh example, that doesn't work #38

Closed danieroux closed 4 years ago

danieroux commented 4 years ago

Hi Will,

I've tried to put together a fast-refresh example that works, so that I can replicate it in my code.

I cannot get it to work. What am I missing?

My expectation:

lilactown commented 4 years ago

Hey @danieroux. I've updated the refresh example to be in line with the latest helix API.

Your PR is relatively correct. The biggest problem I ran into was a mismatch between react-refresh and react.

I'm not sure which react-refresh version maps to which react version, but I had to forcefully install react-refresh@latest in helix in order to pick up the correct version, as well as clear out node_modules and my shadow-cljs build cache.

danieroux commented 4 years ago

Thank you, this now works for me too.

This may very well be out of the realm of helix, and a react-refresh issue:

(hooks/use-effect :once ,,,) runs on every (refresh/refresh!). In the demo the js/setInterval gets called on every refresh.

Which is different from running :once :-)

lilactown commented 4 years ago

According to react-refresh's tests, this is expected behavior:

https://github.com/facebook/react/blob/master/packages/react-refresh/src/__tests__/ReactFresh-test.js#L2282

danieroux commented 4 years ago

That's quite surprising behavior. Thank you for finding it.

This is where they lose me: https://github.com/facebook/react/blob/235a6c4af67e3e1fbfab7088c857265e0c95b81f/packages/react-refresh/src/__tests__/ReactFresh-test.js#L2344