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

refactor: isCSSRequest for all css #4484

Merged
merged 3 commits into from Aug 4, 2021

Conversation

y1d7ng
Copy link
Contributor

@y1d7ng y1d7ng commented Aug 3, 2021

Description

#4127 (comment)

isCSSRequest is misleading. This can easily cause some bugs as people may using it without knowing that it explicitly tests for not being a direct request.

Additional context


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 Commit 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.

@Shinigami92 Shinigami92 added the p1-chore Doesn't change code behavior (priority) label Aug 3, 2021
Shinigami92
Shinigami92 previously approved these changes Aug 3, 2021
@@ -147,7 +151,10 @@ export function transformMiddleware(

// for CSS, we need to differentiate between normal CSS requests and
// imports
if (isCSSRequest(url) && req.headers.accept?.includes('text/css')) {
if (
isIndirectCSSRequest(url) &&
Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't use isIndirectCSSRequest here because at this point we don't know if it is direct or not. It would be more clear to me if we use isCSSRequest(url) && !isDirectRequest(url)
This should read as "is this a CSS Request that is not yet marked as direct?"

@patak-dev
Copy link
Member

This PR is modifying some calls that we should review:

@OneNail is this analysis correct? Would you help us with comments about why each of these changes is correct?

@patak-dev
Copy link
Member

If isIndirectCSSRequest is not needed, this change ends up being just about removing the extra !directRequestRE.test(request) here

cssLangRE.test(request) && !directRequestRE.test(request)

That looks fine to me.

I wonder why it was added. It was part of the original commit that added the direct check.

@y1d7ng
Copy link
Contributor Author

y1d7ng commented Aug 3, 2021

@patak-js Thank you very much for your review, I think your analysis is correct. So it seems that isIndirectCSSRequest is really not needed, I have removed it.

Shinigami92
Shinigami92 previously approved these changes Aug 3, 2021
if (isCSSRequest(url) && req.headers.accept?.includes('text/css')) {
if (
isCSSRequest(url) &&
!isDirectCSSRequest(url) &&
Copy link
Member

Choose a reason for hiding this comment

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

I think we should use a direct regex check here or maybe add a isDirectRequest(url) function to avoid repeating the CSS regex on every CSS file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I misunderstood it before and have changed it

@patak-dev patak-dev merged commit 7ad8ba2 into vitejs:main Aug 4, 2021
@y1d7ng y1d7ng deleted the refactor/isCSSRequest branch August 18, 2021 01:36
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p1-chore Doesn't change code behavior (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants