ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.99k stars 3.25k forks source link

Add [Symbol.dispose] support for ref types #5691

Open yf-yang opened 3 months ago

yf-yang commented 3 months ago

Calling .unref() is just fine, but sometimes it could be forgotten and cause memory leaks.

TC39 stage 3 proposal https://github.com/tc39/proposal-explicit-resource-management is aimed at solving the problem. We can add a [Symbol.dispose]() method to those pathRef, pointRef, rangeRef to keep up with the spec.

The only possible problem here is that we don't know how Symbol.dispose is supported in different js runtimes. I believe latest browsers and node has already supported it, but not sure about previous versions. Can't find the info in CanIUse, either.

work-in-progress-danny commented 1 month ago

Seems related to https://github.com/ianstormtaylor/slate/issues/5726

yf-yang commented 3 weeks ago

Nope, just a standard compatible API