Skip to content
Merged
Changes from all 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
16 changes: 13 additions & 3 deletions packages/block-editor/src/components/block-list/block-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TextareaAutosize from 'react-autosize-textarea';
/**
* WordPress dependencies
*/
import { useEffect, useState } from '@wordpress/element';
import { useEffect, useMemo, useState } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import {
getBlockAttributes,
Expand All @@ -28,6 +28,16 @@ function BlockHTML( { clientId } ) {
[ clientId ]
);
const { updateBlock } = useDispatch( blockEditorStore );

// Derive block content as a primitive string so the effect only fires
// when the serialized content genuinely changes, not when the block
// object reference changes (which happens on every RESET_BLOCKS during
// RTC sync, even for unchanged blocks).
const blockContent = useMemo(
() => ( block ? getBlockContent( block ) : '' ),
[ block ]
);

const onChange = () => {
const blockType = getBlockType( block.name );

Expand Down Expand Up @@ -64,8 +74,8 @@ function BlockHTML( { clientId } ) {
};

useEffect( () => {
setHtml( getBlockContent( block ) );
}, [ block ] );
setHtml( blockContent );
}, [ blockContent ] );

return (
<TextareaAutosize
Expand Down
Loading