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

Bug: StrictMode is not detecting "ref-trashing" #27432

Closed
theKashey opened this issue Sep 28, 2023 · 1 comment
Closed

Bug: StrictMode is not detecting "ref-trashing" #27432

theKashey opened this issue Sep 28, 2023 · 1 comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@theKashey
Copy link
Contributor

React version:

  • any (18.2.0 currently)

Steps To Reproduce

  1. create unstable ref on a component (<div ref={(node) => setState(node)}/>)
  2. render/re-render component
  3. StrictMode will not report about the problem of ref being unstable between renders

Link to code example:

there are many different ways to create unstable ref:

The current behavior

  • nothing enforces the correct usage of refs or able to inform about the incorrect ones

The expected behavior

  • StrictMode is capable of reporting refs being updated on every render

I've monkey-patched react code (markRef here and here) to get informed about ref change and found a few changes that should not happen.

This a problem very hard to detect without a support from the platform, and my little experiment is incapable to understand the legacy of ref update, only the fact of such update.

@theKashey theKashey added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Sep 28, 2023
@sophiebits
Copy link
Collaborator

This is not technically incorrect code. Generally there should not be a need to store a DOM node in state.

Thanks for the idea but we don't have plans to add more to StrictMode at this time; I would recommend using a lint rule to prevent the patterns you mentioned if this is important for your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants