Skip to content

Fix components not refreshing during hmr #306

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

PatrykWalach
Copy link
Member

Fixes HMR by method described in #264
Follow up to #264
Rebase of #305

@PatrykWalach
Copy link
Member Author

We can consider importing different function from @isograph/react instead of changing iso definition, this way we can still error if babel is not setup correctly.

@PatrykWalach
Copy link
Member Author

Ideally we should support the new Activity component

@PatrykWalach
Copy link
Member Author

I had an idea that I need to think over but instead of introducing arbitrary timeout to dispose, maybe we can dispose in the nextTick/nextAnimationFrame or something like that

@rbalicki2
Copy link
Collaborator

The activity component (which I believe was called the offscreen API at some point in time in the past) is going to be tough, because if a component goes off and onscreen, React will:

  • call the effect disposal function when the component turns invisible, then
  • "restore the state" when the component becomes visible again. (Perhaps it will also call the effect, I don't remember.)

But for something like useLazyReference, that would result in the state containing a fragment reference that is disposed. I guess the usual thing to do is to refetch in a situation like this, and we should probably just do that.

The additional problem is that you might invoke a mutation in useLazyReference. (Should you? I don't think it's necessarily a bad idea, if you can't avoid fetching during render. You might imagine that navigating to https://docs.new creates a new document during render. Or, you might imagine a modal that opens idiopathically, and that modal executes a mutation during initial render.) So, we should either:

  • discourage that pattern and let folks be aware that that's the risk, or
  • find some way to force folks to store that state somewhere else (e.g. tag some fields as safely refetchable?)

But yeah!

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

Successfully merging this pull request may close these issues.

2 participants