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

[CDataTable] Error in objectsAreIdentical with circular obj #75

Closed
ajm13 opened this issue Mar 28, 2020 · 1 comment
Closed

[CDataTable] Error in objectsAreIdentical with circular obj #75

ajm13 opened this issue Mar 28, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@ajm13
Copy link

ajm13 commented Mar 28, 2020

CDataTable uses JSON.stringify in objectsAreIdentical. When items contains objects with circular references, JSON.stringify throws an error, and this will happen every time items or sortedItems changes.

This can be fixed by using a cache and providing a function to JSON.stringify to avoid circular references, like this example:

export const customStringify = function (v: any) {
  const cache = new Map();
  return JSON.stringify(v, function (key, value) {
    if (typeof value === 'object' && value !== null) {
      if (cache.get(value)) {
        // Circular reference found, discard key
        return;
      }
      // Store value in our collection
      cache.set(value, true);
    }
    return value;
  });
};

from here

@woothu woothu added the bug Something isn't working label Mar 28, 2020
@woothu
Copy link

woothu commented Mar 30, 2020

Hi! Thank you for this report! What is the use case of passing circular objects to items?

@woothu woothu closed this as completed Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants