Skip to content

fix: allow requested() in a command called from other server code - #17040

Open
kdelay wants to merge 1 commit into
sveltejs:version-3from
kdelay:fix/issue-17035-command-requested-outside-remote-request
Open

fix: allow requested() in a command called from other server code#17040
kdelay wants to merge 1 commit into
sveltejs:version-3from
kdelay:fix/issue-17035-command-requested-outside-remote-request

Conversation

@kdelay

@kdelay kdelay commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #17035.

requested() throws as soon as a command runs outside a /_app/remote/... request, e.g. when a +server.js handler calls it. is_in_remote_form_or_command is set only by the remote endpoint, so "inside a command" now means "the request arrived at that endpoint". Before #15991 the command wrapper marked the context itself.

The wrapper sets the flag again, the way query.bind sets is_in_remote_query. Such a request has no client-side cache to update, so requested() yields nothing and refreshAll() is a no-op rather than throwing.

Testing

  • pnpm -F @sveltejs/kit test:unit — the first test in the new command.spec.js fails without the runtime change
  • pnpm lint, pnpm -F @sveltejs/kit check, prepublishOnly
  • test-async remote suite in dev mode

@pkg-svelte-dev

pkg-svelte-dev Bot commented Sep 5, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from b768d38:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/b768d38b9d881f8ddffaf9fa0f8a828fba8c6c6f

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/17040

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b768d38

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: QUIET

Plan: Advanced

Run ID: 16502844-da3f-4c17-80cc-9d56646a268c

📥 Commits

Reviewing files that changed from the base of the PR and between c47be02 and b768d38.

📒 Files selected for processing (4)
  • .changeset/olive-crabs-listen.md
  • packages/kit/src/runtime/app/server/remote/command.js
  • packages/kit/src/runtime/app/server/remote/command.spec.js
  • packages/kit/src/runtime/app/server/remote/requested.js
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • sveltejs/vite-plugin-svelte (manual)
  • vitejs/vite (manual)
  • sveltejs/svelte (manual)

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The command wrapper now passes copied request state with is_in_remote_form_or_command set to true. This allows requested() to run when a command is called from other server-side code. New specifications cover non-remote requests, invalid invocation contexts, request-store setup, and query refresh propagation. The changeset records the patch release. The explanatory comment in requested.js now matches the updated context handling.

Merge Risk: ⚪ Minimal · up to b768d

Commands invoked from server code can now use requested() without throwing, while requests without client refresh state remain no-ops. The behavior is covered by targeted runtime tests and is ready to merge.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required fix: prefix and clearly describes the main change: allowing requested() in commands called from other server-side code.
Backward Compatibility Impact Disclosure ✅ Passed PASS — The pull request does not introduce a breaking public-interface change covered by this check. The diff adds an internal is_in_remote_form_or_command state value when command() runs and adds…

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/kit/src/runtime/app/server/remote/command.js

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/kit/src/runtime/app/server/remote/command.spec.js

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

packages/kit/src/runtime/app/server/remote/requested.js

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).


Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

requested() throws when a command is called from server code (e.g. +server.ts) since 2.65.0 / #15991, unlike query.refresh() which no-ops

1 participant