Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

0.10.2 fails on a test: global.getSelection().anchorNode undefined #1399

Closed
tleunen opened this issue Sep 21, 2017 · 7 comments
Closed

0.10.2 fails on a test: global.getSelection().anchorNode undefined #1399

tleunen opened this issue Sep 21, 2017 · 7 comments
Assignees

Comments

@tleunen
Copy link
Contributor

tleunen commented Sep 21, 2017

A test with these 3 lines with an error. Removing the last line make it to succeed.
It uses enzyme.

wrapper.find('.public-DraftEditor-content').simulate('beforeInput', { data: '@' });
wrapper.find('.public-DraftEditor-content').simulate('keydown', { which: KEY_ESC });
wrapper.find('.public-DraftEditor-content').simulate('beforeInput', { data: 't' });

So it seems this line anchorNode is undefined, not null.
https://github.com/facebook/draft-js/blob/master/src/component/handlers/edit/editOnBeforeInput.js#L159

TypeError: Cannot read property 'nodeType' of undefined
      
      at editOnBeforeInput (node_modules/draft-js/lib/editOnBeforeInput.js:112:74)
      at node_modules/draft-js/lib/DraftEditor.react.js:146:19
      at Object.invokeGuardedCallback [as invokeGuardedCallbackWithCatch] (node_modules/react-dom/lib/ReactErrorUtils.js:26:5)
      at executeDispatch (node_modules/react-dom/lib/EventPluginUtils.js:83:21)
      at Object.executeDispatchesInOrder (node_modules/react-dom/lib/EventPluginUtils.js:108:5)
      at executeDispatchesAndRelease (node_modules/react-dom/lib/EventPluginHub.js:43:22)
      at executeDispatchesAndReleaseSimulated (node_modules/react-dom/lib/EventPluginHub.js:51:10)
      at forEachAccumulated (node_modules/react-dom/lib/forEachAccumulated.js:26:8)
      at Object.processEventQueue (node_modules/react-dom/lib/EventPluginHub.js:252:7)
      at node_modules/react-dom/lib/ReactTestUtils.js:351:22
      at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-dom/lib/Transaction.js:143:20)
      at Object.batchedUpdates (node_modules/react-dom/lib/ReactDefaultBatchingStrategy.js:62:26)
      at Object.batchedUpdates (node_modules/react-dom/lib/ReactUpdates.js:97:27)
      at node_modules/react-dom/lib/ReactTestUtils.js:349:18
      at ReactWrapper.<anonymous> (node_modules/enzyme/build/ReactWrapper.js:776:11)
      at ReactWrapper.single (node_modules/enzyme/build/ReactWrapper.js:1421:25)
      at ReactWrapper.simulate (node_modules/enzyme/build/ReactWrapper.js:769:14)
@flarnie
Copy link
Contributor

flarnie commented Sep 22, 2017

Hi @tleunen - can you give me more context for this?

At Facebook, we don't usually use Enzyme to simulate events on Draft, so I'm not sure this is something we expect to work. Seeing the whole test would be useful, or knowing why you are writing this test.

Thanks!

@flarnie flarnie self-assigned this Sep 22, 2017
@tleunen
Copy link
Contributor Author

tleunen commented Sep 22, 2017

There's not much more info to be honest. The test is actually testing something outside of draft, but I need to input data there to make sure the rest behaves properly.

The test is something like:

  • Press a letter, see that a suggestion box renders, like a mentions box.
  • Press escape, see the suggestion disappears
  • Press a new letter, see the suggestions is not rendered again

It worked properly with 0.10.1.. Is the new condition on the nodeType too strict? Because the reason is really that the anchor is undefined, not null.

@flarnie
Copy link
Contributor

flarnie commented Sep 24, 2017

Ah - I was focused on the test format itself, but I see now the main issue is that the check we added for null isn't catching the undefined value. That's what you meant by

anchorNode is undefined, not null.

I think it would be reasonable to change the line from

 nativeSelection.anchorNode !== null &&

to

// intentionally check for `null` and `undefined`
nativeSelection.anchorNode != null &&

Would you like to submit a PR?

tleunen added a commit to tleunen/draft-js that referenced this issue Sep 25, 2017
Fixes facebookarchive#1399

`nativeSelection.anchorNode` can be undefined instead of null, so I'm changing the condition to handle this use case.
@flarnie
Copy link
Contributor

flarnie commented Oct 5, 2017

I expect to get this out in a minor release in the next couple of weeks.

@tleunen
Copy link
Contributor Author

tleunen commented Oct 5, 2017

Np. Thank you @flarnie

@eldh
Copy link

eldh commented Dec 21, 2017

I'm still seeing this (or a very similar error) in v0.10.4, coming from editOnInput. I'll make a PR cause I don't know if my fix is nice or not.

@icd2k3
Copy link

icd2k3 commented Apr 23, 2018

I'm running into the same error as @eldh periodically. Still hunting for a solid repro case...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants