fix: getPayload generate import map only when used in Payload Admin Panel (#9371)
After the change with removing `getPayloadHMR`, we do generate import map even outside of Next.js, which leads to errors when using in a project without it: 
This commit is contained in:
@@ -807,7 +807,7 @@ export const getPayload = async (
|
|||||||
// will reach `if (cached.reload instanceof Promise) {` which then waits for the first reload to finish.
|
// will reach `if (cached.reload instanceof Promise) {` which then waits for the first reload to finish.
|
||||||
cached.reload = new Promise((res) => (resolve = res))
|
cached.reload = new Promise((res) => (resolve = res))
|
||||||
const config = await options.config
|
const config = await options.config
|
||||||
await reload(config, cached.payload)
|
await reload(config, cached.payload, !options.importMap)
|
||||||
|
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
@@ -815,7 +815,6 @@ export const getPayload = async (
|
|||||||
if (cached.reload instanceof Promise) {
|
if (cached.reload instanceof Promise) {
|
||||||
await cached.reload
|
await cached.reload
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options?.importMap) {
|
if (options?.importMap) {
|
||||||
cached.payload.importMap = options.importMap
|
cached.payload.importMap = options.importMap
|
||||||
}
|
}
|
||||||
@@ -839,6 +838,7 @@ export const getPayload = async (
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const port = process.env.PORT || '3000'
|
const port = process.env.PORT || '3000'
|
||||||
|
|
||||||
cached.ws = new WebSocket(
|
cached.ws = new WebSocket(
|
||||||
`ws://localhost:${port}${process.env.NEXT_BASE_PATH ?? ''}/_next/webpack-hmr`,
|
`ws://localhost:${port}${process.env.NEXT_BASE_PATH ?? ''}/_next/webpack-hmr`,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user