fix: recover stale editor block references

This commit is contained in:
lucaronin
2026-05-23 16:53:43 +02:00
parent f0fb7b7418
commit 12646d4e98
8 changed files with 157 additions and 18 deletions

View File

@@ -367,6 +367,20 @@ describe('TolariaSideMenu', () => {
})
})
it('hides table header actions when the live block lookup throws after reload churn', () => {
const staleTable = {
id: 'table-block',
type: 'table',
content: { type: 'tableContent', rows: [], headerRows: undefined },
}
mockEditor.getBlock.mockImplementation(() => {
throw staleBlockError(staleTable)
})
expect(() => renderSideMenuWithBlock(staleTable)).not.toThrow()
expect(screen.queryByText('Header row')).not.toBeInTheDocument()
})
it('ignores stale drag starts after reload churn', () => {
renderSideMenuWithBlock(sideMenuBlock)
@@ -386,6 +400,18 @@ describe('TolariaSideMenu', () => {
expect(mockEditor.insertBlocks).toHaveBeenCalledWith([draggedBlock], targetBlock.id, 'before')
})
it('ignores pointer reorders when a target block lookup throws after reload churn', () => {
const { draggedBlock, dragHandle, targetBlock } = renderPointerReorderFixture()
mockEditor.getBlock.mockImplementation((id: string) => {
if (id === targetBlock.id) throw staleBlockError(id)
return id === draggedBlock.id ? draggedBlock : undefined
})
expect(() => dispatchHandlePointerReorder(dragHandle)).not.toThrow()
expect(mockEditor.removeBlocks).not.toHaveBeenCalled()
expect(mockEditor.insertBlocks).not.toHaveBeenCalled()
})
it('shows and clears pointer reorder affordances while dragging', () => {
const { draggedElement, dragHandle } = renderPointerReorderFixture()