mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 09:43:58 +02:00
Fix pointRef leaks caused by not unref'ing (#4939)
* Fix pointRef leaks caused by not unref'ing May cause severe performance degradation if more and more point refs need to be updated. * changeset
This commit is contained in:
5
.changeset/khaki-panthers-burn.md
Normal file
5
.changeset/khaki-panthers-burn.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix pointRef leaks caused by not unref'ing
|
@@ -12,6 +12,7 @@ import {
|
|||||||
Ancestor,
|
Ancestor,
|
||||||
} from '..'
|
} from '..'
|
||||||
import { NodeMatch, PropsCompare, PropsMerge } from '../interfaces/editor'
|
import { NodeMatch, PropsCompare, PropsMerge } from '../interfaces/editor'
|
||||||
|
import { PointRef } from '../interfaces/point-ref'
|
||||||
|
|
||||||
export interface NodeTransforms {
|
export interface NodeTransforms {
|
||||||
insertNodes: <T extends Node>(
|
insertNodes: <T extends Node>(
|
||||||
@@ -728,6 +729,8 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
const beforeRef = Editor.pointRef(editor, at, {
|
const beforeRef = Editor.pointRef(editor, at, {
|
||||||
affinity: 'backward',
|
affinity: 'backward',
|
||||||
})
|
})
|
||||||
|
let afterRef: PointRef | undefined
|
||||||
|
try {
|
||||||
const [highest] = Editor.nodes(editor, { at, match, mode, voids })
|
const [highest] = Editor.nodes(editor, { at, match, mode, voids })
|
||||||
|
|
||||||
if (!highest) {
|
if (!highest) {
|
||||||
@@ -759,7 +762,7 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
always = true
|
always = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const afterRef = Editor.pointRef(editor, at)
|
afterRef = Editor.pointRef(editor, at)
|
||||||
const depth = at.path.length - height
|
const depth = at.path.length - height
|
||||||
const [, highestPath] = highest
|
const [, highestPath] = highest
|
||||||
const lowestPath = at.path.slice(0, depth)
|
const lowestPath = at.path.slice(0, depth)
|
||||||
@@ -801,9 +804,10 @@ export const NodeTransforms: NodeTransforms = {
|
|||||||
const point = afterRef.current || Editor.end(editor, [])
|
const point = afterRef.current || Editor.end(editor, [])
|
||||||
Transforms.select(editor, point)
|
Transforms.select(editor, point)
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
beforeRef.unref()
|
beforeRef.unref()
|
||||||
afterRef.unref()
|
afterRef?.unref()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -214,9 +214,9 @@ export const TextTransforms: TextTransforms = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const point = reverse
|
const startUnref = startRef.unref()
|
||||||
? startRef.unref() || endRef.unref()
|
const endUnref = endRef.unref()
|
||||||
: endRef.unref() || startRef.unref()
|
const point = reverse ? startUnref || endUnref : endUnref || startUnref
|
||||||
|
|
||||||
if (options.at == null && point) {
|
if (options.at == null && point) {
|
||||||
Transforms.select(editor, point)
|
Transforms.select(editor, point)
|
||||||
|
Reference in New Issue
Block a user