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

Infinite loop #751

Closed
pulciux opened this issue Jan 3, 2018 · 3 comments
Closed

Infinite loop #751

pulciux opened this issue Jan 3, 2018 · 3 comments
Labels
resolution:duplicate This issue is a duplicate of another issue and was merged into it.

Comments

@pulciux
Copy link

pulciux commented Jan 3, 2018

  • Bug report

💻 CKEditor 5 1.0.0-alpha.2 inline CDN

📋 Steps to reproduce

  1. It happens in Chrome 63.0.3239.108 (64 bit) - desktop and mobile tested. No further browsers tested.
  2. Leaving a DIV element bound to an inline editor for another element which gets focus, it ends up in a never ending while loop when it calls getParentUIElement from domconverter.js

domNode is undefined and ancestors.length too but it will never be false.

	/**
	 * Returns parent {@link module:engine/view/uielement~UIElement} for provided DOM node. Returns `null` if there is no
	 * parent UIElement.
	 *
	 * @param {Node} domNode
	 * @return {module:engine/view/uielement~UIElement|null}
	 */
	getParentUIElement( domNode ) {
		const ancestors = getAncestors( domNode );

		// Remove domNode from the list.
		ancestors.pop();

		while ( ancestors.length ) {
			const domNode = ancestors.pop();
			const viewNode = this._domToViewMapping.get( domNode );

			if ( viewNode && viewNode.is( 'uiElement' ) ) {
				return viewNode;
			}
		}

		return null;
	}

✅ Exit the loop

❎ Doesn't quit

@Reinmar
Copy link
Member

Reinmar commented Jan 3, 2018

Hi! Thanks for the report.

I tried to understand what happens, but it seems I don't. There's the ancestors array from which we pop an item on each iteration. So no matter what happens ancestors.length should become 0 at some point. Are you sure it never is? How could that happen?

Also, could you explain what do you do exactly? Even when fixing such low-level issues. we'd like to have a higher-level scenario to make sure that such a problem will never occur again.

@pulciux
Copy link
Author

pulciux commented Jan 4, 2018

Hi Reinmar,
it took a while but I've figured out what it triggers the infinite loop.
I was integrating ckeditor5 into my framework and I've noticed that after a certain event was fired by a different element it was ending in an infinite loop.
The event was triggering a complex cascade of events but eventually, I've found it was also trying to reinitiate the editor on the same div.
So I've reproduced it in a simpler code and it is actually what it causes the infinite loop.

If for some reason you have initiated an inline editor and then you try to reinitiate it, it will end in an infinite loop.

<!DOCTYPE html>
<html>
   <head>
      <meta charset="UTF-8">
      <script type="text/javascript" src="https://cdn.ckeditor.com/ckeditor5/1.0.0-alpha.2/inline/ckeditor.js"></script>
      <script type="text/javascript">
      	function initEditor(sel) {
		    try {
		        var elm = document.querySelector(sel);
		        InlineEditor
		                .create(elm)
		                .then(editor => {
		                    console.log(editor);
		                })
		                .catch(error => {
		                    console.error(error);
		                });

		    } catch (err) {
		        console.error(err.message);
		    }
      	}
      </script>      
   </head>
   <body>
   		<div id="mfield-test" contenteditable="true" style="border: 1px solid gray; margin-bottom: 200px;">
   			<p>This is a test text</p>
   		</div>
   	  	<div onclick="initEditor('#mfield-test');;" style="border: 1px solid red; width: 200px;">init editor again</span>
        <script type="text/javascript">
        	initEditor('#mfield-test');
        </script>
   </body>
</html>

to reproduce it, run the example and then click on 'init editor again'

@Reinmar
Copy link
Member

Reinmar commented Jan 4, 2018

Yep, it's a known problem. You can't initialise two editors on one element because they start to override each others' changes in that element.

DUP of #746.

@Reinmar Reinmar closed this as completed Jan 4, 2018
@Reinmar Reinmar added the resolution:duplicate This issue is a duplicate of another issue and was merged into it. label Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution:duplicate This issue is a duplicate of another issue and was merged into it.
Projects
None yet
Development

No branches or pull requests

2 participants