Fix select() to handle direct ref returns as spreads#1276
Fix select() to handle direct ref returns as spreads#1276KyleAMathews wants to merge 2 commits intomainfrom
Conversation
… operator
When a RefProxy is returned directly from the select callback
(e.g. `.select(({ users }) => users)`), convert it to a spread sentinel
so it behaves identically to the spread form
(`.select(({ users }) => ({ ...users }))`).
Previously, the direct return form would pass a RefProxy through
buildNestedSelect → toExpr, producing a PropRef whose own properties
(type, path) were iterated by the compiler instead of the actual row
data — yielding ref metadata objects instead of the real data.
The fix detects RefProxy at the top level of select() and synthesizes
the equivalent spread sentinel before handing off to buildNestedSelect.
https://claude.ai/code/session_01KAGFqbqFxY2YYV4uTVTBa8
|
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: |
|
Size Change: +54 B (+0.06%) Total Size: 92.1 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
samwillis
left a comment
There was a problem hiding this comment.
I think we need to validate that the ref proxy is for a spreadable object. At the moment we can't support a user returning a single literal value, like a string or number.
|
Other than that, looking good. Needs a changeset |
|
Closing this in favor of the work that landed in #1384. We did incorporate the useful part of this PR, but in a narrower form. What we kept:
What we intentionally did not keep:
The reason is that we needed to land scalar child selects for select(({ c }) => c.text)to remain genuine scalar selections, not be rewritten as spread-like object projections. So the behavior now is:
That gives us the safe/fixed case this PR was targeting, without conflicting with the scalar-select work in #1384 and the follow-up boundary tightening there. Because of that, this PR is effectively superseded by the narrower implementation on that branch, so I’m closing this one. |
🎯 Changes
Fixed a common pitfall in the
select()query builder where returning a ref directly (e.g.,select(({ users }) => users)) would produce ref/proxy metadata instead of actual row data.The fix detects when a callback returns a
RefProxydirectly and automatically treats it as if the user had spread it (e.g.,select(({ users }) => ({ ...users }))). This is accomplished by:isRefProxy()check in theselect()methodbuildNestedSelect()logic already handles correctly✅ Checklist
pnpm test.🚀 Release Impact
Test Coverage: Added three comprehensive test cases covering:
https://claude.ai/code/session_01KAGFqbqFxY2YYV4uTVTBa8