Skip to content

Commit ffb1f0d

Browse files
authored
refactor(superdoc): optional-chain two callable-optional sites (SD-2867 phase B) (#3068)
* refactor(superdoc): type three implicit-any locals (SD-2867 phase B) * refactor(superdoc): type four implicit-any params (SD-2867 phase B) * refactor(superdoc): cast doc.ydoc in setLocked (SD-2867 phase B) * refactor(superdoc): drop redundant === false checks (SD-2867 phase B) * refactor(superdoc): optional-chain two callable-optional sites (SD-2867 phase B) * fix(superdoc): soften onContentError optional-chain comment (SD-2867 phase B)
1 parent c3a155e commit ffb1f0d

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

packages/superdoc/src/core/SuperDoc.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,13 @@ export class SuperDoc extends EventEmitter {
10151015
onContentError({ error, editor }) {
10161016
const { documentId } = editor.options;
10171017
const doc = this.superdocStore.documents.find((d) => d.id === documentId);
1018-
this.config.onContentError({ error, editor, documentId: doc.id, file: doc.data });
1018+
// `onContentError` is typed as optional on the public Config typedef
1019+
// because consumers don't have to wire a handler. The class field
1020+
// initializer installs a `() => null` default, but `#init` spreads
1021+
// the consumer-supplied config over it (`{ ...this.config, ...config }`),
1022+
// so an explicit `onContentError: undefined` can still strip the
1023+
// default. The optional chain keeps the call safe in that case.
1024+
this.config.onContentError?.({ error, editor, documentId: doc.id, file: doc.data });
10191025
}
10201026

10211027
/**
@@ -1855,7 +1861,11 @@ export class SuperDoc extends EventEmitter {
18551861
*/
18561862
setHighContrastMode(isHighContrast) {
18571863
if (!this.activeEditor) return;
1858-
this.activeEditor.setHighContrastMode(isHighContrast);
1864+
// `setHighContrastMode` is typed as optional on Editor because the
1865+
// method is only present once the editor's mount hooks run. By the
1866+
// time this entry point is reachable the editor is fully constructed
1867+
// and the method is installed, so the optional chain is a no-op.
1868+
this.activeEditor.setHighContrastMode?.(isHighContrast);
18591869
this.highContrastModeStore.setHighContrastMode(isHighContrast);
18601870
}
18611871
}

0 commit comments

Comments
 (0)