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

fix(core): split view reordering crash #9461

Merged
merged 1 commit into from
Dec 31, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { useService } from '@toeverything/infra';
import clsx from 'clsx';
import type { HTMLAttributes, RefObject } from 'react';
import { useCallback, useMemo, useRef, useState } from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { createPortal } from 'react-dom';

import type { View } from '../../entities/view';
Expand Down Expand Up @@ -50,6 +50,10 @@ export const SplitView = ({
const { appSettings } = useAppSettingHelper();
const workbench = useService(WorkbenchService).workbench;

// blocksuite's lit host element has an issue on remounting.
// Add a workaround here to force remounting after dropping.
const [visible, setVisibility] = useState(true);

const sensors = useSensors(
useSensor(
PointerSensor,
Expand Down Expand Up @@ -102,11 +106,25 @@ export const SplitView = ({
const fromIndex = views.findIndex(v => v.id === active.id);
const toIndex = views.findIndex(v => v.id === over?.id);
onMove?.(fromIndex, toIndex);
setVisibility(false);
}
},
[onMove, views]
);

useEffect(() => {
if (!visible) {
const timeoutId = setTimeout(() => {
setVisibility(true);
}, 0);

return () => {
clearTimeout(timeoutId);
};
}
return;
}, [visible]);

return (
<div
ref={rootRef}
Expand All @@ -121,11 +139,13 @@ export const SplitView = ({
onDragEnd={handleDragEnd}
>
<SortableContext items={views} strategy={horizontalListSortingStrategy}>
{views.map((view, index) => (
<SplitViewPanel view={view} key={view.id} setSlots={setSlots}>
{resizeHandleRenderer(view, index)}
</SplitViewPanel>
))}
{views.map((view, index) =>
visible ? (
<SplitViewPanel view={view} key={view.id} setSlots={setSlots}>
{resizeHandleRenderer(view, index)}
</SplitViewPanel>
) : null
)}
</SortableContext>
</DndContext>

Expand Down
Loading