Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: inline server stylesheets instead of client stylesheets #13068

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino 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.

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

@eltigerchino eltigerchino marked this pull request as draft November 28, 2024 07:01
@eltigerchino eltigerchino marked this pull request as ready for review November 28, 2024 07:45
packages/kit/src/exports/vite/build/build_server.js Outdated Show resolved Hide resolved
}

// 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

@eltigerchino eltigerchino 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".

@eltigerchino eltigerchino 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

@eltigerchino eltigerchino marked this pull request as ready for review December 24, 2024 09:01
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
3 participants