Reading window event's relatedTarget property throws.
Reproducible on a playground: https://developer.salesforce.com/docs/component-library/tools/playground/f0mKwIvOs/1/edit
event.relatedTarget returning smth, undefined at least
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)
Possible Solution
Additional context/Screenshots
Are there any restrictions to listen window events?
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.
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.
Most helpful comment
It looks like the
pathComposeris 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.parentNodemight be an instance ofWindow. AccessingparentNodeon theWindowreturnsundefinedexplaining why the error is thrown.