fix: allow query().current and other data properties to work in non-reactive contexts#15699
Conversation
🦋 Changeset detectedLatest commit: e117e75 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 |
|
This is intentional. There's a pretty good explanation here: https://svelte.dev/docs/kit/remote-functions#query-Deduplication Basically, because query.set((current) => [new, ...current]);Since set is already a noop if there's nothing listening for it, it'd achieve what you want. (It's also weird that, as written in this PR, you can access |
|
@elliott-with-the-longest-name-on-github I'm not sure I understand fully – is it not possible to just get the cached value if it exists and return undefined if it doesn't? This patch is working as expected for me, so is there a hidden bug I'm not seeing? A callback form of .set would definitely also work, yes. |
|
Ok we've discussed this at length and I think this is the right way to go, but if we're doing it with |
|
I've added the other properties. I'll make a new PR for the callback form of |
|
@ottomated we can leave the new |
query().current to work in non-reactive contextsquery().current and other data properties to work in non-reactive contexts
b77f00d
into
sveltejs:main
|
can we update doc to indicate this ? also does this mean i can do .run with cache outside of .svelte ? it'd be helpful to allow run and use cache if it is there // b.svelte.ts import a from "a.remote"
async function cached(){
let a = a()
if(a.current is nil ) { return a.run()}
return a.current
} |
|
@zhihengGet please don't revive merged PRs, if you have an issue open an issue! We can discuss there |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @sveltejs/kit@2.58.0 ### Minor Changes - breaking: require `limit` in `requested` (as originally intended) ([#15739](#15739)) - feat: `RemoteQueryFunction` gains an optional third generic parameter `Validated` (defaulting to `Input`) that represents the argument type after schema validation/transformation ([#15739](#15739)) - breaking: `requested` now yields `{ arg, query }` entries instead of the validated argument ([#15739](#15739)) ### Patch Changes - fix: allow `query().current`, `.error`, `.loading`, and `.ready` to work in non-reactive contexts ([#15699](#15699)) - fix: prevent `deep_set` crash on nullish nested values ([#15600](#15600)) - fix: restore correct `RemoteFormFields` typing for nullable array fields (e.g. when a schema uses `.default([])`), so `.as('checkbox')` and friends work again ([#15723](#15723)) - fix: don't warn about removed SSI comments in `transformPageChunk` ([#15695](#15695)) Server-side include (SSI) directives like `<!--#include virtual="..." -->` are HTML comments that are replaced by servers such as nginx. Previously, removing them in `transformPageChunk` would trigger a false positive warning about breaking Svelte's hydration. Since SSI comments always start with `<!--#` and Svelte's hydration comments never do, they can be safely excluded from the check. - Change enhance function return type from void to MaybePromise<void>. ([#15710](#15710)) - fix: throw an error when `resolve` is called with an external URL ([#15733](#15733)) - fix: avoid FOUC for CSR-only pages by loading styles and fonts before CSR starts ([#15718](#15718)) - fix: reset form result on redirect ([#15724](#15724)) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
As of #15533,
query().currentno longer works in non-reactive contexts. I believe this is unwanted behavior -- take the following scenario:This PR fixes it by simply restoring the old behavior of
.currentreturningundefinedif the query has not been called yet.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits