Add global wc-fallback script and styles#2422
Merged
anselmbradford merged 1 commit intomainfrom Apr 1, 2026
Merged
Conversation
36cdefc to
a02f559
Compare
itsmedavep
approved these changes
Nov 17, 2025
Collaborator
itsmedavep
left a comment
There was a problem hiding this comment.
Ans and I discussed, the approach makes sense. Reviewed the code and it looks fine to me.Approved.
a02f559 to
4536d2f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the architecture to handle fallback content relatively gracefully. It aims to provide a workflow for addressing the states of: JS disabled, JS enabled + no web component support, JS enabled + web component support. The architecture is as follows:
Given the component
my-custom-btn. It wraps a fallback, and as needed, slotted content:JS disabled
The
<noscript>content is rendered AND the author supplied slotted content is rendered. So it looks like this:To fix this, we can provide CSS that hide everything but the
<noscript>tag, however we can't generically target all web components in CSS:To make this more generic, we could have the author add a
<noscript>tag and, also, if they want to hide other content in the component, add a boolean attributehasfallbackor similar. Then we can make the selector more generic:JS enabled, web components not supported
In this case, we can globally check if web components are supported, and if not, we can load a polyfill, or just let it fall back to the
<noscript>content. However, the problem here is that if JS is enabled, but web components are not supported, then the<noscript>content will not show. So, in this case we need to use JavaScript to turn<noscript>inside the web component into<div class="fallback">or similar. This would now show that content, except non-noscript tags are hidden via the CSS, so we need to add more CSS to show.fallbackclasses:// wc-fallback.js (see files added)JS enabled, web components are supported
If JS is enabled, the
<noscript>content is hidden and it is not swapped with<div class="fallback">and then the web component uses the author-supplied slotted content to render. However, because of the existing CSS that hides everything but thenoscriptcontent, that means everything will be hidden. So in this case, we add another CSS rule:Additions
Testing