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

fix error with hot module replacement #264

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

Conversation

PatrykWalach
Copy link
Collaborator

When hot module replacement happens the parentCache doesn't change but useEffect is rerun (don't know what the exact cause of this is), when useEffect is rerun it crashes, because it can't access cacheItem anymore.

The extra check makes sure effect is run once per parentCache (maybe we are compatible with StrictMode now?)

@@ -51,6 +51,10 @@ export function useCachedResponsivePrecommitValue<T>(
const lastCommittedParentCache = useRef<ParentCache<T> | null>(null);

useEffect(() => {
if (lastCommittedParentCache.current === parentCache) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-11-13 at 6 10 17 PM
I now see this, btw... I'll investigate what is going on.

My suspicion is that the component cache is caching the old component. I haven't looked into this.

I think in terms of strict mode, we're still likely incompatible. Basically, useLazyReference will uncommit, dispose, and re-commit, which does not re-issue the query.

I am philosophically opposed to that — queries aren't always re-issuable! But we can probably warn loudly and reissue queries. Just sucks if you're lazily doing a mutation, which is possible :-P

Once #252 lands, there probably won't be a huge need for lazy loaded queries though

@rbalicki2
Copy link
Collaborator

@PatrykWalach
Copy link
Collaborator Author

Now useLazyDisposableState should work correctly, it will setup cleanup once for every parentCache

@PatrykWalach
Copy link
Collaborator Author

PatrykWalach commented Nov 14, 2024

This is not erroring, but the environment cache will indeed produce stale components

PS. so if we fix component cache we will receive fresh components, and it shouldn't cause these errors

PPS. the issue seems to be components get hot reloaded, but somehow iso("entrypoint ...") does not

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