Slate: Chinese IME throws out errors

Created on 14 Oct 2017  Â·  5Comments  Â·  Source: ianstormtaylor/slate

I want to report a bug?

What's the current behavior?

Using Chinese IME on slatejs.org throws out errors

````
Error: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
at removeChild (http://slatejs.org/build.prod.js:4828:7974)
at a (http://slatejs.org/build.prod.js:4825:25233)
at commitDeletion (http://slatejs.org/build.prod.js:4825:26981)
at n (http://slatejs.org/build.prod.js:4825:31488)
at u (http://slatejs.org/build.prod.js:4826:1356)
at c (http://slatejs.org/build.prod.js:4826:1793)
at batchedUpdates (http://slatejs.org/build.prod.js:4826:4655)
at qb (http://slatejs.org/build.prod.js:4825:3879)
at ob (http://slatejs.org/build.prod.js:4825:3813)
at Object.batchedUpdates (http://slatejs.org/build.prod.js:4826:19682)
`````
1

TypeError: Cannot read property 'node' of null at t.n.updateSelection (http://slatejs.org/build.prod.js:5014:4115) at t.n.componentDidUpdate (http://slatejs.org/build.prod.js:5014:3374) at commitLifeCycles (http://slatejs.org/build.prod.js:4825:27709) at n (http://slatejs.org/build.prod.js:4825:31692) at u (http://slatejs.org/build.prod.js:4826:1356) at c (http://slatejs.org/build.prod.js:4826:1793) at batchedUpdates (http://slatejs.org/build.prod.js:4826:4655) at qb (http://slatejs.org/build.prod.js:4825:3879) at ob (http://slatejs.org/build.prod.js:4825:3813) at Object.batchedUpdates (http://slatejs.org/build.prod.js:4826:19682)
2

OS: macOS High Sierra
Browser: Chrome version 61
Slate version: slatejs.org

bug ♥ help ⚑ ime

Most helpful comment

The error is caused by the <br> added by slate https://github.com/ianstormtaylor/slate/blob/master/packages/slate-react/src/components/leaf.js#L130

It looks like some browser would remove <br> after IME complete, so react could not find it and throw error. One solution is use a whitespace instead:

    if (text == '' && parent.kind == 'block' && parent.text == '') return '\u2060'

All 5 comments

This error is only triggered by macOS native pinyin IME, third party pinyin IME (Sougou, Baidu, etc.) does not throw this error, instead they 'eat' characters afterwards.

not just the pinyin IME, all the native Chinese IMEs have the issue.

screen shot 2017-10-14 at 9 35 47 pm

IMEs don't eat characters afterwards anymore, but I can still reproduce the error if I try to type Chinese in an empty new line, like the first gif shows.

OS: macOS High Sierra
Browser: Chrome version 61
Slate version: slatejs.org
Input Method: Pinyin - Simplified / Sougou Pinyin

The error is caused by the <br> added by slate https://github.com/ianstormtaylor/slate/blob/master/packages/slate-react/src/components/leaf.js#L130

It looks like some browser would remove <br> after IME complete, so react could not find it and throw error. One solution is use a whitespace instead:

    if (text == '' && parent.kind == 'block' && parent.text == '') return '\u2060'

@chemzqm Is add that code in the renderText method like this?
image
However, it still crash after inputting Chinese

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlexeiAndreev picture AlexeiAndreev  Â·  3Comments

gorillatron picture gorillatron  Â·  3Comments

markolofsen picture markolofsen  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments

Slapbox picture Slapbox  Â·  3Comments