From a0741de663730de6cd20fdc8b2571db7de18a590 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 5 Apr 2023 12:50:25 -0300 Subject: [PATCH 1/3] Fix react 18 compatibility --- assets/js/blocks/facets/meta/edit.js | 13 ++++++++----- assets/js/blocks/facets/taxonomy/edit.js | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/assets/js/blocks/facets/meta/edit.js b/assets/js/blocks/facets/meta/edit.js index a4f985319f..1f2fa551d6 100644 --- a/assets/js/blocks/facets/meta/edit.js +++ b/assets/js/blocks/facets/meta/edit.js @@ -29,11 +29,14 @@ const FacetBlockEdit = (props) => { const blockProps = useBlockProps(); - const load = useCallback(async () => { - const metaKeys = await apiFetch({ - path: '/elasticpress/v1/facets/meta/keys', - }); - setMetaKeys(metaKeys); + const load = useCallback(() => { + const handle = async () => { + const metaKeys = await apiFetch({ + path: '/elasticpress/v1/facets/meta/keys', + }); + setMetaKeys(metaKeys); + }; + handle(); }, [setMetaKeys]); useEffect(load, [load]); diff --git a/assets/js/blocks/facets/taxonomy/edit.js b/assets/js/blocks/facets/taxonomy/edit.js index 8de489b136..3556d31c8b 100644 --- a/assets/js/blocks/facets/taxonomy/edit.js +++ b/assets/js/blocks/facets/taxonomy/edit.js @@ -20,11 +20,14 @@ const FacetBlockEdit = (props) => { const blockProps = useBlockProps(); - const load = useCallback(async () => { - const taxonomies = await apiFetch({ - path: '/elasticpress/v1/facets/taxonomies', - }); - setTaxonomies(taxonomies); + const load = useCallback(() => { + const handle = async () => { + const taxonomies = await apiFetch({ + path: '/elasticpress/v1/facets/taxonomies', + }); + setTaxonomies(taxonomies); + }; + handle(); }, [setTaxonomies]); useEffect(load, [load]); From 6a7c1372b9fd2411b3fae40c3cc59975054bd86e Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 5 Apr 2023 15:18:57 -0300 Subject: [PATCH 2/3] Check if block inserter is already open before re-opening it --- tests/cypress/support/commands/block-editor.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/cypress/support/commands/block-editor.js b/tests/cypress/support/commands/block-editor.js index 28c163f045..6e61da680c 100644 --- a/tests/cypress/support/commands/block-editor.js +++ b/tests/cypress/support/commands/block-editor.js @@ -11,8 +11,12 @@ Cypress.Commands.add('openBlockSettingsSidebar', () => { }); Cypress.Commands.add('openBlockInserter', () => { - cy.get('body').then(($el) => { - if ($el.hasClass('widgets-php')) { + cy.get('body').then(($body) => { + // If already open, skip. + if ($body.find('.edit-widgets-layout__inserter-panel-content').length > 0) { + return; + } + if ($body.hasClass('widgets-php')) { cy.get('.edit-widgets-header-toolbar__inserter-toggle').click(); } else { cy.get('.edit-post-header-toolbar__inserter-toggle').click(); @@ -25,6 +29,6 @@ Cypress.Commands.add('getBlocksList', () => { }); Cypress.Commands.add('insertBlock', (blockName) => { - cy.get('.block-editor-inserter__search input[type="search"').type(blockName); + cy.get('.block-editor-inserter__search input[type="search"').clearThenType(blockName); cy.get('.block-editor-block-types-list__item').contains(blockName).click(); }); From e6668ecd3799dd041c7c4cac8a548edd6c9cc9e9 Mon Sep 17 00:00:00 2001 From: Felipe Elia Date: Wed, 5 Apr 2023 16:18:40 -0300 Subject: [PATCH 3/3] Force click to avoid the detached element error --- tests/cypress/support/commands/block-editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cypress/support/commands/block-editor.js b/tests/cypress/support/commands/block-editor.js index 6e61da680c..b259b40f1e 100644 --- a/tests/cypress/support/commands/block-editor.js +++ b/tests/cypress/support/commands/block-editor.js @@ -30,5 +30,5 @@ Cypress.Commands.add('getBlocksList', () => { Cypress.Commands.add('insertBlock', (blockName) => { cy.get('.block-editor-inserter__search input[type="search"').clearThenType(blockName); - cy.get('.block-editor-block-types-list__item').contains(blockName).click(); + cy.get('.block-editor-block-types-list__item').contains(blockName).click({ force: true }); });