-
Notifications
You must be signed in to change notification settings - Fork 167
useSyncEffect proposal Fix for #418 #419
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
Conversation
Johan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Thank you for your contribution. Can you check if the tests pass after your changes? We may automate this as a GitHub action. Test files are in that package, specifically for useFind: Also, consider expanding or modifying test coverage if needed for any new expectations introduced by these changes. |
Thank you for your feedback @nachocodoner. I tried and failed to run tests on my machine. Is there any documentation on how to run them ? |
What failures did you have? you ran using |
Thank you @Grubba27 for your help, i'm more a react dev than a meteor one for now. I ran Event if my |
We are restoring test capabilities in this PR: #422 You can build on those changes, add them here, and run the tests to check for any impact. I still need to review your solution further. Adding a timeout arbitrarily doesn’t seem like a good approach, I think. |
I still encounter this issue:
I'm using meteor 3 on my computer .. could this be the reason ? |
You merged it from master, the branch with tests fixed is |
I have another approach for this issue: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the code now and I'm not sure I get the idea:
- Calling
fetchData
on mount inuseEffect
/useSyncEffect
should not be needed, as the initial one is already covered in the initializer ofuseReducer
. useSyncEffect
is not really synchronous - it calls theeffect
function isuseEffect
's cleanup or in asetTimeout
. And even if it'd be solved, I'm afraid it'd result in double render with (i.e., a flash of the old data and then the correct one).
Hi @radekmie thank you for your review :)
|
The goal of useSyncEffect is to extract the logic of "i wan't to run the cursor.observe at render time but it's a bad practice and forbidden by react". |
Ah, right, I overlooked that it's a |
No problem, thank you for your review anyway :) I hope i finally find a way to run those meteor tests :D |
Thank you for your review ! Code looks cleaner :) Co-authored-by: Notas Hellout <[email protected]>
Thank you for your review @make-github-pseudonymous-again those are nice code change suggestions :) Funny pseudo btw ^^ |
const useSyncEffect = (effect, deps) => { | ||
const [cleanup, timeoutId] = useMemo( | ||
() => { | ||
const cleanup = effect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deduplicate cleanup calls, GC cleanup function reference, and handle undefined
cleanup function:
const cleanup = effect(); | |
let _cleanup = effect(); | |
const cleanup = () => { | |
if (_cleanup === undefined) return; | |
_cleanup(); | |
_cleanup = undefined; | |
}; |
What about adding more test coverage for this issue? In another PR, they provided a test that seems to catch this, showing it failing without the fix and passing when applied. |
I suggest merging #428, or at least merging that here and enabling the test. |
Could we get some effective test coverage for this? The test at #428 is already passing on master, even without the proposed changes here. An effective test should accurately capture the issue you’re fixing (#418). First, it should fail, showing the problem. Then, with the proposed changes, it should pass, confirming the fix. This process is the best way to verify and approve the fix. However, since this test already passes in base branch, we can’t confirm it’s effectively addressing the problem. |
The test is passing due to the early return on https://github.com/meteor/react-packages/blob/master/packages/react-meteor-data/useFind.tests.js#L113 This line should be removed on code change with the fix proposal Note: I didn't want to add a failed test to master, so I did that just for who try to fix benefit for my test |
@PedroMarianoAlmeida: Oh, great aclaration. It is actually documented there, I misread it. Going to verify then. Thank you 🙏 |
Tests are passing after make them fail and merge the proposed changes here in this PR: #433 Going to close this one in favor of the other. As I also solved the conflicts here as well. All your work and commits are perserved. I'm going to approve it and merge it soon for the next beta release. |
This change is available in |
This intends to fix #418
(Note that this is an early code proposal, juste to check if the idea is ok)
I think the "useSyncEffect" approach could solve the problem with useTracker leading to double rendering.