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 page not loading scripts when using tailwind #4378

Closed
wants to merge 2 commits into from

Conversation

kagankan
Copy link
Sponsor Contributor

Changes

Fix #4217 .

When using tailwindcss, Vite adds files specified by content option in tailwind.config.js to the deps after compiling CSS.
Then, moduleInfo (meta) of these files are cleared.
We need to re-transform the file before getting moduleInfo.

Please tell me if my understanding is not correct!

Testing

Add a test in tailwindcss.test.js

Docs

None.

@changeset-bot
Copy link

changeset-bot bot commented Aug 18, 2022

🦋 Changeset detected

Latest commit: be18043

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
astro Patch
@e2e/astro-component Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/solid-recurse Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 18, 2022
@bluwy
Copy link
Member

bluwy commented Aug 19, 2022

Testing this locally, looks like it only works after HMR on index.astro. The initial load doesn't seems to work for me (Also strange that CI passes). I'm trying to dig out whether this is a bug in Vite or Astro, and I'm quite fumbled so far. Will check this again later.

Btw thanks for digging into this too!

@kagankan
Copy link
Sponsor Contributor Author

Thank you for checking.

Testing this locally, looks like it only works after HMR on index.astro.

🤔

I tested locally on my Windows, it worked correctly even the initial load.
Is there any other problem depends on OS...? 🤷

@bluwy
Copy link
Member

bluwy commented Aug 19, 2022

It might be an OS issue, I'm using macos. I also just submitted a fix in Vite instead which worked for me locally too 😅 vitejs/vite#9759

You were right that after loading tailwind, where it has to add all deps via ensureEntryFromUrl via it's contents field, the URL being passed resolves to the same existing id for src/pages/index.astro, which accidentally overrides it, removing the meta. The PR should prevent that from happening. Would be glad if you can check that PR too!

@kagankan
Copy link
Sponsor Contributor Author

I didn't know much about inside Vite, I recognized this behavior as Vite's default! Sorry.

Thank you for sending the PR to Vite.
I hope your fix solve this problem 🙏

@kagankan
Copy link
Sponsor Contributor Author

I tested your change on my Windows locally, it worked!
It seems the true bug to fix.

@bluwy
Copy link
Member

bluwy commented Aug 20, 2022

No need to apologize! Thank you for investigating this first and reporting your findings. It helped me to have a head start regarding the root cause. Also looks like the Vite PR is merged, it'll be released in the next Vite 3.1 beta.

I think we can close this for now until we update Vite. Thanks again for checking and testing this!

@bluwy bluwy closed this Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script file isn't loaded on start astro dev when using tailwindcss
2 participants