Skip to content

Commit

Permalink
Extract module name (#940)
Browse files Browse the repository at this point in the history
* Extract module name
  • Loading branch information
penalosa authored Feb 20, 2025
1 parent 2cd4c3c commit 52f0113
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-spoons-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

chore: Extract module name in dynamic imports
3 changes: 2 additions & 1 deletion packages/next-on-pages/templates/_worker.js/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export async function getSuspenseCacheAdaptor(): Promise<CacheAdaptor> {
async function getInternalCacheAdaptor(
type: 'kv' | 'cache-api',
): Promise<CacheAdaptor> {
const adaptor = await import(`./__next-on-pages-dist__/cache/${type}.js`);
const moduleName = `./__next-on-pages-dist__/cache/${type}.js`;
const adaptor = await import(moduleName);
return new adaptor.default();
}

Expand Down
5 changes: 2 additions & 3 deletions packages/next-on-pages/templates/_worker.js/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ async function handleInlineAssetRequest(request: Request) {
if (request.url.startsWith('blob:')) {
try {
const url = new URL(request.url);
const binaryContent = (
await import(`./__next-on-pages-dist__/assets/${url.pathname}.bin`)
).default;
const moduleName = `./__next-on-pages-dist__/assets/${url.pathname}.bin`;
const binaryContent = (await import(moduleName)).default;

// Note: we can't generate a real Response object here because this fetch might be called
// at the top level of a dynamically imported module, and such cases produce the following
Expand Down

0 comments on commit 52f0113

Please sign in to comment.