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

Preact/compat - StrictMode should call shouldComponentUpdate twice in DEV #2676

Closed
christianpv opened this issue Aug 4, 2020 · 2 comments
Closed

Comments

@christianpv
Copy link

christianpv commented Aug 4, 2020

Reproduction

Steps to reproduce

Type "a" in the email input.

Expected Behavior

Console log shows the value "a" twice.

Actual Behavior

Console log shows the value "a" once.

Note

React added this change in the following PR: facebook/react#17942

@sventschui
Copy link
Member

sventschui commented Aug 4, 2020

Thank you for the bug report.

The "problem" here is that we do not have a "DEV Mode" as react has. We might want to add this to preact/debug though since I understand this "feature" more as a hint for developers to not rely on side effects in sCU as it might be called multiple times in the future (concurrent mode).

Would you be happy with having this in preact/debug?

Edit: This should not only apply for sCU but also for:

  • Class component constructor, render, and shouldComponentUpdate methods
  • Class component static getDerivedStateFromProps method
  • Function component bodies
  • State updater functions (the first argument to setState)
  • Functions passed to useState, useMemo, or useReducer

@developit
Copy link
Member

Since we don't have a dev mode, we won't be adding this feature. It's not an API decision, it's a forcing function the react team is using to make sure developers don't rely on lifecycle timing semantics. Preact is not changing those timing semantics, so we have no reason to intentionally break them as a developent aide. No code should ever be relying on sCU being called twice, doing so would be a hack.

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