Skip to content

Commit

Permalink
useCompatibilityStyles: clarify how dependencies related to inline st…
Browse files Browse the repository at this point in the history
…yles work (#51199)
  • Loading branch information
oandregal authored Jun 2, 2023
1 parent fb34a98 commit 6626c4a
Showing 1 changed file with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,40 @@ export function useCompatibilityStyles() {
if ( matchFromRules( cssRules ) ) {
const isInline = ownerNode.tagName === 'STYLE';

// Add inline styles belonging to the stylesheet.
const inlineCssId = ownerNode.id.replace(
isInline ? '-inline-css' : '-css',
isInline ? '-css' : '-inline-css'
);
const otherElement = document.getElementById( inlineCssId );

// If the matched stylesheet is inline, add the main
// stylesheet before the inline style element.
if ( otherElement && isInline ) {
accumulator.push( otherElement.cloneNode( true ) );
if ( isInline ) {
// If the current target is inline,
// it could be a dependency of an existing stylesheet.
// Look for that dependency and add it BEFORE the current target.
const mainStylesCssId = ownerNode.id.replace(
'-inline-css',
'-css'
);
const mainStylesElement =
document.getElementById( mainStylesCssId );
if ( mainStylesElement ) {
accumulator.push(
mainStylesElement.cloneNode( true )
);
}
}

accumulator.push( ownerNode.cloneNode( true ) );

if ( otherElement && ! isInline ) {
accumulator.push( otherElement.cloneNode( true ) );
if ( ! isInline ) {
// If the current target is not inline,
// we still look for inline styles that could be relevant for the current target.
// If they exist, add them AFTER the current target.
const inlineStylesCssId = ownerNode.id.replace(
'-css',
'-inline-css'
);
const inlineStylesElement =
document.getElementById( inlineStylesCssId );
if ( inlineStylesElement ) {
accumulator.push(
inlineStylesElement.cloneNode( true )
);
}
}
}

Expand Down

1 comment on commit 6626c4a

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 6626c4a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5158801027
📝 Reported issues:

Please sign in to comment.