Trigger noscript #20061
Replies: 2 comments 4 replies
|
I don't think this would work with the way Tailwind variants work. They generally modify rule selectors, not property values, and since container styles aren't widely implemented yet, using a CSS variable would not work. Instead, you could set some root class name somewhere on error and then tweak @custom-variant noscript {
@media (scripting: none) {
@slot;
}
.script-error & {
@slot;
}
} |
|
I would model this as two activation paths for the same variant:
The CSS variable approach is awkward here because a Tailwind variant needs to change selector generation. A variable can change values, but it cannot make a generated selector start matching by itself. Something like this is closer to how Tailwind variants work: @import "tailwindcss";
@custom-variant noscript {
@media (scripting: none) {
@slot;
}
.script-error & {
@slot;
}
}Then, if your critical script fails: <script
src="/app.js"
onerror="document.documentElement.classList.add('script-error')"
></script>After that, classes using the The caveat is timing. If you need fallback styles before any blocking render happens, the failure class needs to be set very early, ideally from the same script tag that can fail or from a tiny inline bootstrap. If the class is added later, you will still get a brief state where only the normal scripted styles apply. |
Uh oh!
There was an error while loading. Please reload this page.
The noscript selector is useful, but it would also be useful if I could manually activate noscript mode if, e.g., loading JS fails for some reason. In terms of implementation, I think the way to do it is to have
@media (scripting: none)set some CSS variable, and then I could set the same variable in a<script onerror="...">handler as well.All reactions