Lwc: Accessing event.relatedTarget throws

Created on 3 Apr 2020  路  3Comments  路  Source: salesforce/lwc

Description

Reading window event's relatedTarget property throws.

Steps to Reproduce

Reproducible on a playground: https://developer.salesforce.com/docs/component-library/tools/playground/f0mKwIvOs/1/edit

Expected Results

event.relatedTarget returning smth, undefined at least

Actual Results

Exception is thrown:

TypeError: Cannot read property 'parentNode' of undefined
    at pathComposer (https://d3nm9grey5nsoo.cloudfront.net/api/runtime/lwc-synthetic-shadow/1.1.13-224.8/dist/synthetic-shadow.js:372:25)
    at retarget (https://d3nm9grey5nsoo.cloudfront.net/api/runtime/lwc-synthetic-shadow/1.1.13-224.8/dist/synthetic-shadow.js:396:23)
    at MouseEvent.get [as relatedTarget] (https://d3nm9grey5nsoo.cloudfront.net/api/runtime/lwc-synthetic-shadow/1.1.13-224.8/dist/synthetic-shadow.js:517:16)
    at compiledPreview.js:694:34
    at fnOrObj.$$lwcEventWrapper$$ (https://d3nm9grey5nsoo.cloudfront.net/api/runtime/lwc-synthetic-shadow/1.1.13-224.8/dist/synthetic-shadow.js:2471:44)

Browsers Affected

Version

  • "@lwc/engine: "1.1.13-224.4"

Possible Solution

Additional context/Screenshots
Are there any restrictions to listen window events?

BUG P3 bug

Most helpful comment

It looks like the pathComposer is doing a wrong type guard.

https://github.com/salesforce/lwc/blob/f6844f28894b8bad1336dd1753314e41b1737ac5/packages/%40lwc/synthetic-shadow/src/3rdparty/polymer/path-composer.ts#L39

At this point in the algorithm, the current.parentNode might be an instance of Window. Accessing parentNode on the Window returns undefined explaining why the error is thrown.

All 3 comments

Probably a bug in synthetic shadow dom polyfill. cc @Gr8Gatsby @jodarove @ravijayaramappa

This issue has been linked to a new work item: W-7417990

It looks like the pathComposer is doing a wrong type guard.

https://github.com/salesforce/lwc/blob/f6844f28894b8bad1336dd1753314e41b1737ac5/packages/%40lwc/synthetic-shadow/src/3rdparty/polymer/path-composer.ts#L39

At this point in the algorithm, the current.parentNode might be an instance of Window. Accessing parentNode on the Window returns undefined explaining why the error is thrown.

Was this page helpful?
0 / 5 - 0 ratings