typewriter-editor / typewriter

A rich text editor based off of Quill.js and Ultradom, and using Svelte for UI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Circular Dependency

JimFung opened this issue · comments

Hi there 👋

Using this with Rollup warns of a handful of circular dependencies. From my terminal:

(!) Circular dependencies
node_modules/typewriter-editor/lib/delta/Op.js -> node_modules/typewriter-editor/lib/delta/Iterator.js -> node_modules/typewriter-editor/lib/delta/Op.js
node_modules/typewriter-editor/lib/doc/Line.js -> node_modules/typewriter-editor/lib/doc/Iterator.js -> node_modules/typewriter-editor/lib/doc/Line.js
...and 3 more

Not sure if its related but I can't seem to delete the text that I type into the editor.

EDIT: forgot to check the js console 🤦 There is an error stack produced when I try to backspace, it seems possibly related to the circular dependency (I guess I don't really understand Rollup's behaviour wrt circular dependencies) or I'm not creating the editor properly. but it seems like its calling onBackspace and further down stream it's calling Iterator.peekLength and it can't because the iterator is undefined (looking at the source, seems like this is Op.length, which would be undefined if rollup doesn't import anything that is circular, or at least that is my hypothesis).

Iterator.js:65 Uncaught TypeError: Cannot read property 'length' of undefined
    at Iterator.peekLength (Iterator.js:65)
    at Iterator.hasNext (Iterator.js:14)
    at Delta.transformPosition (Delta.js:389)
    at TextDocument.apply (TextDocument.js:149)
    at Editor.update (Editor.js:134)
    at changeFormat (Editor.js:358)
    at Editor.formatLine (Editor.js:278)
    at unindent (keyboard.js:98)
    at onBackspace (keyboard.js:69)
    at HTMLDivElement.onKeyDown (keyboard.js:164)

Hi,

I had the exactly same issue. My work-around was to use web-pack instead of rollup. You can do this by creating the svelte app using this command:

npx degit sveltejs/template-webpack my-svelte-app

Now typewriter-editor is working as a charm. No warning about Circular Dependencies during build and no missing length property when run.

Afaik circular dependencies are fine. I get them in my apps without problems, it's just a warning

They can be fine, but there can be issues as well. I'm not sure if this is the case here. I've always liked the idea of rollup, but I've always run into issues like this that prevent me from using it for much. We could do some work to make Typewriter work with rollup, maybe even use it as the build tool for a single tree-shakable file.

fwiw I only ever use rollup and have never hit any issues apart from those warnings (occasionally)

If anyone would like to convert this to Rollup for the build, we welcome it.

This has been fixed in 0980942