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

Warn on non-plain objects with same prototype and own fields #74

Closed
Hypnosphi opened this issue Nov 14, 2019 · 7 comments · Fixed by #179
Closed

Warn on non-plain objects with same prototype and own fields #74

Hypnosphi opened this issue Nov 14, 2019 · 7 comments · Fixed by #179
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Hypnosphi
Copy link
Contributor

Hypnosphi commented Nov 14, 2019

Right now there is a false negative with non-plain objects passed as props, e.g. errors:

const DisplayError = memo(({error}) => (
  <>
    <h1>{error.message}</h1>
    <p>{error.stack}<p>
    {error instanceof SomeSpecificError && <SomethingElse />}
  </>
)

const App = () => {
  const [counter, increment] = useReducer(state => state + 1, 0)
  useEffect(() => setTimeout(increment, 100), [])
  return <DisplayError error={new Error('message')} />
}

here, error prop is deep equal to the previous value but there's no warning

One possible solution is to check both Object.getPrototypeOf(obj) and Object.keys(obj) for non-plain objects

@vzaidman vzaidman added good first issue Good for newcomers help wanted Extra attention is needed labels Nov 19, 2019
@VariableVasasMT
Copy link

Can I pick this up?

@vzaidman
Copy link
Collaborator

yes, go on :)

@vzaidman
Copy link
Collaborator

@VariableVasasMT no success? :)

@VariableVasasMT
Copy link

@vzaidman I am extremely sorry, shit hit the fan, will pick this up, this week.

@vzaidman vzaidman added the enhancement New feature or request label Apr 29, 2020
@vzaidman
Copy link
Collaborator

vzaidman commented Feb 5, 2021

what's up @VariableVasasMT?

@barakyosi
Copy link
Contributor

@vzaidman @VariableVasasMT I saw this issue was stale for few months so I opened a PR for it, hope you don't mind.
LMKWYT :)

@vzaidman
Copy link
Collaborator

Great!
I'll go over the pr asap!
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants