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

Include styles for dynamically imported components #5138

Merged
merged 14 commits into from Jul 5, 2022
Merged

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Jun 1, 2022

#5137. This is a partial fix — it solves the SSR problem in prod builds, and solves it in dev when the page is reloaded (because node.ssrTransformResult has been computed by that point), but not for the initial page load. Not yet sure what the solution looks like. Maybe we can wait until load has completed before computing the styles. (The most obvious alternative is to eagerly load the dynamically imported modules, but that would be a bad idea in the case where they're dynamically imported precisely because they can't be loaded on the server.)

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. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Jun 1, 2022

🦋 Changeset detected

Latest commit: 036e35c

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

@Rich-Harris Rich-Harris marked this pull request as draft June 1, 2022 17:56
@benmccann
Copy link
Member

It might be nice to see if we can use Vite's importedCss (vitejs/vite#6629)

@dominikg
Copy link
Member

dominikg commented Jun 1, 2022

maybe related: injecting a link for component styles is pending this: sveltejs/vite-plugin-svelte#341

If we want to avoid the js, is there a way to compile only the css for a component?

@PatrickG
Copy link
Contributor

Can we merge this as is so that styles of dynamic imported components load at least in production builds without javascript?

@Rich-Harris
Copy link
Member Author

It might be nice to see if we can use Vite's importedCss (vitejs/vite#6629)

Not sure I understand what that is and what benefit it brings?

If we want to avoid the js, is there a way to compile only the css for a component?

Not without changes to Svelte itself

Can we merge this as is so that styles of dynamic imported components load at least in production builds without javascript?

We generally try and avoid that — it ends up being more work as you need to create a new issue and then (eventually) a new PR. Better to just fix it in one go, even if it means a slight delay

@Rich-Harris
Copy link
Member Author

Alright, I think this is ready to go

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.

None yet

4 participants