ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

sporadic error due to missing staticAreaItemDomRef when rendering certain elements

Open phil-mitchell opened this issue 5 years ago • 2 comments

Describe the bug

Occasionally when loading my page I get an error printed in the console. The app continues to work as expected, but the error is ugly and indicates a coding error inside UI5.

TypeError: Cannot read property 'querySelector' of null

One example stack trace is as follows:

_getPopover (TextArea.js:483)
await in _getPopover (async)
closePopover (TextArea.js:477)
toggleValueStateMessage (TextArea.js:467)
onAfterRendering (TextArea.js:403)
_render (UI5Element.js:615)
renderImmediately (RenderScheduler.js:46)
connectedCallback (UI5Element.js:143)
await in connectedCallback (async)
_updateAttribute (UI5Element.js:440)
set (UI5Element.js:1012)
attributeChangedCallback (UI5Element.js:415)
connectedCallback (BaseEditor.js:137)
...

It is clear from this that:

const staticAreaItem = await this.getStaticAreaItemDomRef();

returned null. I confirmed this with the debugger.

To reproduce I don't quite know how to reproduce as it seems to be timing-related in some way. Perhaps things are being added or removed from the DOM asynchronously creating a race condition.

Isolated example This happens when I render the following template:

<ui5-responsive-popover id="confirm-delete-popover" header-text="Confirm removal">
  <div class="popover-content">
    <div class="messages">
    </div>
  </div>
  <div slot="footer" class="popover-footer">
    <ui5-button id="confirm-delete-popover-submit" design="Negative">Remove</ui5-button>
  </div>
</ui5-responsive-popover>

Using the following JS code:

    async connectedCallback() {
        ...
        this.shadowRoot.innerHTML = template;
        ...
   }

Expected behavior This error condition needs to be handled within UI5 to avoid the error message. If it is possible for getStaticAreaItemDomRef() to return null, then the caller needs to check for null before dereferencing. This same pattern happens in...many...elements.

Context

  • UI5 Web Components version 1.0.0-rc.11
  • OS/Platform: Mac
  • Browser: Chrome

phil-mitchell avatar Dec 31 '20 21:12 phil-mitchell

Hi @phil-mitchell

Could you provide your sample in CodeSandbox so that we can take a look

fifoosid avatar Jan 04 '21 08:01 fifoosid

Closing due to inactivity. You can still comment and we will reopen the issue.

ilhan007 avatar Jan 28 '21 10:01 ilhan007