welldone-software / why-did-you-render

why-did-you-render by Welldone Software monkey patches React to notify you about potentially avoidable re-renders. (Works with React Native as well.)
https://www.npmjs.com/package/@welldone-software/why-did-you-render
MIT License
11.11k stars 196 forks source link

Diff function produces no output #254

Open jcollum-nutrien opened 2 years ago

jcollum-nutrien commented 2 years ago

Start by rendering a page, get this result, click on item 1:

image

Save as a global:

image

When I run the global function the result is undefined:

image

I have seen this function produce detailed output before. So either I'm doing something wrong or there's a bug.

jcollum-nutrien commented 2 years ago

Talked this over with another dev and the issue is probably due to circular references in the object. If you want to fix that:

const getCircularReplacer = () => {
  const seen = new WeakSet();
  return (key, value) => {
    if (typeof value === 'object' && value !== null) {
      if (seen.has(value)) {
        return;
      }
      seen.add(value);
    }
    return value;
  };
};

JSON.stringify(obj, getCircularReplacer());
jcollum-nutrien commented 2 years ago

Related #250