Skip to content

Commit

Permalink
fix: make sure unknown is mapped to HTMLUnknownElement cstr (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoebbelsB authored Dec 12, 2024
1 parent c031bfd commit e43df90
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/sandbox/read-main-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ export const readMainInterfaces = () => {
// and create each element to get their implementation
const elms = Object.getOwnPropertyNames(mainWindow)
.map((interfaceName) => createElementFromConstructor(docImpl, interfaceName))
.filter((elm) => elm)
.filter((elm) => {
if (!elm) {
return false;
}
const constructorName = getConstructorName(elm);
return !(
constructorName === 'HTMLUnknownElement' && elm.nodeName.toUpperCase() !== 'UNKNOWN'
);
})
.map((elm) => [elm]);

return readImplementations(elms, []);
Expand Down
4 changes: 4 additions & 0 deletions tests/platform/custom-element/custom-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ test('custom-element', async ({ page }) => {
const testDefine = page.locator('#testDefine');
await expect(testDefine).toHaveText('TestDefineElement');

await page.waitForSelector('.testDefineOnMainAccessOnWorker');
const testDefineOnMainAccessOnWorker = page.locator('#testDefineOnMainAccessOnWorker');
await expect(testDefineOnMainAccessOnWorker).toHaveText('it works');

await page.waitForSelector('.testNoReDefine');
const testNoReDefine = page.locator('#testNoReDefine');
await expect(testNoReDefine).toHaveText('TestNoReDefineElement');
Expand Down
17 changes: 17 additions & 0 deletions tests/platform/custom-element/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
logScriptExecution: true,
};
</script>
<script type="text/javascript">
class TestDefineOnMainAccessOnWorker extends HTMLElement {}
customElements.define('define-on-main-access-on-worker', TestDefineOnMainAccessOnWorker);
</script>
<script src="/~partytown/debug/partytown.js"></script>
</head>
<body>
Expand All @@ -79,6 +83,19 @@ <h1>Custom Element</h1>
</script>
</li>

<li>
<strong>define on main, access on worker</strong>

<define-on-main-access-on-worker id="testDefineOnMainAccessOnWorker"></define-on-main-access-on-worker>
<script type="text/partytown">
(function () {
const elm = document.getElementById('testDefineOnMainAccessOnWorker');
elm.textContent = 'it works';
elm.className = 'testDefineOnMainAccessOnWorker';
})();
</script>
</li>

<li>
<strong>no worker re-define</strong>
<div id="testNoReDefine"></div>
Expand Down

0 comments on commit e43df90

Please sign in to comment.