Skip to content

Commit a7ab8a1

Browse files
committed
fix(docs): ignore non-doc embed drawings
1 parent 57ee89d commit a7ab8a1

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

packages/docs-drawing-ui/src/controllers/__tests__/doc-float-dom.controller.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function createScene() {
4040

4141
function createController(options: {
4242
drawing?: Record<string, unknown>;
43+
hasDocumentUnit?: boolean;
4344
rects?: Rect[];
4445
page?: any;
4546
refreshDrawingOnAdd?: { left: number; top: number; width: number; height: number; angle: number };
@@ -115,7 +116,7 @@ function createController(options: {
115116
};
116117
const doc = { getUnitId: () => 'doc-1' };
117118
const univerInstanceService = {
118-
getUnit: vi.fn(() => doc),
119+
getUnit: vi.fn(() => options.hasDocumentUnit === false ? null : doc),
119120
getCurrentUnitOfType: vi.fn(() => doc),
120121
getCurrentTypeOfUnit$: vi.fn(() => new BehaviorSubject(null)),
121122
};
@@ -308,6 +309,23 @@ describe('DocFloatDomController', () => {
308309
controller.dispose();
309310
});
310311

312+
it('ignores embed drawing events owned by non-document hosts', () => {
313+
const { controller, add$, renderUnit, drawingRenderService, refreshDrawings } = createController({
314+
drawing: {
315+
data: { version: 1, embedId: 'embed-1', hostAnchorId: 'anchor-1' },
316+
},
317+
hasDocumentUnit: false,
318+
});
319+
320+
add$.next([{ unitId: 'sheet-1', subUnitId: 'sheet-1', drawingId: 'dom-1' }]);
321+
322+
expect(renderUnit.with).not.toHaveBeenCalled();
323+
expect(drawingRenderService.renderFloatDom).not.toHaveBeenCalled();
324+
expect(refreshDrawings).not.toHaveBeenCalled();
325+
326+
controller.dispose();
327+
});
328+
311329
it('waits for layout runtime geometry before mounting an embed custom block', () => {
312330
const rect = new Rect('dom-rect', {
313331
left: 10,

packages/docs-drawing-ui/src/controllers/doc-float-dom.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ export class DocFloatDomController extends Disposable {
217217
const ready: IDrawingSearch[] = [];
218218
const refreshUnitIds = new Set<string>();
219219
for (const param of params) {
220+
const documentDataModel = this._univerInstanceService.getUnit(
221+
param.unitId,
222+
UniverInstanceType.UNIVER_DOC
223+
);
224+
if (documentDataModel == null) {
225+
continue;
226+
}
227+
220228
const drawing = this._drawingManagerService.getDrawingByParam(param);
221229
if (isEmbedFloatDomRuntimeParam(drawing)) {
222230
this._pendingRuntimeGeometryInsert.set(param.drawingId, param);

0 commit comments

Comments
 (0)