Skip to content

Commit

Permalink
Text Editor: Avoid content loss
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed May 1, 2022
1 parent 6fab3c4 commit cac83e2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/editor/src/components/post-text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Textarea from 'react-autosize-textarea';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';
import { parse } from '@wordpress/blocks';
import { useDispatch, useSelect } from '@wordpress/data';
import { useInstanceId } from '@wordpress/compose';
Expand Down Expand Up @@ -65,6 +65,16 @@ export default function PostTextEditor() {
}
};

// Ensure changes aren't lost when the component unmounts
useEffect( () => {
return () => {
if ( isDirty ) {
const blocks = parse( value );
resetEditorBlocks( blocks );
}
};
}, [ isDirty, value ] );

return (
<>
<VisuallyHidden
Expand Down

0 comments on commit cac83e2

Please sign in to comment.