Skip to content

Conversation

@teemingc
Copy link
Member

@teemingc teemingc commented Nov 28, 2024

fixes #6720

This PR changes the inlined stylesheet from client to server so that the paths for imported assets in the CSS such as fonts are correct when the document first loads. In comparison, the client stylesheet links are relative by default, so they always link to the wrong place

e.g., URL("./font.woff") links to example.com/font.woff when loaded from the document instead of example.com/_app/immutable/.... However, when loaded from an external stylesheet, the link is correct because the stylesheet is already loaded from /_app/immutable/....

TODO:

  • find a more reliable way of mapping client stylesheets to server stylesheets

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 lint and pnpm check

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.

@changeset-bot
Copy link

changeset-bot bot commented Nov 28, 2024

🦋 Changeset detected

Latest commit: 3b44f22

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

@teemingc teemingc marked this pull request as draft November 28, 2024 07:01
@teemingc teemingc marked this pull request as ready for review November 28, 2024 07:45
}

// ignore dynamically imported stylesheets since we can't inline those
css.filter(asset => client_stylesheets.has(asset.fileName))
Copy link
Member

Choose a reason for hiding this comment

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

Just for understanding: asset.fileName is always different between client and server, i.e. there's no chance of this accidentally filtering out a server stylesheet?

Copy link
Member Author

@teemingc teemingc Dec 17, 2024

Choose a reason for hiding this comment

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

Yeah, they're always different. The client stylesheets correspond to the node index number while server stylesheets are always "_page" or "_layout".

Copy link
Contributor

@tkhs0813 tkhs0813 Jan 29, 2025

Choose a reason for hiding this comment

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

@eltigerchino @dummdidumm
When running npm run build in SvelteKit v2.16.1, the following error occurs:

[vite-plugin-sveltekit-compile] ENOENT: no such file or directory, open '/Users/me/.svelte-kit/output/server/undefined'
    at Object.readFileSync (node:fs:442:20)
    at file:///Users/me/node_modules/@sveltejs/kit/src/exports/vite/build/build_server.js:59:24
    at Array.forEach (<anonymous>)
    at build_server_nodes (file:///Users/me/node_modules/@sveltejs/kit/src/exports/vite/build/build_server.js:51:5)
    at Object.handler (file:///Users/me/node_modules/@sveltejs/kit/src/exports/vite/index.js:919:5)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async PluginDriver.hookParallel (file:///Users/me/node_modules/rollup/dist/es/shared/node-entry.js:20734:17)
    at async file:///Users/me/node_modules/rollup/dist/es/shared/node-entry.js:21783:13
    at async catchUnfinishedHookActions (file:///Users/me/node_modules/rollup/dist/es/shared/node-entry.js:21158:16)
    at async build (file:///Users/me/node_modules/vite/dist/node/chunks/dep-CHZK6zbr.js:65607:16)

Looking at the contents of client_stylesheets and asset.fileName, there is a filename string like _app/immutable/assets/Header.k7gKBesC.css, which seems to be causing the error.
inlineStyleThreshold is set in sveltekit.config.js.

Since this issue only occurs in the SvelteKit application developed at my company, I am unable to provide a minimal reproducible code example. Do you know how to resolve this?

Using the following versions:

    "@sveltejs/adapter-node": "5.2.12",
    "@sveltejs/kit": "2.16.1",
    "@sveltejs/vite-plugin-svelte": "3.1.2",
    "vite": "5.4.14",

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that someone else has encountered the same issue as me.
#13304 (comment)

Choose a reason for hiding this comment

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

@tkhs0813, removing inlineStyleThreshold resolved the issue for me!

Copy link
Member

Choose a reason for hiding this comment

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

Will be fixed by #13395

Choose a reason for hiding this comment

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

@dummdidumm, great! Thanks for the update!

@teemingc teemingc marked this pull request as draft December 17, 2024 07:53
@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-kit-13068-svelte.vercel.app/

this is an automated message

@teemingc teemingc marked this pull request as ready for review December 24, 2024 09:01
@teemingc teemingc requested a review from dummdidumm December 24, 2024 09:02
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.

inlineStyleThreshold causes relative link to fonts/resources to be broken

6 participants