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: lightningcss fails with html-proxy #13776

Merged
merged 6 commits into from Jul 24, 2023

Conversation

Marabyte
Copy link
Contributor

@Marabyte Marabyte commented Jul 10, 2023

Description

Fixes a bug when using Lightning CSS with Vite Server and html-proxy

Additional context

The issue was originally found when attempting to use Storybook with + Vitejs 4.4 with the lightningcss optioins enabled.

The shell app builds but when build the preview iframe it breaks with the error:

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: GenericFailure] {
  code: 'GenericFailure',
  plugin: 'vite:css',
  id: '\x00/iframe.html?html-proxy&direct&index=0.css',
  pluginCode:[css code]
}

I would guess the problem is here: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/css.ts#L2176:L2181

When processing CSS from proxy the filePath is an empty string or a relative path without a filename so we fail the first condition and try to read the file from the file system.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Jul 10, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@Marabyte Marabyte marked this pull request as ready for review July 10, 2023 16:03
ArnaudBarre
ArnaudBarre previously approved these changes Jul 16, 2023
Comment on lines +2186 to +2189
// This happens with html-proxy (#13776)
if (!filePath.endsWith('.css')) {
return src
}
Copy link
Member

Choose a reason for hiding this comment

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

When running the playground, I got "" (empty string) as a value of filePath. I think this doesn't make sense and it's a bug in Lightning CSS. But I think it's fine to merge this as a workaround for now.

@sapphi-red sapphi-red added feat: css p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) labels Jul 24, 2023
@patak-dev
Copy link
Member

We can merge this PR as a temporal patch as suggested, but I think more tests are needed and the way id is converted to filename here doesn't seems correct to me. What happens when the id is a virtual module? Several html-proxy ids could end up mapped to the same filename, no? And then this filename is resolved and added to deps. Shouldn't there be a way to respect the id that has already been resolved and for which we already have the src and avoid re-resolving it?

@patak-dev patak-dev merged commit 6b56094 into vitejs:main Jul 24, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants