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

CSP: Hide wrapper span with class instead of style attribute #581

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/VirtualDom/Styled.elm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module VirtualDom.Styled exposing
, unstyledNode
)

import Css
import Css.Preprocess as Preprocess exposing (Style)
import Css.Preprocess.Resolve as Resolve
import Css.Structure as Structure
Expand Down Expand Up @@ -479,13 +480,18 @@ toKeyedStyleNode maybeNonce allStyles keyedChildNodes =

toStyleNode : Maybe Nonce -> Dict CssTemplate Classname -> VirtualDom.Node msg
toStyleNode maybeNonce styles =
-- wrap the style node in a div to prevent `Dark Reader` from blowin up the dom.
let
styleWrapperClass =
"elm-css-style-wrapper"
in
-- wrap the style node in a span to prevent `Dark Reader` from blowin up the dom.
VirtualDom.node "span"
[ VirtualDom.attribute "style" "display: none;"
, VirtualDom.attribute "class" "elm-css-style-wrapper"
]
[ VirtualDom.attribute "class" styleWrapperClass ]
[ -- this <style> node will be the first child of the requested one
toDeclaration styles
styles
|> toDeclaration
-- add css to hide the wrapper span
|> styleToDeclaration (getCssTemplate [ Css.display Css.none ]) styleWrapperClass
|> VirtualDom.text
|> List.singleton
|> VirtualDom.node "style"
Expand Down