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

fix: make sure unknown is mapped to HTMLUnknownElement cstr #606

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -79,7 +79,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
Loading