mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
fix: Guard against out-of-range position in scrollToAnchor (#12489)
The MutationObserver callback could throw an uncaught RangeError when posAtDOM returned a position outside the document, since the existing try/catch only wrapped the observer setup, not the async callback. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+12
-6
@@ -572,12 +572,18 @@ export class Editor extends React.PureComponent<
|
||||
this.mutationObserver = observe(
|
||||
hash,
|
||||
(element) => {
|
||||
const pos = this.view.posAtDOM(element, 0, 1);
|
||||
this.view.dispatch(
|
||||
this.view.state.tr.setSelection(
|
||||
TextSelection.near(this.view.state.doc.resolve(pos), 1)
|
||||
)
|
||||
);
|
||||
try {
|
||||
const pos = this.view.posAtDOM(element, 0, 1);
|
||||
if (pos >= 0 && pos <= this.view.state.doc.content.size) {
|
||||
this.view.dispatch(
|
||||
this.view.state.tr.setSelection(
|
||||
TextSelection.near(this.view.state.doc.resolve(pos), 1)
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch (_err) {
|
||||
// posAtDOM may throw if the element is not part of the editor doc
|
||||
}
|
||||
|
||||
if (isVisible(element)) {
|
||||
element.scrollIntoView();
|
||||
|
||||
Reference in New Issue
Block a user