Skip to content

feat: circular ref json serialization#29

Merged
Bekacru merged 10 commits intobetter-auth:mainfrom
Kinfe123:fix/circular-ref-json-serialization
Aug 6, 2025
Merged

feat: circular ref json serialization#29
Bekacru merged 10 commits intobetter-auth:mainfrom
Kinfe123:fix/circular-ref-json-serialization

Conversation

@Kinfe123
Copy link
Contributor

@Kinfe123 Kinfe123 commented Aug 6, 2025

No description provided.

replacer?: (key: string, value: any) => any,
space?: string | number,
): string {
const seen = new WeakSet();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let id = 0;
const seen = new WeakMap<object, number>(); // ref -> counter

// then

if (seen.has(value)) {
  return `[Circular ref${seen.get(value)}]`;
}
seen.add(value, id++);

By doing like this, it would be useful for cross-boundary and recover the circular reference to the original JSON (in the future)

@Bekacru Bekacru merged commit 6010e4a into better-auth:main Aug 6, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants