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

Replace __OXIDE__ at build time to prevent @tailwindcss/oxide leaks in the stable engine #10988

Merged
merged 8 commits into from
Apr 18, 2023

Conversation

RobinMalfait
Copy link
Contributor

@RobinMalfait RobinMalfait commented Apr 11, 2023

This PR will ensure that the oxide engine doesn't leak in the current stable version.

The oxide engine is currently behind a runtime feature flag:

if (env.OXIDE) {
  require('@tailwindcss/oxide').doSomethingOxideSpecific()
}

But some build tools that use the commonjs plugin (often used in Vite / Rollup) will hoist that require part out of the guard... this typically results in a static import instead. But since the stable engine doesn't have any idea what @tailwindcss/oxide even is, it crashes.

If you would inspect the generated code, then it will look something like this:

import moduleName from '@tailwindcss/oxide'

if (env.OXIDE) {
  moduleName.doSomethingOxideSpecific()
}

... which kind of defeats the whole purpose of the feature flag in the first place. In a project where OXIDE is defined this all works fine, but in other places it won't.

This PR will switch the runtime feature flag, to a build time feature flag. This will ensure that the code is not even there in the final built code but that should be fine since you can switch between the engines if you install a different version (insiders vs oxide-insiders).

We will replace __OXIDE__ at build time. This also means that some parts of the code will now look something like if (false) { require('@tailwindcss/oxide') }. This means that the block will never be reachable, but luckily SWCs optimizer will get rid of the dead code entirely.

@RobinMalfait RobinMalfait force-pushed the fix/oxide-leaks branch 3 times, most recently from 876b6e2 to fea35dc Compare April 12, 2023 13:55
This will allow us to replace the `__OXIDE__` at build time, and fully
remove the branches from the final code so that there is not even any
reference to `@tailwindcss/oxide` on the stable engine.
RobinMalfait and others added 2 commits April 12, 2023 16:14
This is currently a redirect to the same file, so doesn't hurt.
Copy link
Contributor

@thecrypticace thecrypticace left a comment

Choose a reason for hiding this comment

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

LGTM

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.

None yet

2 participants