Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: leaf.position is not a function #740

Closed
benbro opened this issue Jun 8, 2016 · 14 comments
Closed

TypeError: leaf.position is not a function #740

benbro opened this issue Jun 8, 2016 · 14 comments

Comments

@benbro
Copy link
Contributor

benbro commented Jun 8, 2016

I saw the following error several times.
I'll try to reproduce it while writing the deltas in the console.

TypeError: leaf.position is not a function
var _leaf$position5 = leaf.position(offset, i !== 0);
quill.js (line 5199, col 36)

Steps for Reproduction

  1. Visit http://beta.quilljs.com/docs/formats/
  2. Try random combinations of font, size, bold and H1 until you get the TypeError

Platforms:
Firefox 47 on Windows 7

Version:
1.0-beta.4

@jhchen
Copy link
Member

jhchen commented Jun 13, 2016

Can you post a stack trace next time you encounter it?

@benbro
Copy link
Contributor Author

benbro commented Jun 14, 2016

I saw the error several times but I'm not able to reproduce it again.
Closing for now.

@benbro benbro closed this as completed Jun 14, 2016
@sachinrekhi
Copy link
Contributor

I just encountered this issue myself in Quill 1.0 Beta 6.

bundle.js:43989 Uncaught TypeError: leaf.position is not a function

This occurs in quill.getBounds()
(more specifically within call to this.selection.getBounds() within quill.getBounds() call.

Pic of exact offending line here:

screen shot 2016-06-21 at 3 48 26 pm

@jhchen
Copy link
Member

jhchen commented Jun 22, 2016

Are you defining custom leaf blots? The line above makes sure leaf is not null so it's something that doesn't implement position, which should be inherited by Parchment's Leaf blot. It could also be that the structure is messed up because scroll.leaf just gets the deepest blot, assuming it is a Leaf which should be a safe assumption.

@sachinrekhi
Copy link
Contributor

Nope, not yet using any custom blots in the current implementation where I encountered this error. Though possible that some of the other issues I filed were root causes for the structure getting messed up.

@sachinrekhi
Copy link
Contributor

sachinrekhi commented Jun 24, 2016

I'm consistently getting this error now. I set a breakpoint and here is what the local variables are. It looks like the leaf object is of type Block.

screen shot 2016-06-23 at 5 17 57 pm

@sachinrekhi
Copy link
Contributor

sachinrekhi commented Jun 24, 2016

For my case, a workaround that seems to be working is calling quill.update() explicitly before calling quill.getBounds()

My guess at maybe what is going on is that quill is in the middle of creating the new dom nodes for a updateContents() call made just before, and then getBounds() is being call in the middle of it, resulting in it picking up a non-leaf node via scroll.leaf.

@jhchen
Copy link
Member

jhchen commented Jun 27, 2016

This is probably fixed with 3b2167f but without reproduction steps I can't be certain. The symptoms look the same though.

@sachinrekhi
Copy link
Contributor

Yup, looks like that did the trick! Thanks

@Poizd
Copy link

Poizd commented Oct 8, 2018

Reproducible
Quill Editor v1.3.6

Platforms:
Windows 10,
GCH Version 69.0.3497.100
FF 62.0.3
IE11, EDGE

Link where tested
https://quilljs.com/playground/#autosave

Steps

  1. Add any link f.e
    http://en.wikipedia.org/wiki/One_Ring
  2. Set Mouse pointer to the end of link, right after ..._Ring
  3. Select any btn with styling (f.e. underscore text, or other color)
  4. Click somewhere on link text http://en.wikipedia.org/wiki/One_Ring

WB: Uncaught TypeError: leaf.position is not a function
var _leaf$position3 = leaf.position(offset, true);
image

@itspauloroberto
Copy link

I did make sure that i am using 3b2167f on my repository and the bug still occurs.

I have a consistent way to reproduce this error:

  1. Click the editor to get the focus.
  2. Type "A".
  3. Hit [Enter] to create a new line.
  4. Hold [Shift] and click [Arrow Left] on keyboard.
  5. Boom!

@prodrammer
Copy link

I also experience a similar error, "leaf.position is not a function". Interestingly, it also involves an arrow keypress, but in my case, it's the down arrow. I'm not sure why in some cases leaf.position is not a function. If someone from the quill team would like to reach out to me, I'd be happy to set up a live demo to see if we can narrow it down.

I've addressed this in a hack that seems to work for me here: https://github.com/1010data/quill/commit/03f3b6f73840425f0cf61f4983ca3b0ef9b69383

Note that this is based off the 1.3.6 branch. If someone with this issue wants to test, you can use the "quill-leaf-fix" npm package. Note that you'll have to change your quill import/require statements to use 'quill-leaf-fix' instead, or figure out some other clever approach.

@divyanalluri
Copy link

divyanalluri commented May 21, 2020

Is this commit 3b2167f merged to the latest version ..

is this the solution for this error also:
Array.forEach() error c.position is not a function in quill/dist/quill.js in rangeToNative

@quill-bot
Copy link

Quill 2.0 has been released (announcement post) with many changes and fixes. If this is still an issue please create a new issue after reviewing our updated Contributing guide 🙏

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

No branches or pull requests

8 participants