fix: premature cleanup in strict mode and improved performance#429
fix: premature cleanup in strict mode and improved performance#429welkinwong wants to merge 2 commits intometeor:masterfrom welkinwong:master
Conversation
|
Supplementary Description: Premature cleanup of subscriptions and |
|
This would explain some of the issues I ran into! Looking forward to a patch release with this! |
|
Also very much appreciate the lodash removal. |
|
I understand the problem you describe and the code makes sense. But, is there any chance to provide tests capturing the problem you describe? I’m hesitant to merge changes in these critical packages without reliable evidence that we fully understand the issue and the fix. Since we’ve just restored tests in this repository, it’s a good opportunity to ensure they’re up to date and accurately cover the problem. |
In strict mode (development only), useEffect may run 1-2 times. Throwing a promise outside can cause premature cleanup of subscriptions and cachedSubscription before unmount. To avoid this, check the timeout to ensure cleanup only occurs after unmount.
@nachocodoner Your argument is perfectly valid, so I've added two test cases to cover these changes. :) |
|
This change is available in |
Verified - normal operation 👏 |
… server side and improved performance 1. On the server, useEffect doesn't run, so cached find data isn't cleared. Even after database updates, stale data is returned on subsequent requests. 2. useFindSuspense can't run on the client (non-reactive data makes it pointless), so the useEffect part was removed. 3. lodash.remove is no longer in use and can be removed. 4. According to 7d45b72, the package-lock.json file can be deleted. This PR depends on #429

When strict mode is enabled (development mode only),
useEffectmay run 1 to 2 times. Due to the outer layer throwing a promise, the multiple executions ofuseEffectin this scenario can lead to premature cleanup of subscriptions and cachedSubscription (i.e., before the component unmounts). Therefore, it is necessary to check the timeout to ensure that subscriptions and cachedSubscription are only cleared after the component has unmounted.