7 points · by PaulHoule · 2y ago · 13 comments
I exported a few hundred notes from Evernote, these have about 300k of CSS and SVG. I am displaying these through a web application that can compose HTML documents at the DOM level, so I can just insert some elements into the <head> and <body>. I am inserting a toolbar into the page that also pops up modal dialogs to let the user annotate text. Right now I am keeping the native CSS but I know there's some risk of namespace collisions between my CSS and their CSS particularly because I am using Bootstrap which uses bog common words for names.
I am facing something similar to work where we have a React application that sometimes gets loaded on our partners web pages so we always have some concern we might break each others CSS.
The pages from Evernote have no JS so I'd imagine in principle I could rewrite names in the style sheet and HTML. My UI is mostly HTMX but the back end has to know what things are called on the front end and there are small amounts of Javascript.
I think of Ted Nelson's ideas of "transclusion" and how it's a bit difficult to cut and paste a piece of one HTML page into another HTML page because of these namespace issues.
What solutions are out there for this sort of problem?
Also, it may be worth looking into why you're writing so much CSS in the first place. I found that 80% of my CSS addressed layout concerns (display: flex; direction: 'column'; margin: var(--space-2);), so using specialised components allowed me to write less coupled components in fewer lines of code. You can either write them yourself, or check out something like https://www.radix-ui.com/themes/docs/overview/layout.
A Shadow DOM could ensure isolation between the two teams, but CSS namespacing is also a concern within a team, so CSS modules will just kill two birds with one stone here.
So they handle the upstream collisions nicely (i.e. the embedded content not affecting the parent site).
But the other side of it is the downstream (i.e. the parent site doing `div { color: black }` which propogates to the embedded content) and it won't handle that nicely.
You can do something like cleanslate does (https://github.com/premasagar/cleanslate) to aggressively unset so the parent sites CSS gets "disarmed". But it is not the smoothest and things like REM unit values still propagate to the embedded content.
We plan to re-assess using iframes. Which we originally steered clear from due to their rather "dated" feel as a technology.
https://developer.mozilla.org/en-US/docs/Web/API/Web_compone...
and I see some CSS pseudo-classes but I don't see anything I can use to suppress the host site's CSS acting on my UI elements -- am I missing something?
https://htmx.org/examples/web-components/
thanks!