Skip to content

Commit 7aadfe6

Browse files
authored
Prevent editor crash when updating styles in Site Desing component (#2631)
* Fix CoBlocks/Go Design Style conflict * Refactor to remove iframe injection * Update RC tests to 6.8-RC4
1 parent d54db44 commit 7aadfe6

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

.github/workflows/test-wp-next.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
outputs:
2525
# Should be current latest WP Next release on `wordpress.org`. eg: `https://wordpress.org/wordpress-6.5-beta2.zip`
26-
wp_next: "https://wordpress.org/wordpress-6.5-RC4.zip"
26+
wp_next: "https://wordpress.org/wordpress-6.8-RC2.zip"
2727
steps:
2828
- run: echo "Setting WP Next Constant"
2929

@@ -35,7 +35,7 @@ jobs:
3535
uses: ./.github/workflows/test-e2e-cypress.yml
3636
with:
3737
wpVersion: ${{ needs.set_constant.outputs.wp_next }}
38-
installPath: "tests-wordpress-6.5-RC4"
38+
installPath: "tests-wordpress-6.8-RC2"
3939
theme: "https://downloads.wordpress.org/theme/go.zip"
4040
concurrency:
4141
group: chrome-wp-next

src/extensions/site-design/color-palette-preview.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export function ColorPalettePreviews() {
4545
updateColors();
4646

4747
Object.entries( currentColors ).forEach( ( [ name, color ] ) => {
48-
document.getElementsByClassName( siteDesign.editorClass )[ 0 ].style.setProperty( `--go--color--${ name }`, color );
48+
const editor = document.getElementsByClassName( siteDesign.editorClass )[ 0 ];
49+
if ( editor ) {
50+
document.getElementsByClassName( siteDesign.editorClass )[ 0 ].style.setProperty( `--go--color--${ name }`, color );
51+
}
4952
} );
5053
}, [ currentColors ] );
5154

src/extensions/site-design/component.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export function SiteDesignStyles() {
6363

6464
const stylesElement = document.getElementById( 'site-design-styles' );
6565

66+
if ( ! stylesElement ) {
67+
return;
68+
}
69+
6670
fontStylesCache = !! fontStylesCache ? fontStylesCache : designResp.fontStyles;
6771

6872
// Set the style element innerHTML to remove the old design style.

src/extensions/site-design/hooks/useFontSize.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ function useFontSize() {
1616
if ( ! baseFontSize ) {
1717
return;
1818
}
19-
document.getElementsByClassName( siteDesign.editorClass )[ 0 ].style.setProperty( '--go--font-size', `${ baseFontSize }rem` );
19+
const editor = document.getElementsByClassName( siteDesign.editorClass )[ 0 ];
20+
if ( editor ) {
21+
editor.style.setProperty( '--go--font-size', `${ baseFontSize }rem` );
22+
}
2023
}, [ baseFontSize ] );
2124

2225
return [ baseFontSize, designFontSize ];

src/extensions/site-design/hooks/useTypeRatio.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ function useTypeRatio() {
1414
if ( ! typeRatio ) {
1515
return;
1616
}
17-
document.getElementsByClassName( siteDesign.editorClass )[ 0 ].style.setProperty( '--go--type-ratio', typeRatio );
17+
const editor = document.getElementsByClassName( siteDesign.editorClass )[ 0 ];
18+
if ( editor ) {
19+
editor.style.setProperty( '--go--type-ratio', typeRatio );
20+
}
1821
}, [ typeRatio ] );
1922

2023
return [ typeRatio, designTypeRatio ];

0 commit comments

Comments
 (0)