Skip to content
Open
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions frontend/src/components/Chat/ConverterPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ function makePreviewResponse(
}

describe('ConverterPanel', () => {
it('releases the body cursor and selection lock when the panel unmounts mid drag', () => {
const panel = renderPanel()
fireEvent.mouseDown(screen.getByTestId('converter-panel-resize'))
expect(document.body.style.cursor).toBe('col-resize')
expect(document.body.style.userSelect).toBe('none')

// Unmount while the drag is still held: the mouseup listener is gone with
// the panel, so the cleanup is the only thing that can restore the body.
panel.rerender({ open: false })

expect(document.body.style.cursor).toBe('')
expect(document.body.style.userSelect).toBe('')
})


beforeEach(() => {
jest.clearAllMocks()
mockedConvertersApi.listConverters.mockResolvedValue({ items: [textConverter] })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@ export default function ConverterPanel({
return () => {
document.removeEventListener('mousemove', handleMouseMove)
document.removeEventListener('mouseup', handleMouseUp)
// Unmounting mid drag removes the mouseup listener before it can fire,
// so the body wide cursor and selection lock have to be released here or
// they stick until a full page reload.
if (isResizing.current) {
isResizing.current = false
document.body.style.cursor = ''
document.body.style.userSelect = ''
}
}
}, [])

Expand Down
Loading