question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vzaidmancommented, Feb 13, 2021

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

0reactions
barakyosicommented, Feb 13, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inheritance and the prototype chain - JavaScript | MDN
Each object has a private property which holds a link to another object called its prototype. That prototype object has a prototype of...
Read more >
Prototypal inheritance - The Modern JavaScript Tutorial
In JavaScript, objects have a special hidden property [[Prototype]] (as named in the specification), that is either null or references another ...
Read more >
Understanding Prototypes and Inheritance in JavaScript
In this tutorial, we will learn what object prototypes are and how to use the constructor function to extend prototypes into new objects....
Read more >
Use of 'prototype' vs. 'this' in JavaScript? - Stack Overflow
In JavaScript, all functions objects have a prototype property by default so there is no separate code to create an A.prototype object. In...
Read more >
Prototype in JavaScript - TutorialsTeacher
The prototype is an object that is associated with every functions and objects by default in JavaScript, where function's prototype property is accessible ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found