fix(db): treat objects with Symbol.toStringTag as leaf values in IsPlainObject#1373
Open
sleitor wants to merge 2 commits intoTanStack:mainfrom
Open
fix(db): treat objects with Symbol.toStringTag as leaf values in IsPlainObject#1373sleitor wants to merge 2 commits intoTanStack:mainfrom
sleitor wants to merge 2 commits intoTanStack:mainfrom
Conversation
…ainObject
Temporal types (Temporal.PlainDate, ZonedDateTime, etc.) have
Symbol.toStringTag set but are not in the JsBuiltIns union, causing
IsPlainObject to return true and Ref<T> to recursively walk their
methods and mangle them to {}.
Adds a Symbol.toStringTag check so all class instances (including all
Temporal types) are treated as leaf values, preserving their types in
query select projections.
Fixes TanStack#1372
🦋 Changeset detectedLatest commit: 634beb3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
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 |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1372
Temporal types (e.g.
Temporal.PlainDate,Temporal.ZonedDateTime,Temporal.Instant) haveSymbol.toStringTagset to a string. Previously,IsPlainObjectwould returntruefor these types because they are objects and not in theJsBuiltInsunion. This caused theRef<T>mapped type to recursively walk their methods and mangle them to{}.Root Cause
In
packages/db/src/query/builder/types.ts,IsPlainObject<T>determines how each field is processed through theRef<T>mapped type:JsBuiltInslikeDate,Map, etc.) → treated as leaf values, type preserved as-isTemporal.PlainDateextendsobjectbut is not in theJsBuiltInsunion, soIsPlainObjectreturnstrue. This causesRef<T>to recursively walk its methods, producing:Fix
Adds a
T extends { readonly [Symbol.toStringTag]: string }check toIsPlainObjectbefore returningtrue. Objects withSymbol.toStringTagare class instances (Temporal types, custom tagged objects), not plain data objects. This covers all Temporal types without requiring an explicit import or a maintained hardcoded list.Testing
Lint and build pass. The type change is entirely in
types.tswith no runtime behavior affected.