File tree 4 files changed +17
-2
lines changed
packages/next-on-pages/templates/_worker.js/utils
4 files changed +17
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @cloudflare/next-on-pages ' : patch
3
+ ---
4
+
5
+ chore: Extract module name in dynamic imports so that esbuild doesn't minify them
Original file line number Diff line number Diff line change 1
1
import type { CacheAdaptor , IncrementalCacheValue } from '../../cache' ;
2
2
import { SUSPENSE_CACHE_URL } from '../../cache' ;
3
+ import { doImport } from './doImport' ;
3
4
4
5
// https://github.com/vercel/next.js/blob/48a566bc/packages/next/src/server/lib/incremental-cache/fetch-cache.ts#L19
5
6
const CACHE_TAGS_HEADER = 'x-vercel-cache-tags' ;
@@ -118,7 +119,7 @@ async function getInternalCacheAdaptor(
118
119
type : 'kv' | 'cache-api' ,
119
120
) : Promise < CacheAdaptor > {
120
121
const moduleName = `./__next-on-pages-dist__/cache/${ type } .js` ;
121
- const adaptor = await import ( moduleName ) ;
122
+ const adaptor = await doImport ( moduleName ) ;
122
123
return new adaptor . default ( ) ;
123
124
}
124
125
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Newer versions of esbuild try to resolve dynamic imports by crawling the filesystem for matching modules.
3
+ * This doesn't work with the code next-on-pages generates, because the modules don't necessarily exist on the filesystem.
4
+ * This forces esbuild _not_ to look for matching modules on the filesystem (because esbuild doesn't inline functions when minifying)
5
+ */
6
+ export async function doImport ( m : string ) {
7
+ return import ( m ) ;
8
+ }
Original file line number Diff line number Diff line change 1
1
import { handleSuspenseCacheRequest } from './cache' ;
2
+ import { doImport } from './doImport' ;
2
3
3
4
/**
4
5
* Patches the global fetch in ways necessary for Next.js (/next-on-pages) applications
@@ -50,7 +51,7 @@ async function handleInlineAssetRequest(request: Request) {
50
51
try {
51
52
const url = new URL ( request . url ) ;
52
53
const moduleName = `./__next-on-pages-dist__/assets/${ url . pathname } .bin` ;
53
- const binaryContent = ( await import ( moduleName ) ) . default ;
54
+ const binaryContent = ( await doImport ( moduleName ) ) . default ;
54
55
55
56
// Note: we can't generate a real Response object here because this fetch might be called
56
57
// at the top level of a dynamically imported module, and such cases produce the following
You can’t perform that action at this time.
0 commit comments