Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Alazli
Copy link
Contributor

@Alazli Alazli commented Oct 15, 2025

Summary
Fixes syntax errors in remote module transformation when .remote.js files end without a trailing semicolon, space, or newline.
Fixes #14726

Problem
Remote module transformation fails with syntax errors when the source file ends with an expression or a comment and lacks a trailing semicolon, space, or newline.
This causes the concatenated output to become invalid JavaScript.

Example of the Problem:

// Original file ends with:
console.log(22)

// Becomes invalid after transformation:
console.log(22)import * as $$_self_$$ from "./test.remote.js";
//                                    ^ Syntax error here

Root Cause
When Vite transforms .remote.js files, it concatenates the generated code directly with the original module.
If the original file ends with an expression (e.g. console.log) or a comment without a trailing newline, the combined code breaks syntax validity.

Fix
Ensure safe concatenation by adding a newline (or other delimiter) between the transformed code and the original module content.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm check
  • Note: One intermittent timeout error in test suite (unrelated to string concatenation change)

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Problem
Remote module transformation fails with syntax errors when the source file ends with an expression or a comment and does not include a trailing semicolon, space, or newline. This results in invalid concatenated code.

Root Cause
When Vite transforms .remote.js files, it concatenates the generated code with the original module. If the original module ends with an expression (e.g. console.log) or a comment without a trailing newline, the resulting code becomes syntactically invalid.
@changeset-bot
Copy link

changeset-bot bot commented Oct 15, 2025

🦋 Changeset detected

Latest commit: fc3d26c

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

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.

thank you!

@dummdidumm dummdidumm merged commit 9c933a2 into sveltejs:main Oct 15, 2025
16 of 18 checks passed
@github-actions github-actions bot mentioned this pull request Oct 15, 2025
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.

Remote function file fails when containing commented-out functions: $$_self_$$ is not defined

2 participants