From 8a0561173c44b07c3804e00e92c2f633318a1976 Mon Sep 17 00:00:00 2001 From: Peter Sorensen Date: Mon, 5 Feb 2024 15:21:53 -0800 Subject: [PATCH 1/4] ensure blocks are present before processing --- assets/js/admin/admin.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/js/admin/admin.js b/assets/js/admin/admin.js index 8d05eef6..d4deccc8 100644 --- a/assets/js/admin/admin.js +++ b/assets/js/admin/admin.js @@ -246,6 +246,10 @@ import {select, subscribe} from '@wordpress/data'; subscribe(() => { if (editorStore.isSavingPost()) { const changes = editorStore.getPostEdits(); + // maske sure we have blocks to process + if (!Array.isArray(changes.blocks) || !changes.blocks.length) { + return; + } for (const changedBlock of changes.blocks) { const blockName = changedBlock?.name ?? ''; const innerBlocks = changedBlock?.innerBlocks ?? []; From 708e9c1c17138d47b0a72b190534d173560aad88 Mon Sep 17 00:00:00 2001 From: Peter Sorensen Date: Mon, 5 Feb 2024 16:43:37 -0800 Subject: [PATCH 2/4] adds tests for optimizer bug --- .wp-env.json | 6 +++++- tests/cypress/e2e/safe-svg.cy.js | 9 +++++++++ .../test-plugin/e2e-test-plugin-optimizer.php | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/cypress/test-plugin/e2e-test-plugin-optimizer.php diff --git a/.wp-env.json b/.wp-env.json index 093a5fb9..699c99cd 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,5 +1,9 @@ { - "plugins": [".", "./tests/cypress/test-plugin"], + "plugins": [ + ".", + "./tests/cypress/test-plugin/e2e-test-plugin.php", + "./tests/cypress/test-plugin/e2e-test-plugin-optimizer.php" + ], "env": { "tests": { "mappings": { diff --git a/tests/cypress/e2e/safe-svg.cy.js b/tests/cypress/e2e/safe-svg.cy.js index 30f0c561..7f95718f 100644 --- a/tests/cypress/e2e/safe-svg.cy.js +++ b/tests/cypress/e2e/safe-svg.cy.js @@ -72,4 +72,13 @@ describe('Safe SVG Tests', () => { cy.get('.media-item .error-div.error').should('exist').contains('has failed to upload'); }); + + + // Test plugin doesn't break the block editor when no blocks are added + it('Plugin should not break the block editor when optimizer enabled', () => { + // Activate Test Plugin + cy.deactivatePlugin('safe-svg-cypress-test-plugin'); + cy.activatePlugin('safe-svg-cypress-optimizer-test-plugin'); + cy.createPost('Hello World'); + }); }); diff --git a/tests/cypress/test-plugin/e2e-test-plugin-optimizer.php b/tests/cypress/test-plugin/e2e-test-plugin-optimizer.php new file mode 100644 index 00000000..7dac07e7 --- /dev/null +++ b/tests/cypress/test-plugin/e2e-test-plugin-optimizer.php @@ -0,0 +1,12 @@ + Date: Tue, 6 Feb 2024 10:27:38 -0700 Subject: [PATCH 3/4] Fix typo --- assets/js/admin/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/admin/admin.js b/assets/js/admin/admin.js index d4deccc8..d6a29e51 100644 --- a/assets/js/admin/admin.js +++ b/assets/js/admin/admin.js @@ -246,7 +246,7 @@ import {select, subscribe} from '@wordpress/data'; subscribe(() => { if (editorStore.isSavingPost()) { const changes = editorStore.getPostEdits(); - // maske sure we have blocks to process + // make sure we have blocks to process if (!Array.isArray(changes.blocks) || !changes.blocks.length) { return; } From 9aeb2366c918ef60e192a8b57bcd68343ce4d1aa Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Tue, 6 Feb 2024 10:46:06 -0700 Subject: [PATCH 4/4] Ensure the new iframed block editor loads properly in tests --- tests/cypress/cypress.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/cypress/cypress.config.js b/tests/cypress/cypress.config.js index bb87f0e1..fc61a5be 100644 --- a/tests/cypress/cypress.config.js +++ b/tests/cypress/cypress.config.js @@ -1,6 +1,7 @@ const { defineConfig } = require('cypress') module.exports = defineConfig({ + chromeWebSecurity: false, fixturesFolder: 'tests/cypress/fixtures', screenshotsFolder: 'tests/cypress/screenshots', videosFolder: 'tests/cypress/videos',