Skip to content

Commit

Permalink
fix async document.currentScript
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 5, 2021
1 parent 9f63513 commit b6cbeb1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/web-worker/worker-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class HTMLDocument extends HTMLElement {
}

get currentScript() {
if (webWorkerCtx.$currentScriptId$) {
if (webWorkerCtx.$currentScriptId$ > 0) {
return constructInstance(
InterfaceType.Element,
webWorkerCtx.$currentScriptId$,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/web-worker/worker-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class HTMLImageElement {
}
set src(src: string) {
if (debug && webWorkerCtx.$config$.logImageRequests) {
logWorker(`Image() src request: ${resolveUrl(src)}`);
logWorker(`Image() request: ${resolveUrl(src)}`);
}
fetch(resolveUrl(src) + '', {
mode: 'no-cors',
Expand Down
4 changes: 4 additions & 0 deletions tests/platform/document/document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ test('document', async ({ page }) => {
await expect(testCurrentScriptSrc).toHaveText('src');
await expect(testCurrentScriptSrcLocation).toHaveText('/platform/document/current-script-src.js');

await page.waitForSelector('.testCurrentScriptNullAsync');
const testCurrentScriptNullAsync = page.locator('#testCurrentScriptNullAsync');
await expect(testCurrentScriptNullAsync).toHaveText('null');

const testHeadParentNode = page.locator('#testHeadParentNode');
await expect(testHeadParentNode).toHaveText('HTML HTML');

Expand Down
12 changes: 12 additions & 0 deletions tests/platform/document/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ <h1 class="title">Document</h1>
></script>
</li>

<li>
<strong>currentScript, null async</strong>
<code id="testCurrentScriptNullAsync"></code>
<script type="text/partytown">
setTimeout(() => {
const elm = document.getElementById('testCurrentScriptNullAsync');
elm.textContent = String(document.currentScript);
elm.className = 'testCurrentScriptNullAsync';
});
</script>
</li>

<li>
<strong>head.parentNode/Element</strong>
<code id="testHeadParentNode"></code>
Expand Down

1 comment on commit b6cbeb1

@vercel
Copy link

@vercel vercel bot commented on b6cbeb1 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.