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

Error while creating an editor (using node tree cloned from template before appending to DOM?) #4634

Closed
AgainPsychoX opened this issue Feb 13, 2022 · 1 comment

Comments

@AgainPsychoX
Copy link

AgainPsychoX commented Feb 13, 2022

Situation

My guess is, it may have something to do with fact I am creating it node tree cloned from template, before being appended to actual DOM.

Steps to reproduce, vaguely:

  1. Have <template> with child node you want to attach the editor to.
    <template class="something">
        <div class="something-else"></div>
        <div class="editor"></div>
    </template>
  2. Get template and clone it. Access the node you want attach the editor, and try to use it.
    const fragment = document.querySelectior('template.something').content.cloneNode(true);
    const editorElement = fragment.querySelect('.editor');
    const editor = ace.edit(editorElement);
  3. Later of course the fragment is attached to the DOM (in the same code-flow).

Stacktrace

ace.min.js:1 Uncaught TypeError: Cannot read properties of null (reading 'appendChild')
    at Object.o.scrollbarWidth (ace.min.js:1:6019)
    at new l (ace.min.js:1:270981)
    at new e (ace.min.js:1:293008)
    at Object.o.edit (ace.min.js:1:362270)
    at StrategiesManager.registerStrategy (strategies.js:250:24)
    at registerStrategy (index.js:68:56)
    at static-naive.js:2:1

Tracking the issue

  1. body.appendChild(outer);
  2. this.width = dom.scrollbarWidth(parent.ownerDocument);
  3. this.scrollBarV = new VScrollBar(this.container, this);
  4. this.container = container || dom.createElement("div");

    and here I'll stop, because it looks like only uses for this VirtualRenderer classes are related to testing: [removed image] because I was lazy and found workaround anyway.

Workaround:

Currently, I use setTimeout or requestAnimationFrame to delay attaching the editor to the element, but it looks bad.

@andrewnester
Copy link
Contributor

Fixed in 1.13.0

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

No branches or pull requests

2 participants