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

useEffect didn't run in some rare case (lazy + memo) #4631

Open
1 task done
guoyunhe opened this issue Jan 13, 2025 · 3 comments
Open
1 task done

useEffect didn't run in some rare case (lazy + memo) #4631

guoyunhe opened this issue Jan 13, 2025 · 3 comments

Comments

@guoyunhe
Copy link

  • Check if updating to the latest Preact version resolves the issue

Describe the bug

I have a simple app with the following structure:

  • App (suspense)
    • Foobar (lazy)
      • Foo (memo)
      • Bar (lazy)

I found that in this case, Foo's useEffect() will NOT be executed. (But it does in React 18)

To Reproduce

https://codesandbox.io/p/sandbox/preact-memo-gpmrxk

Expected behavior

Show foobar

Actual behavior

Show bar

@JoviDeCroock
Copy link
Member

JoviDeCroock commented Jan 13, 2025

This shortcoming originates from the detaching logic, located here currently it bubbles up in a straight line but it should reset every child up until the Suspense boundary, including siblings.

Edit: wait it does, but somehow the memo'd component just bails... we might need to set _force to true - I guess a similar fix would be needed for #3449 either way

@CaptainWang98
Copy link

I noticed the bug disappears if replace the memo(Foo) with Foo;
I spend several days but get no idea, can I get some clue here?

@JoviDeCroock
Copy link
Member

As outlined in my comment it's a bug with memoization and can be addressed in the detaching logic by i.e. setting _force to true.

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

No branches or pull requests

3 participants