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 .tsmb-icon-close to not rely on inline style attribute #3

Merged
merged 1 commit into from
Aug 23, 2024

Conversation

Krinkle
Copy link
Member

@Krinkle Krinkle commented Aug 22, 2024

This makes the web component compatible with a stict CSP setting, without granting style-src unsafe-inline, and without hardcoding a hash of the exact display: none; value.

This has been there since the initial commit. This was factored out of the QUnit website theme originally, and I think I had an idea at some point to make it generated by an HTML template (e.g. Mustache, or something else in Ruby or PHP) where the HTML form should render correctly even without CSS or JS present, so that it is safe to embed in content that may be rendered in e.g. an RSS Feed reader, or Safari Reader mode, without a confusing "x" rendered there when site resources aren't applied. I ended up abandoning this in favour of making it a web component with minimal HTML markup, and instead render anything that only matters to JS, inside JS. This makes it easier to install and upgrade as well.

Anyway, that means we don't need this inline style. We can expect that if a context requested the JS, it also requested the CSS. And we support JS in fewer browsers than the CSS (progressive enhancement, cut the mustard), not the other way around.

Alternatives

I considered the hidden attribute, but this doesn't work for <svg>. And, would have the downside of requiring us to hardcode block which is totally fine for this, but ever so slightly something I'd generally avoid in favour of only encoding how to hide it, since how to show it is already known by default and may vary between different elements.

Ref jquery/infrastructure-puppet#54.
Ref jquery/infrastructure-puppet#57.

This makes the web component compatible with a stict CSP setting,
without granting `style-src unsafe-inline`, and without hardcoding
a hash of the exact `display: none;` value.
Copy link
Member

@timmywil timmywil left a comment

Choose a reason for hiding this comment

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

I'll remove the hash from the CSP

@Krinkle Krinkle merged commit d8572f1 into main Aug 23, 2024
3 checks passed
@Krinkle Krinkle deleted the close-without-unsafe-inline branch August 23, 2024 16:45
Krinkle added a commit that referenced this pull request Aug 24, 2024
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.

2 participants