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: reuse the old preprocessor after changing the lang attr #4224

Merged
merged 3 commits into from
Jul 20, 2021

Conversation

y1d7ng
Copy link
Contributor

@y1d7ng y1d7ng commented Jul 12, 2021

Description

fix #4214

Additional context

In the .vue file, changing the lang attribute of the style tag will not cause the preprocessor to be updated. Instead, it will continue to use the previous preprocessor to compile.


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.

Comment on lines +93 to +94
m.url.includes(`type=style&index=${i}`) &&
m.url.endsWith(`.${next.lang || 'css'}`)
Copy link
Member

Choose a reason for hiding this comment

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

question:

"[...] changing the lang attribute of the style tag will not cause the preprocessor to be updated. [...]"

Why should this work? You just shrink the condition from includes to includes + endsWith 🤔
Could you explain what is happening here?

Copy link
Contributor Author

@y1d7ng y1d7ng Jul 12, 2021

Choose a reason for hiding this comment

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

When the lang is changed, the corresponding module will be found through the following line of code, but the url of the module still contains the previous lang. The css plugin will parse the url of this module to select the preprocessor.

const mod = modules.find((m) => m.url.includes(`type=style&index=${i}`))

After adding endsWith, a new module will be generated with the new lang in the url.

Shinigami92
Shinigami92 previously approved these changes Jul 12, 2021
@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jul 12, 2021
@patak-dev
Copy link
Member

@OneNail would it be possible to add a test case for this in the vue playground so we avoid future regressions?

@y1d7ng
Copy link
Contributor Author

y1d7ng commented Jul 13, 2021

@OneNail would it be possible to add a test case for this in the vue playground so we avoid future regressions?

Ok, I will add the test case later.

@y1d7ng
Copy link
Contributor Author

y1d7ng commented Jul 16, 2021

@patak-js @Shinigami92
I have added the test case and found that there was no test for stylus lang before, so I merged them together to test.

@patak-dev patak-dev changed the title fix(plugin-vue): reuse the old preprocessor after changing the lang attr fix: reuse the old preprocessor after changing the lang attr Jul 20, 2021
@patak-dev patak-dev merged commit 7a3c6e6 into vitejs:main Jul 20, 2021
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
…4224)

* fix(plugin-vue): reuse the old preprocessor after changing the lang attr

* feat(playground): add stylus + change lang test in vue

* chore: add eol line break

Co-authored-by: Shinigami <chrissi92@hotmail.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Still use the old preprocessor after changing lang of style tag
3 participants