Runaway recursion when trying to access `editor.value` in a plugin `onChange` event
See original GitHub issueDo you want to request a feature or report a bug?
Report a bug
What’s the current behavior?
Get a depth exception when trying to access editor.value
in a plugin onChange
event.
Just try to load this fiddle and it will throw errors: https://jsfiddle.net/uvkrn9ge/1/
Chrome latest Mac OSX.
Note: I did narrow this down to a change in version 4.0.2 of memoize-one
. I think this error may have always been happening, it was just covered up.
Issue Analytics
- State:
- Created 5 years ago
- Comments:25 (25 by maintainers)
Top Results From Across the Web
recursive onchange event not triggered - Stack Overflow
I have this code, I want to make all dropdowns to be updated once I change the first dropdown. But when I used...
Read more >Prevent an onChange Client Script from going into recursion
I have an onChange client script called when a user selects an item for a field using the lookup functionality (here, referring to...
Read more >Understanding common frustrations with React Hooks
React Hooks can be frustrating despite their popularity and widespread use. Learn about some of the drawbacks to using React Hooks.
Read more >TWikiDocumentation < TWiki < TWiki
Try the installed skins at TWikiSkinBrowser and more at TWiki:Plugins. ... number of pages accessed by current user since login, current value: ==....
Read more >OnChange event plugin - The Choice Cards
1.4: 7-September-2012 Don't fire events if the editor is readonly, thanks to Ulrich Gabor. Included code to use Mutation Observers. Installation. 1. Copying...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok this will be reproducible with this fiddle once a new version of slate gets published with memoize-one@4.0.2. https://jsfiddle.net/uvkrn9ge/21/
The loop is:
onChange()
handlers.The reason why this wasn’t a problem before is that in 4.0.2, the behavior of memoize-one changed such that when you recurse in a memoized method, it doesn’t remember what the result is until after the function finishes getting called, which will never happen because the recursion never terminates. So it just keeps seeing the same value and passing the same value check because it was never set. I think this is actually the correct behavior in
memoize-one
as it makes sure that in recursive methods the original arguments are what g memoized.What ends up making this even worse is that if you specify a schema in a plugin, the same schema check will also fail in
before.onChange()
so the change will get an operation added. This means that in the pluginonChange()
you can’t short circuit ifchange.operations.size === 0
. The workaround we had to do was to pinmemoize-one@4.0.2
.I created a simple local slate example based on that fiddle and upgraded to
memoize-one@4.0.2
and it does indeed break as we see in our environment. I can push that if people want to look at it.@ericedem The problem of setState with componentDidUpdate is the performance. Here is a issue about it https://github.com/ianstormtaylor/slate/issues/1938
Using
setState
incomponentDidUpdate
will double the updates, significantly harm the capacity of handling large document with decorations. (Though, in current slate, we still experience a significant delay (0.3s~0.6s) when editing with large document + decoration)