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

TypeError: Cannot read properties of undefined (reading 'lastNode') #1398

Open
johanrd opened this issue Nov 15, 2022 · 3 comments
Open

TypeError: Cannot read properties of undefined (reading 'lastNode') #1398

johanrd opened this issue Nov 15, 2022 · 3 comments

Comments

@johanrd
Copy link

johanrd commented Nov 15, 2022

I see TypeError: Cannot read properties of undefined (reading 'lastNode') from time to time popping up in Sentry:

Screen Shot 2022-11-15 at 12 21 15

https://github.com/glimmerjs/glimmer-vm/blob/master/packages/@glimmer/runtime/lib/vm/element-builder.ts#L506-L515

I have yet to reproduce it when I try, unfortunately. Any ideas on what may be causing this? Possibly related to #1372 and emberjs/ember.js#18520


Environment:
@glimmer/component: "^1.1.1",
ember-source: "4.8.0",
Browser: Chrome 107.0.0
OS: Windows 10

@lifeart
Copy link
Contributor

lifeart commented Nov 15, 2022

@johanrd it's likely related to google page translate or any extensions, modifying dom nodes

@johanrd
Copy link
Author

johanrd commented Nov 16, 2022

@lifeart Yes, that may very well be.

As commented on #1372 (comment), I don't think it is a very viable solution to tell users to uninstall various chrome extensions and/or not use google translate in order to not break a glimmer app.

Is it possible with a more resilient handling? E.g. by applying optional chaining on tail.lastNode()? (if that does not break browser support or other parts too much)

// https://github.com/glimmerjs/glimmer-vm/blob/master/packages/@glimmer/runtime/lib/vm/element-builder.ts#L506-L515

lastNode(): SimpleNode {
    let boundList = this.boundList;

    let tail = expect(
      boundList[boundList.length - 1],
      'cannot call `lastNode()` while `LiveBlockList` is still initializing'
    );

-    return tail.lastNode();
+    return tail?.lastNode();
  }

@golampo
Copy link

golampo commented Jan 12, 2023

This issue appears to result from the usage of htmlSafe from @ember/template.
It happens when the htmlSafe outputted code is torn down/updated after it has been translated w/ Google Translate (or similar tool). Oddly, adding a wrapper element to the htmlSafe output fixes the issue - though not a reasonable solution in most cases.

htmlSafe(`<span>${someValue}</span>`)

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

No branches or pull requests

3 participants