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

Ensure browser package does not pollute global namespace #15978

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Jan 28, 2025

Resolves #15977

Our @tailwindcss/browser build is intended to run inside a <script> tag inside browsers. Because of how variable assignment within <script> tags work, all variables that were defined within that script are currently assigned on the global namespace.

This is especially troublesome as eslint uses $ as a valid mangling character so importing the CDN build would now redefine globalThis.$ which collides with many very popular JavaScript libraries.

In order to avoid polluting the global namespace, this PR changes the build step to emit an IIFE (so all vars defined are scroped to the function closure instead of the global namespace).

Test plan

  • Ensure UI tests still work
  • Screenshot 2025-01-28 at 16 49 27

@philipp-spiess philipp-spiess merged commit 82ddc24 into next Jan 28, 2025
5 checks passed
@philipp-spiess philipp-spiess deleted the fix/use-iife-for-browser-bundle branch January 28, 2025 15:58
philipp-spiess added a commit that referenced this pull request Jan 28, 2025
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.

[v4] CDN jQuery compatibility
2 participants