Repository navigation
Conversation
Let JSON.stringify perform toJSON conversion before the existing circular-reference checks.
Cover single invocation with property keys, returned objects, and genuine conversion errors.
Add a patch release note for the internal serializer correction.
🦋 Changeset detectedLatest commit: de8bb6e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
PR Checklist
fix(internal): avoid calling toJSON twice in safeStringifyBugs / Features
JSON.stringify; there is no public API change.What is the current behavior?
JSON.stringifycalls an object'stoJSON(key)before passing its result to the replacer.safeStringifythen invokestoJSONagain when that result is an object with atoJSONmethod.For example, a self-returning
toJSONruns twice for one property. If its second invocation throws,safeStringifyreturnsSAFE_STRINGIFY_ERRORrather than valid JSON. The extra invocation also lacks the property-key argument. An object returned bytoJSONcan likewise have its own method unexpectedly invoked.What is the new behavior?
Leave
toJSONconversion toJSON.stringify, then apply the existing circular-reference checks to its result. The traversal stack andWeakSethandling are preserved.Regression tests cover a self-returning method being called once with its property key, an object returned by
toJSON, and errors genuinely thrown by the initial conversion. Existing circular-reference, shared-reference, Date, and custom-serialization tests remain unchanged.Notes for reviewers
Validation used Node 24.22.1 and Vitest 3.2.4 against the actual source modules:
tscreports a pre-existingMapinference error insrc/utils/objects.spec.ts:171. Running the same check with the original HEAD source and tests produced identical output.git diff --checkpassed.The full monorepo build, full-repository lint, core integration/e2e tests, and Node 20/22 matrix were not run locally. Tools were installed in an isolated lightweight environment rather than installing the entire monorepo.
Historical PR #961 replaced recursive reconstruction with stack-based traversal for performance. This patch keeps that approach; its existing custom-serialization tests compare against native
JSON.stringify. The behavioral correction is specifically removal of the extra conversion, including for objects returned bytoJSON.This contribution was prepared and independently checked with AI assistance. The checks listed above were actually run; this does not claim human review.
Independent validation refresh (2026-11-03)
Exact PR head
de8bb6eb2173790c1d736e19fd3ba052f5999e67was rechecked against unchanged main72a46c76b4507e1f98b41d5050a92bd30587eb70. A fresh Node 24 run of all six internal-package test files produced 129 passed, 2 failed and 1 skipped on the baseline, then 131 passed and 1 skipped on the PR. This repeats the package inventory above; it is not an additional 131 unique tests. Ten separate direct-TypeScript boundary probes produced 7 passed/3 failed on baseline and 10 passed on the PR. Changed-file strict TypeScript and Biome checks passed. Whole-package TypeScript still reports the identical pre-existing TS2769 Map inference diagnostic on baseline and PR; it did not pass.This refresh did not run the full workspace build/tests/lint, core integration/E2E, or Node 20/22. It does not claim hosted CI success: the PR workflow currently awaits maintainer approval, and CodeRabbit skipped review while the PR was a draft. The independent verification was AI-assisted, not human or maintainer approval.
Summary by CodeRabbit
toJSONbehavior without invoking it twice, and handles circular references and serialization errors correctly.toJSONcall counts, returned values, and errors.