diff options
author | 2021-04-19 14:41:06 -0400 | |
---|---|---|
committer | 2021-04-19 14:41:06 -0400 | |
commit | eb984559a89b4f0b09c42604a18f1198c8d7ecca (patch) | |
tree | 5bcf0ea7c136733aa39c6dffc3d9b31d77dde719 /src/compiler/codegen/index.ts | |
parent | 188541260acad5ccd6699f0a21d6da600860e74c (diff) | |
download | astro-eb984559a89b4f0b09c42604a18f1198c8d7ecca.tar.gz astro-eb984559a89b4f0b09c42604a18f1198c8d7ecca.tar.zst astro-eb984559a89b4f0b09c42604a18f1198c8d7ecca.zip |
Fix dynamic React components (#111)
Another change in snowpack@3 caused this bug. It's not actually a bug in snowpack. Previously snowpack was keeping its list of installed packages in a global cache. In 3.3 it stopped doing so. We were accidentally relying on that global cache to be able to resolve dynamic components.
This fixes it so that we use the frontend snowpack instance to resolve dynamic components. Doing so means they are available when we try to load them.
Diffstat (limited to 'src/compiler/codegen/index.ts')
-rw-r--r-- | src/compiler/codegen/index.ts | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/compiler/codegen/index.ts b/src/compiler/codegen/index.ts index d3e8a45dd..8d968e1ea 100644 --- a/src/compiler/codegen/index.ts +++ b/src/compiler/codegen/index.ts @@ -258,21 +258,21 @@ function compileExpressionSafe(raw: string): string { } /** Build dependency map of dynamic component runtime frameworks */ -async function acquireDynamicComponentImports(plugins: Set<ValidExtensionPlugins>, resolve: (s: string) => Promise<string>): Promise<DynamicImportMap> { +async function acquireDynamicComponentImports(plugins: Set<ValidExtensionPlugins>, resolvePackageUrl: (s: string) => Promise<string>): Promise<DynamicImportMap> { const importMap: DynamicImportMap = new Map(); for (let plugin of plugins) { switch (plugin) { case 'vue': { - importMap.set('vue', await resolve('vue')); + importMap.set('vue', await resolvePackageUrl('vue')); break; } case 'react': { - importMap.set('react', await resolve('react')); - importMap.set('react-dom', await resolve('react-dom')); + importMap.set('react', await resolvePackageUrl('react')); + importMap.set('react-dom', await resolvePackageUrl('react-dom')); break; } case 'preact': { - importMap.set('preact', await resolve('preact')); + importMap.set('preact', await resolvePackageUrl('preact')); break; } } @@ -643,7 +643,7 @@ export async function codegen(ast: Ast, { compileOptions, filename }: CodeGenOpt }; const { script, componentPlugins, createCollection } = compileModule(ast.module, state, compileOptions); - state.dynamicImports = await acquireDynamicComponentImports(componentPlugins, compileOptions.resolve); + state.dynamicImports = await acquireDynamicComponentImports(componentPlugins, compileOptions.resolvePackageUrl); compileCss(ast.css, state); |