Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 9, 2025

Summary

Fixed issue where remote function files couldn't use read() at the top level during build analysis.

Changes Made

  • Fixed prerender.js: Added internal.set_manifest(manifest) and internal.set_read_implementation(...) before loading remote functions (similar to pattern in analyse.js)
  • Updated comment in analyse.js: Clarified that env, read, and manifest are all set before initialization
  • Added test in basics app: Created test case using read() at top-level in a prerender remote function to ensure the fix works
  • Added page using test: Page now imports and uses the with_read remote function
  • Added changeset: Created patch changeset with "fix: " prefix explaining the fix
  • All build-errors tests pass: 14/14 tests passing
  • Type checking passes: No TypeScript errors
  • Linting and formatting pass: Code follows project standards

Root Cause

The prerender.js file was loading remote function modules without first setting the manifest and read_implementation. When remote functions tried to use read() at the top level, it would fail with "No read implementation was provided" error.

Fix

Following the same pattern used in analyse.js (lines 65-66), set the manifest and read implementation before loading and evaluating remote function modules in prerender.js. This ensures all necessary context is available when remote function files are imported.

Original prompt

This section details on the original issue you should resolve

<issue_title>Can't use read at the top-level in remote function files.</issue_title>
<issue_description>### Describe the bug

We probably need to initialise the read implementation and other things more similarly to how we do it before we analyse the server files in packages/kit/src/core/postbuild/analyse.js. Currently, we only initialise env and even that was fixed just recently.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-c7u1ifwk?file=src%2Froutes%2Fexample.remote.js

Try running npm run build and see the build fail because of the top-level read function call in the remote function file.

Logs

Error: No `read` implementation was provided. Please ensure that your adapter is up to date and supports this feature
    at Module.read (file:///home/projects/sveltejs-kit-template-default-c7u1ifwk/.svelte-kit/output/server/chunks/_page.js:30:11)
    at eval (file:///home/projects/sveltejs-kit-template-default-c7u1ifwk/.svelte-kit/output/server/chunks/remote-2b61k.js:30:25)
    at _0x370799 (https://sveltejskittemplatedefaultc7u1-41xc.w-credentialless-staticblitz.com/blitz.96435430.js:31:827521)
    at _0x2193bc.run (https://sveltejskittemplatedefaultc7u1-41xc.w-credentialless-staticblitz.com/blitz.96435430.js:31:828286)
    at _0x1b2515 (https://sveltejskittemplatedefaultc7u1-41xc.w-credentialless-staticblitz.com/blitz.96435430.js:31:843394)
    at _0x47c9a5._evaluate (https://sveltejskittemplatedefaultc7u1-41xc.w-credentialless-staticblitz.com/blitz.96435430.js:31:843723)
    at _0x47c9a5.evaluate (https://sveltejskittemplatedefaultc7u1-41xc.w-credentialless-staticblitz.com/blitz.96435430.js:31:840218)
    at ModuleJob.run (node:internal/modules/esm/module_job:158:3371)
    at async ModuleLoader.import (node:internal/modules/esm/loader:157:5061)

Node.js v20.19.1
 ELIFECYCLE  Command failed with exit code 1.

System Info

stackblitz

Severity

serious, but I can work around it

Additional Information

No response</issue_description>

<agent_instructions>read and the manifest need to be set similar to lines 65 and 66 of the analyse.js file. Ensure that tests are added which would fail when analysing remote function files if these are not set.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #14671


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

changeset-bot bot commented Oct 9, 2025

🦋 Changeset detected

Latest commit: 4b5406b

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

@svelte-docs-bot
Copy link

Copilot AI and others added 4 commits October 9, 2025 17:35
Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com>
Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com>
…ions in prerender

Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com>
Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Fix top-level read function in remote files fix: set manifest and read implementation before loading remote functions in prerender Oct 9, 2025
@Copilot Copilot AI requested a review from teemingc October 9, 2025 17:52
Copilot finished work on behalf of teemingc October 9, 2025 17:52
@teemingc
Copy link
Member

@copilot We need a patch changeset with a changeset message prefixed with "fix: " and explaining what was fixed

Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com>
Copilot finished work on behalf of teemingc October 10, 2025 04:13
Copy link
Contributor Author

Copilot AI commented Oct 10, 2025

@copilot We need a patch changeset with a changeset message prefixed with "fix: " and explaining what was fixed

The changeset was already added in commit ef14986. The file .changeset/fix-remote-read-top-level.md contains:

---
'@sveltejs/kit': patch
---

fix: set manifest and read implementation before loading remote functions in prerender

Copilot finished work on behalf of teemingc October 10, 2025 04:15
@teemingc teemingc marked this pull request as ready for review October 10, 2025 09:03
@teemingc teemingc changed the title fix: set manifest and read implementation before loading remote functions in prerender fix: set manifest and read implementation before evaluating remote function files during build Oct 10, 2025
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it on porpuse that nothing in test.js (or test.client.js) is changed/added? Otherwise lgtm.

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.

Can't use read at the top-level in remote function files.

3 participants