Skip to content

Commit c1db3a3

Browse files
committed
fixup! fix: do not load asynchronously content scripts without imports/exports
1 parent 77abfa8 commit c1db3a3

File tree

14 files changed

+163
-388
lines changed

14 files changed

+163
-388
lines changed
Loading
Loading

Diff for: packages/vite-plugin/tests/out/basic-js/__snapshots__/build.test.ts.snap

+15-33
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Object {
1212
"content_scripts": Array [
1313
Object {
1414
"js": Array [
15-
"assets/content.js-loader.hash0.js",
15+
"assets/content.js.hash0.js",
1616
],
1717
"matches": Array [
1818
"https://a.com/*",
@@ -34,7 +34,7 @@ Object {
3434
"https://a.com/*",
3535
],
3636
"resources": Array [
37-
"assets/content.js.hash1.js",
37+
"assets/content.js.hash0.js",
3838
],
3939
"use_dynamic_url": false,
4040
},
@@ -44,46 +44,28 @@ Object {
4444

4545
exports[`build fs output > _01 output files 1`] = `
4646
Array [
47-
"assets/background.js.hash2.js",
48-
"assets/content.js-loader.hash0.js",
49-
"assets/content.js.hash1.js",
50-
"assets/popup.html.hash3.js",
51-
"assets/vendor.hash4.js",
47+
"assets/background.js.hash1.js",
48+
"assets/content.js.hash0.js",
49+
"assets/popup.html.hash2.js",
50+
"assets/vendor.hash3.js",
5251
"manifest.json",
5352
"service-worker-loader.js",
5453
"src/popup.html",
5554
]
5655
`;
5756

58-
exports[`build fs output > assets/background.js.hash2.js 1`] = `
57+
exports[`build fs output > assets/background.js.hash1.js 1`] = `
5958
"console.log(\\"service_worker.js\\");
6059
"
6160
`;
6261

63-
exports[`build fs output > assets/content.js.hash1.js 1`] = `
64-
"console.log(\\"content script\\");
65-
"
66-
`;
67-
68-
exports[`build fs output > assets/content.js-loader.hash0.js 1`] = `
69-
"(function () {
70-
'use strict';
71-
72-
const injectTime = performance.now();
73-
(async () => {
74-
const { onExecute } = await import(
75-
/* @vite-ignore */
76-
chrome.runtime.getURL(\\"assets/content.js.hash1.js\\")
77-
);
78-
onExecute?.({ perf: { injectTime, loadTime: performance.now() - injectTime } });
79-
})().catch(console.error);
80-
81-
})();
82-
"
62+
exports[`build fs output > assets/content.js.hash0.js 1`] = `
63+
"(function(){console.log(\\"content script\\");
64+
})()"
8365
`;
8466

85-
exports[`build fs output > assets/popup.html.hash3.js 1`] = `
86-
"import { R as React, a as ReactDOM } from \\"./vendor.hash4.js\\";
67+
exports[`build fs output > assets/popup.html.hash2.js 1`] = `
68+
"import { R as React, a as ReactDOM } from \\"./vendor.hash3.js\\";
8769
(function polyfill() {
8870
const relList = document.createElement(\\"link\\").relList;
8971
if (relList && relList.supports && relList.supports(\\"modulepreload\\")) {
@@ -135,7 +117,7 @@ ReactDOM.render(/* @__PURE__ */ React.createElement(App, null), root);
135117
`;
136118

137119
exports[`build fs output > service-worker-loader.js 1`] = `
138-
"import './assets/background.js.hash2.js';
120+
"import './assets/background.js.hash1.js';
139121
"
140122
`;
141123

@@ -146,8 +128,8 @@ exports[`build fs output > src/popup.html 1`] = `
146128
<meta charset=\\"UTF-8\\" />
147129
<meta name=\\"viewport\\" content=\\"width=1000, initial-scale=1.0\\" />
148130
<title>Popup Page</title>
149-
<script type=\\"module\\" crossorigin src=\\"/assets/popup.html.hash3.js\\"></script>
150-
<link rel=\\"modulepreload\\" crossorigin href=\\"/assets/vendor.hash4.js\\">
131+
<script type=\\"module\\" crossorigin src=\\"/assets/popup.html.hash2.js\\"></script>
132+
<link rel=\\"modulepreload\\" crossorigin href=\\"/assets/vendor.hash3.js\\">
151133
</head>
152134
<body>
153135
<div id=\\"root\\"></div>

Diff for: packages/vite-plugin/tests/out/basic-ts/__snapshots__/build.test.ts.snap

+15-33
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Object {
1212
"content_scripts": Array [
1313
Object {
1414
"js": Array [
15-
"assets/content.ts-loader.hash0.js",
15+
"assets/content.ts.hash0.js",
1616
],
1717
"matches": Array [
1818
"https://*/*",
@@ -31,7 +31,7 @@ Object {
3131
"https://*/*",
3232
],
3333
"resources": Array [
34-
"assets/content.ts.hash1.js",
34+
"assets/content.ts.hash0.js",
3535
],
3636
"use_dynamic_url": false,
3737
},
@@ -41,46 +41,28 @@ Object {
4141

4242
exports[`build fs output > _01 output files 1`] = `
4343
Array [
44-
"assets/background.ts.hash2.js",
45-
"assets/content.ts-loader.hash0.js",
46-
"assets/content.ts.hash1.js",
47-
"assets/popup.html.hash3.js",
48-
"assets/vendor.hash4.js",
44+
"assets/background.ts.hash1.js",
45+
"assets/content.ts.hash0.js",
46+
"assets/popup.html.hash2.js",
47+
"assets/vendor.hash3.js",
4948
"manifest.json",
5049
"service-worker-loader.js",
5150
"src/popup.html",
5251
]
5352
`;
5453

55-
exports[`build fs output > assets/background.ts.hash2.js 1`] = `
54+
exports[`build fs output > assets/background.ts.hash1.js 1`] = `
5655
"console.log(\\"service_worker.ts\\");
5756
"
5857
`;
5958

60-
exports[`build fs output > assets/content.ts.hash1.js 1`] = `
61-
"console.log(\\"content script\\");
62-
"
63-
`;
64-
65-
exports[`build fs output > assets/content.ts-loader.hash0.js 1`] = `
66-
"(function () {
67-
'use strict';
68-
69-
const injectTime = performance.now();
70-
(async () => {
71-
const { onExecute } = await import(
72-
/* @vite-ignore */
73-
chrome.runtime.getURL(\\"assets/content.ts.hash1.js\\")
74-
);
75-
onExecute?.({ perf: { injectTime, loadTime: performance.now() - injectTime } });
76-
})().catch(console.error);
77-
78-
})();
79-
"
59+
exports[`build fs output > assets/content.ts.hash0.js 1`] = `
60+
"(function(){console.log(\\"content script\\");
61+
})()"
8062
`;
8163

82-
exports[`build fs output > assets/popup.html.hash3.js 1`] = `
83-
"import { R as React, r as reactDom } from \\"./vendor.hash4.js\\";
64+
exports[`build fs output > assets/popup.html.hash2.js 1`] = `
65+
"import { R as React, r as reactDom } from \\"./vendor.hash3.js\\";
8466
(function polyfill() {
8567
const relList = document.createElement(\\"link\\").relList;
8668
if (relList && relList.supports && relList.supports(\\"modulepreload\\")) {
@@ -132,7 +114,7 @@ reactDom.exports.render(/* @__PURE__ */ React.createElement(App, null), root);
132114
`;
133115

134116
exports[`build fs output > service-worker-loader.js 1`] = `
135-
"import './assets/background.ts.hash2.js';
117+
"import './assets/background.ts.hash1.js';
136118
"
137119
`;
138120

@@ -143,8 +125,8 @@ exports[`build fs output > src/popup.html 1`] = `
143125
<meta charset=\\"UTF-8\\" />
144126
<meta name=\\"viewport\\" content=\\"width=1000, initial-scale=1.0\\" />
145127
<title>Popup Page</title>
146-
<script type=\\"module\\" crossorigin src=\\"/assets/popup.html.hash3.js\\"></script>
147-
<link rel=\\"modulepreload\\" crossorigin href=\\"/assets/vendor.hash4.js\\">
128+
<script type=\\"module\\" crossorigin src=\\"/assets/popup.html.hash2.js\\"></script>
129+
<link rel=\\"modulepreload\\" crossorigin href=\\"/assets/vendor.hash3.js\\">
148130
</head>
149131
<body>
150132
<div id=\\"root\\"></div>

Diff for: packages/vite-plugin/tests/out/dynamic-script/__snapshots__/build.test.ts.snap

+18-54
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Object {
99
"content_scripts": Array [
1010
Object {
1111
"js": Array [
12-
"assets/declared-script.ts-loader.hash0.js",
12+
"assets/declared-script.ts.hash0.js",
1313
],
1414
"matches": Array [
1515
"https://a.com/*",
@@ -27,8 +27,8 @@ Object {
2727
"https://a.com/*",
2828
],
2929
"resources": Array [
30-
"assets/declared-script.ts.hash1.js",
31-
"assets/main-world.ts.hash2.js",
30+
"assets/declared-script.ts.hash0.js",
31+
"assets/main-world.ts.hash1.js",
3232
],
3333
"use_dynamic_url": false,
3434
},
@@ -38,7 +38,7 @@ Object {
3838
"https://*/*",
3939
],
4040
"resources": Array [
41-
"assets/dynamic-script.ts.hash3.js",
41+
"assets/dynamic-script.ts.hash2.js",
4242
],
4343
"use_dynamic_url": false,
4444
},
@@ -48,19 +48,17 @@ Object {
4848

4949
exports[`build fs output > _01 output files 1`] = `
5050
Array [
51-
"assets/background.ts.hash4.js",
52-
"assets/declared-script.ts-loader.hash0.js",
53-
"assets/declared-script.ts.hash1.js",
54-
"assets/dynamic-script.ts-loader.hash5.js",
55-
"assets/dynamic-script.ts.hash3.js",
56-
"assets/main-world.ts.hash2.js",
51+
"assets/background.ts.hash3.js",
52+
"assets/declared-script.ts.hash0.js",
53+
"assets/dynamic-script.ts.hash2.js",
54+
"assets/main-world.ts.hash1.js",
5755
"manifest.json",
5856
"service-worker-loader.js",
5957
]
6058
`;
6159

62-
exports[`build fs output > assets/background.ts.hash4.js 1`] = `
63-
"const scriptFileName = \\"/assets/dynamic-script.ts-loader.hash5.js\\";
60+
exports[`build fs output > assets/background.ts.hash3.js 1`] = `
61+
"const scriptFileName = \\"/assets/dynamic-script.ts.hash2.js\\";
6462
console.log(\\"background.ts\\");
6563
chrome.action.onClicked.addListener((tab) => {
6664
if (tab.id)
@@ -72,61 +70,27 @@ chrome.action.onClicked.addListener((tab) => {
7270
"
7371
`;
7472

75-
exports[`build fs output > assets/declared-script.ts.hash1.js 1`] = `
76-
"const fileName = \\"/assets/main-world.ts.hash2.js\\";
73+
exports[`build fs output > assets/declared-script.ts.hash0.js 1`] = `
74+
"(function(){const fileName = \\"/assets/main-world.ts.hash1.js\\";
7775
console.log(\\"declared script\\");
7876
const script = document.createElement(\\"script\\");
7977
script.src = chrome.runtime.getURL(fileName);
8078
script.type = \\"module\\";
8179
document.head.prepend(script);
82-
"
83-
`;
84-
85-
exports[`build fs output > assets/declared-script.ts-loader.hash0.js 1`] = `
86-
"(function () {
87-
'use strict';
88-
89-
const injectTime = performance.now();
90-
(async () => {
91-
const { onExecute } = await import(
92-
/* @vite-ignore */
93-
chrome.runtime.getURL(\\"assets/declared-script.ts.hash1.js\\")
94-
);
95-
onExecute?.({ perf: { injectTime, loadTime: performance.now() - injectTime } });
96-
})().catch(console.error);
97-
98-
})();
99-
"
80+
})()"
10081
`;
10182

102-
exports[`build fs output > assets/dynamic-script.ts.hash3.js 1`] = `
103-
"console.log(\\"dynamic script\\");
104-
"
105-
`;
106-
107-
exports[`build fs output > assets/dynamic-script.ts-loader.hash5.js 1`] = `
108-
"(function () {
109-
'use strict';
110-
111-
const injectTime = performance.now();
112-
(async () => {
113-
const { onExecute } = await import(
114-
/* @vite-ignore */
115-
chrome.runtime.getURL(\\"assets/dynamic-script.ts.hash3.js\\")
116-
);
117-
onExecute?.({ perf: { injectTime, loadTime: performance.now() - injectTime } });
118-
})().catch(console.error);
119-
120-
})();
121-
"
83+
exports[`build fs output > assets/dynamic-script.ts.hash2.js 1`] = `
84+
"(function(){console.log(\\"dynamic script\\");
85+
})()"
12286
`;
12387

124-
exports[`build fs output > assets/main-world.ts.hash2.js 1`] = `
88+
exports[`build fs output > assets/main-world.ts.hash1.js 1`] = `
12589
"console.log(\\"main world script\\");
12690
"
12791
`;
12892

12993
exports[`build fs output > service-worker-loader.js 1`] = `
130-
"import './assets/background.ts.hash4.js';
94+
"import './assets/background.ts.hash3.js';
13195
"
13296
`;

0 commit comments

Comments
 (0)