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

High priority fixes for 6.3.1 #53709

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 7 additions & 8 deletions packages/block-library/src/footnotes/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function render_block_core_footnotes( $attributes, $content, $block ) {

$footnotes = json_decode( $footnotes, true );

if ( count( $footnotes ) === 0 ) {
if ( ! is_array( $footnotes ) || count( $footnotes ) === 0 ) {
return '';
}

Expand Down Expand Up @@ -98,7 +98,7 @@ function wp_save_footnotes_meta( $revision_id ) {

if ( $footnotes ) {
// Can't use update_post_meta() because it doesn't allow revisions.
update_metadata( 'post', $revision_id, 'footnotes', $footnotes );
update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) );
}
}
}
Expand Down Expand Up @@ -154,15 +154,14 @@ function wp_add_footnotes_revisions_to_post_meta( $post ) {

if ( $footnotes ) {
// Can't use update_post_meta() because it doesn't allow revisions.
update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', $footnotes );
update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash( $footnotes ) );
}
}
}
}

foreach ( array( 'post', 'page' ) as $post_type ) {
add_action( "rest_after_insert_{$post_type}", 'wp_add_footnotes_revisions_to_post_meta' );
}
add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' );
add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' );

/**
* Restores the footnotes meta value from the revision.
Expand All @@ -176,7 +175,7 @@ function wp_restore_footnotes_from_revision( $post_id, $revision_id ) {
$footnotes = get_post_meta( $revision_id, 'footnotes', true );

if ( $footnotes ) {
update_post_meta( $post_id, 'footnotes', $footnotes );
update_post_meta( $post_id, 'footnotes', wp_slash( $footnotes ) );
} else {
delete_post_meta( $post_id, 'footnotes' );
}
Expand Down Expand Up @@ -243,7 +242,7 @@ function _wp_rest_api_autosave_meta( $autosave ) {
return;
}

update_post_meta( $id, 'footnotes', $body['meta']['footnotes'] );
update_post_meta( $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) );
}
// See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1.
add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' );
Expand Down
9 changes: 9 additions & 0 deletions packages/core-data/src/entity-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ export function useEntityBlockEditor( kind, name, { id: _id } = {} ) {
);

function updateAttributes( attributes ) {
// Only attempt to update attributes, if attributes is an object.
if (
! attributes ||
Array.isArray( attributes ) ||
typeof attributes !== 'object'
) {
return attributes;
}

attributes = { ...attributes };

for ( const key in attributes ) {
Expand Down
94 changes: 54 additions & 40 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
InterfaceSkeleton,
store as interfaceStore,
} from '@wordpress/interface';
import { useState, useEffect, useCallback } from '@wordpress/element';
import { useState, useEffect, useCallback, useMemo } from '@wordpress/element';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { store as noticesStore } from '@wordpress/notices';

Expand Down Expand Up @@ -70,6 +70,57 @@ const interfaceLabels = {
footer: __( 'Editor footer' ),
};

function useEditorStyles() {
const { hasThemeStyleSupport, editorSettings } = useSelect(
( select ) => ( {
hasThemeStyleSupport:
select( editPostStore ).isFeatureActive( 'themeStyles' ),
editorSettings: select( editorStore ).getEditorSettings(),
} ),
[]
);

// Compute the default styles.
return useMemo( () => {
const presetStyles =
editorSettings.styles?.filter(
( style ) =>
style.__unstableType && style.__unstableType !== 'theme'
) ?? [];

const defaultEditorStyles = [
...editorSettings.defaultEditorStyles,
...presetStyles,
];

// Has theme styles if the theme supports them and if some styles were not preset styles (in which case they're theme styles).
const hasThemeStyles =
hasThemeStyleSupport &&
presetStyles.length !== ( editorSettings.styles?.length ?? 0 );

// If theme styles are not present or displayed, ensure that
// base layout styles are still present in the editor.
if ( ! editorSettings.disableLayoutStyles && ! hasThemeStyles ) {
defaultEditorStyles.push( {
css: getLayoutStyles( {
style: {},
selector: 'body',
hasBlockGapSupport: false,
hasFallbackGapSupport: true,
fallbackGapValue: '0.5em',
} ),
} );
}

return hasThemeStyles ? editorSettings.styles : defaultEditorStyles;
}, [
editorSettings.defaultEditorStyles,
editorSettings.disableLayoutStyles,
editorSettings.styles,
hasThemeStyleSupport,
] );
}

function Layout() {
const isMobileViewport = useViewportMatch( 'medium', '<' );
const isHugeViewport = useViewportMatch( 'huge', '>=' );
Expand All @@ -94,45 +145,10 @@ function Layout() {
showBlockBreadcrumbs,
isTemplateMode,
documentLabel,
styles,
} = useSelect( ( select ) => {
const { getEditorSettings, getPostTypeLabel } = select( editorStore );
const { isFeatureActive } = select( editPostStore );
const editorSettings = getEditorSettings();
const postTypeLabel = getPostTypeLabel();
const hasThemeStyles = isFeatureActive( 'themeStyles' );

const themeStyles = [];
const presetStyles = [];
editorSettings.styles?.forEach( ( style ) => {
if ( ! style.__unstableType || style.__unstableType === 'theme' ) {
themeStyles.push( style );
} else {
presetStyles.push( style );
}
} );

const defaultEditorStyles = [
...editorSettings.defaultEditorStyles,
...presetStyles,
];

// If theme styles are not present or displayed, ensure that
// base layout styles are still present in the editor.
if (
! editorSettings.disableLayoutStyles &&
! ( hasThemeStyles && themeStyles.length )
) {
defaultEditorStyles.push( {
css: getLayoutStyles( {
style: {},
selector: 'body',
hasBlockGapSupport: false,
hasFallbackGapSupport: true,
fallbackGapValue: '0.5em',
} ),
} );
}

return {
isTemplateMode: select( editPostStore ).isEditingTemplate(),
Expand Down Expand Up @@ -165,13 +181,11 @@ function Layout() {
),
// translators: Default label for the Document in the Block Breadcrumb.
documentLabel: postTypeLabel || _x( 'Document', 'noun' ),
styles:
hasThemeStyles && themeStyles.length
? editorSettings.styles
: defaultEditorStyles,
};
}, [] );

const styles = useEditorStyles();

const openSidebarPanel = () =>
openGeneralSidebar(
hasBlockSelected ? 'edit-post/block' : 'edit-post/document'
Expand Down
34 changes: 28 additions & 6 deletions test/e2e/specs/editor/various/footnotes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@
await editor.clickBlockToolbarButton( 'More' );
await page.locator( 'button:text("Footnote")' ).click();

await page.keyboard.type( 'first footnote' );
// Check if content is correctly slashed on save and restore.
await page.keyboard.type( 'first footnote"' );

const id1 = await editor.canvas.evaluate( () => {
return document.activeElement.id;
Expand All @@ -316,7 +317,7 @@
id: id2,
},
{
content: 'first footnote',
content: 'first footnote"',
id: id1,
},
] );
Expand All @@ -329,7 +330,7 @@
// This also saves the post!
expect( await getFootnotes( page ) ).toMatchObject( [
{
content: 'first footnote',
content: 'first footnote"',
id: id1,
},
{
Expand All @@ -338,12 +339,22 @@
},
] );

const editorPage = page;
const previewPage = await editor.openPreviewPage();

await expect(
previewPage.locator( 'ol.wp-block-footnotes' )
).toHaveText( 'first footnote” ↩︎second footnote ↩︎' );

await previewPage.close();
await editorPage.bringToFront();

// Open revisions.
await editor.openDocumentSettingsSidebar();
await page
.getByRole( 'region', { name: 'Editor settings' } )
.getByRole( 'button', { name: 'Post' } )
.click();

Check failure on line 357 in test/e2e/specs/editor/various/footnotes.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 2

[chromium] › editor/various/footnotes.spec.js:284:2 › Footnotes › works with revisions

1) [chromium] › editor/various/footnotes.spec.js:284:2 › Footnotes › works with revisions ──────── TimeoutError: locator.click: Timeout 10000ms exceeded. =========================== logs =========================== waiting for getByRole('region', { name: 'Editor settings' }).getByRole('button', { name: 'Post' }) locator resolved to <button type="button" aria-label="Post" data-label="Post…>Post</button> attempting click action waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #1 waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #2 waiting 20ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #3 waiting 100ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #4 waiting 100ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #5 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #6 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #7 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #8 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #9 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #10 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable s

Check failure on line 357 in test/e2e/specs/editor/various/footnotes.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 2

[chromium] › editor/various/footnotes.spec.js:284:2 › Footnotes › works with revisions

1) [chromium] › editor/various/footnotes.spec.js:284:2 › Footnotes › works with revisions ──────── Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.click: Timeout 10000ms exceeded. =========================== logs =========================== waiting for getByRole('region', { name: 'Editor settings' }).getByRole('button', { name: 'Post' }) locator resolved to <button type="button" aria-label="Post" data-label="Post…>Post</button> attempting click action waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #1 waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #2 waiting 20ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #3 waiting 100ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #4 waiting 100ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #5 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #6 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #7 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #8 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #9 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #10 waiting 500ms wait

Check failure on line 357 in test/e2e/specs/editor/various/footnotes.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 2

[chromium] › editor/various/footnotes.spec.js:284:2 › Footnotes › works with revisions

1) [chromium] › editor/various/footnotes.spec.js:284:2 › Footnotes › works with revisions ──────── Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.click: Timeout 10000ms exceeded. =========================== logs =========================== waiting for getByRole('region', { name: 'Editor settings' }).getByRole('button', { name: 'Post' }) locator resolved to <button type="button" aria-label="Post" data-label="Post…>Post</button> attempting click action waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #1 waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #2 waiting 20ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #3 waiting 100ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #4 waiting 100ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #5 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #6 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #7 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #8 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #9 waiting 500ms waiting for element to be visible, enabled and stable element is visible, enabled and stable scrolling into view if needed done scrolling <span class="components-menu-item__item">Desktop</span> from <div class="popover-slot">…</div> subtree intercepts pointer events retrying click action, attempt #10 waiting 500ms wait
await page.locator( 'a:text("2 Revisions")' ).click();
await page.locator( '.revisions-controls .ui-slider-handle' ).focus();
await page.keyboard.press( 'ArrowLeft' );
Expand All @@ -355,10 +366,19 @@
id: id2,
},
{
content: 'first footnote',
content: 'first footnote"',
id: id1,
},
] );

const previewPage2 = await editor.openPreviewPage();

await expect(
previewPage2.locator( 'ol.wp-block-footnotes' )
).toHaveText( 'second footnote ↩︎first footnote” ↩︎' );

await previewPage2.close();
await editorPage.bringToFront();
} );

test( 'can be previewed when published', async ( { editor, page } ) => {
Expand Down Expand Up @@ -392,12 +412,14 @@
// path).
await editor.canvas.click( 'ol.wp-block-footnotes li span' );
await page.keyboard.press( 'End' );
await page.keyboard.type( '3' );
// Test slashing.
await page.keyboard.type( '3"' );

const previewPage2 = await editor.openPreviewPage();

// Note: quote will get curled by wptexturize.
await expect(
previewPage2.locator( 'ol.wp-block-footnotes li' )
).toHaveText( '123 ↩︎' );
).toHaveText( '123 ↩︎' );
} );
} );
Loading