Skip to content

TypeError: Cannot read properties of undefined (reading 'name') #283

@thewatts

Description

@thewatts

I'm trying to leverage Morphdom while using Hotwire/Turbo → Similar to this documentation/example here: Turbo Handbook: Custom Rendering

This is to attempt to have a little more control over what gets replaced by Turbo.

Here's my code:

handleTurboFrameRender(event) {
  const focusedElement = document.activeElement;

  event.detail.render = (currentElement, newElement) => {
    morphdom(currentElement, newElement, {
      childrenOnly: false,
      onBeforeElUpdated: (fromEl, toEl) => {
        // Skip updating data-turbo-permanent items
        if (fromEl.hasAttribute("data-turbo-permanent")) {
          return false;
        }

        // Skip updating focused elements, so that we don't lose where we're typing
        if (fromEl === focusedElement) {
          return false;
        }

        return true;
      },
    });
  };
}

However, I'm getting this error - specifically after setting childrenOnly: false

Morphdom error: TypeError: Cannot read properties of undefined (reading 'name')

Coming from [this line of code, where Morphdom is striving to get the attribute name](

attrName = attr.name;
.

In the instance above though, there's no attribute 🤔

Is there something, re: how Morphdom works, that I'm missing?

Image

Thanks so much for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions