fix(core): some dnd perf issues (#9661)

1. page list item are bound two draggables. adding `draggable` prop to WorkbenchLink to mitigate the issue.
2. DndService may not resolve datatransfer when dragging.
This commit is contained in:
pengx17
2025-01-15 15:04:01 +00:00
parent b1896746f9
commit 0ed9258f51
5 changed files with 89 additions and 73 deletions

View File

@@ -382,7 +382,7 @@ const PageListItemWrapper = forwardRef(
if (to) {
return (
<WorkbenchLink ref={ref} {...commonProps} to={to}>
<WorkbenchLink ref={ref} draggable={false} {...commonProps} to={to}>
{children}
</WorkbenchLink>
);

View File

@@ -81,7 +81,7 @@ export class DndService extends Service {
isDropEvent?: boolean
) => {
if (!isDropEvent) {
return this.resolveBlocksuiteExternalData(args.source) || {};
return {};
}
let resolved: AffineDNDData['draggable'] | null = null;
@@ -168,30 +168,24 @@ export class DndService extends Service {
if (!dndAPI) {
return null;
}
if (source.types.includes(dndAPI.mimeType)) {
const from = {
at: 'blocksuite-editor',
} as const;
let entity: Entity | null = null;
const encoded = source.getStringData(dndAPI.mimeType);
const snapshot = encoded ? dndAPI.decodeSnapshot(encoded) : null;
entity = snapshot ? this.resolveBlockSnapshot(snapshot) : null;
if (!entity) {
return {
from,
};
} else {
return {
entity,
from,
};
}
const encoded = source.getStringData(dndAPI.mimeType);
if (!encoded) {
return null;
}
return null;
const snapshot = dndAPI.decodeSnapshot(encoded);
if (!snapshot) {
return null;
}
const entity = this.resolveBlockSnapshot(snapshot);
if (!entity) {
return null;
}
return {
entity,
from: {
at: 'blocksuite-editor',
},
};
};
private readonly resolveHTML: EntityResolver = html => {

View File

@@ -47,7 +47,10 @@ function resolveToEntity(
}
export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
function WorkbenchLink({ to, onClick, replaceHistory, ...other }, ref) {
function WorkbenchLink(
{ to, onClick, draggable = true, replaceHistory, ...other },
ref
) {
const { workbenchService } = useServices({
WorkbenchService,
});
@@ -79,8 +82,10 @@ export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
to: stringTo,
},
},
canDrag:
typeof draggable === 'boolean' ? draggable : draggable === 'true',
};
}, [to, basename, stringTo]);
}, [to, basename, stringTo, draggable]);
return (
<a