Read query and mutation state as properties, not accessors - #285
Merged
Conversation
2.12.0 exposed accessors -- `query.data()`. `solid-query`, which this replaces, returned a store, so every consumer that will be migrated onto it is written `query.data`: about 3300 such reads across these applications, 2097 of them `.data` alone. Keeping accessors would have made the migration touch every file that *reads* a query rather than the ~300 that define one, for no gain. These are getters over the same signals, so a read inside a tracked scope subscribes exactly as an accessor call did -- there is a test asserting the subscription rather than just the value. `isPending`, `isError` and `isSuccess` come along for the same reason, so carried-over call sites keep working. `isPending` deliberately does not mean what it meant: there it was "has no data", which stayed true forever for a query held back by `enabled: false`, so `if (isPending) return <Spinner/>` spun for the life of the page. Here it means a fetch is in flight. Breaking against 2.12.0, which no application consumes yet.
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.
Corrects the API shape of the primitives added in #284, before any application is written against them.
Why this is needed
I designed
createQueryaround accessors —query.data()— without first measuring how the code that will consume it is written.solid-queryreturns a store, so every existing consumer reads properties:.data.isLoading.isSuccess.isError.isPendingRoughly 3300 reads. Keeping accessors would have meant editing every file that reads a query, not just the ~300 that define one — and for no benefit, since a getter over a signal subscribes identically.
So this is a straight shape change: getters over the same signals.
What changed
QueryResultandMutationResultexposedata,error,isLoading,isError,isSuccess,isReady(andisPending) as properties.refetch,mutate,mutateAsync,resetstay methods, matching what call sites already write.isPendingis carried over deliberately with different meaning, and this is the one thing to look at closely. Insolid-queryit meant "has no data", which stayed true forever for a query held back byenabled: false— soif (isPending) return <Spinner/>spun for the life of the page. That is the defect that took honey.id's authenticated routes down. Here it means "a fetch is in flight", so a disabled query reads as not pending and its consumer renders instead of hanging. Call sites migrate without edits, but they behave better rather than identically.Verification
bun test --conditions=browser src/hooks/data— 8 pass.createRenderEffectreadingq.datare-runs when the fetch resolves. It asserts the subscription, not just the value, because "getters still track" is the whole basis for this change.bunx tsc --noEmitclean,biome lintclean on the changed files.Compatibility
Breaking against 2.12.0. Nothing consumes it yet — 2.12.0 published about a minute before this branch — so the blast radius is zero if it lands before the site migrations start.