Skip to content

Commit 47551a6

Browse files
authored
fix(legacy): preserve async generator function invocation (#15021)
1 parent c3b55c4 commit 47551a6

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

packages/plugin-legacy/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https
156156

157157
- `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
158158
- `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
159-
- `sha256-8uUkKieevHiD3yYtzjkRvyDZWt+uZkBLuGEQWNiV3+c=`
159+
- `sha256-6gxDO54HJkJNWi7H6ipFpWWSkWSRpyuZYMGDyG6bcNE=`
160160
- `sha256-+5XkZFazzJo8n0iOP4ti/cLCMUudTf//Mzkb7xNPXIc=`
161161

162162
<!--

packages/plugin-legacy/src/snippets.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export const legacyEntryId = 'vite-legacy-entry'
77
export const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`
88

99
const detectModernBrowserVarName = '__vite_is_modern_browser'
10-
export const detectModernBrowserDetector =
11-
'import.meta.url;import("_").catch(()=>1);(async function* g(){})();'
10+
export const detectModernBrowserDetector = `import.meta.url;import("_").catch(()=>1);(async function*(){})().next()`
1211
export const detectModernBrowserCode = `${detectModernBrowserDetector}if(location.protocol!="file:"){window.${detectModernBrowserVarName}=true}`
1312
export const dynamicFallbackInlineCode = `!function(){if(window.${detectModernBrowserVarName})return;console.warn("vite: loading legacy chunks, syntax error above and the same error below should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}();`
1413

playground/legacy/__tests__/legacy.spec.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ describe.runIf(isBuild)('build', () => {
120120
const terserPattern = /^(?:!function|System.register)/
121121

122122
expect(findAssetFile(/chunk-async-legacy/)).toMatch(terserPattern)
123-
expect(findAssetFile(/chunk-async\./)).not.toMatch(terserPattern)
123+
expect(findAssetFile(/chunk-async(?!-legacy)/)).not.toMatch(terserPattern)
124124
expect(findAssetFile(/immutable-chunk-legacy/)).toMatch(terserPattern)
125-
expect(findAssetFile(/immutable-chunk\./)).not.toMatch(terserPattern)
125+
expect(findAssetFile(/immutable-chunk(?!-legacy)/)).not.toMatch(
126+
terserPattern,
127+
)
126128
expect(findAssetFile(/index-legacy/)).toMatch(terserPattern)
127-
expect(findAssetFile(/index\./)).not.toMatch(terserPattern)
129+
expect(findAssetFile(/index(?!-legacy)/)).not.toMatch(terserPattern)
128130
expect(findAssetFile(/polyfills-legacy/)).toMatch(terserPattern)
129131
})
130132

@@ -149,4 +151,13 @@ describe.runIf(isBuild)('build', () => {
149151
),
150152
).toBeFalsy()
151153
})
154+
155+
test('should have only modern entry files guarded', async () => {
156+
const guard = /(import\s*\()|(import.meta)|(async\s*function\*)/
157+
expect(findAssetFile(/index(?!-legacy)/)).toMatch(guard)
158+
expect(findAssetFile(/polyfills(?!-legacy)/)).toMatch(guard)
159+
160+
expect(findAssetFile(/chunk-async(?!-legacy)/)).not.toMatch(guard)
161+
expect(findAssetFile(/index-legacy/)).not.toMatch(guard)
162+
})
152163
})

0 commit comments

Comments
 (0)