fix(router-core): use safeStringify for loader dependency hash keys - #7834
fix(router-core): use safeStringify for loader dependency hash keys#7834gonzoblasco wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds ChangesLoader dependency serialization
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
126bc3c to
caae808
Compare
Replace JSON.stringify with safeStringify in loaderDepsHash computation to handle types that JSON.stringify cannot serialize (bigint, Set, Map, circular references, functions, symbols, etc.). The previous approach (PR TanStack#7818) attempted to use the configured stringifySearch serializer, but as schiller-manuel pointed out, loader deps are not necessarily search params and should not be tied to the search stringifier. This approach is less invasive: it replaces the serializer inline without changing the API or coupling loader deps to search params. Fixes TanStack#7787
caae808 to
ccca3e5
Compare
…gify-loader-deps # Conflicts: # packages/router-core/src/router.ts
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Description
Replace
JSON.stringifywithsafeStringifyinloaderDepsHashcomputation to handle types thatJSON.stringifycannot serialize (bigint, Set, Map, circular references, functions, symbols, etc.).Problem
loaderDepsHashwas hardcoded toJSON.stringify, which throws onbigintvalues and cannot handleSet,Map, circular references, or symbols. Users with custom search serializers that support these types would get runtime errors when using them inloaderDeps.Previous attempt
PR #7818 attempted to use the configured
stringifySearchserializer instead. As @schiller-manuel correctly pointed out, loader deps are not necessarily search params and should not be tied to the search stringifier.This approach
Introduce
safeStringify— a zero-dependency utility that safely serializes any value to a deterministic JSON string:"123n"(string representation)[key, value]entry arrays"[Circular]"(detected via WeakSet)"[Function]"No API changes. No new dependencies. No coupling between loader deps and search params.
Tests
Added 12 unit tests covering all edge cases above.
Verification
tests/utils.test.ts— 127 passed, 3 expected fail (pre-existing)tests/searchParams.test.ts— all passedFixes #7787
Summary by CodeRabbit
Bug Fixes
Tests