sveltejs / sveltejs/kit

remote query without await

Open
#16,477 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

I don't know if this is intended, but it feels unintuitive.

This does not fetch:

<script lang="ts">
	import { getPosts } from './data.remote';

	const query = getPosts();
</script>

This does:

<script lang="ts">
	import { getPosts } from './data.remote';

	const query = getPosts();
	query.loading
</script>

It seems like you have to access loading, current or error to trigger the fetch of the RemoteQueryFunction.
I created a little repo to showcase how i try to preload stuff for a component.

I would assume, that calling getPosts() would already start fetching.

Reproduction

https://github.com/hendrik-huels/bug-or-feature

Logs

System Info
tested on "@sveltejs/kit": "^2.63.0" and "@sveltejs/kit": "3.0.0-next.11"
Severity

annoyance

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and compare the two snippets: calling getPosts() alone versus reading query.loading, current, or error. Trace the RemoteQueryFunction behavior involved in that difference and determine whether invocation should start the fetch or whether the current behavior is intended. Done means the behavior is corrected or clearly documented, with the reproduction demonstrating the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.