-
As I see, Payload plugins get initialized only when I open a page in the browser, so if I start it using pnpm dev and do not open anything - no plugins are loaded. Is there any way to make a specific plugin start instantly, without waiting for a webpage request from the user? So, this:
can hang forever, but if I open a frontpage, or any other page, only there it starts to initialize plugins:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The same issue with the function export default buildConfig({
async onInit(payload) {
console.log('Payload init!')
}
} it outputs this only after the first HTTP request is made, not after |
Beta Was this translation helpful? Give feedback.
-
Found a way to initialize Payload automatically on the Next.js startup - you need to create the import config from '@payload-config';
import { getPayload } from 'payload';
export async function register() {
if (typeof window !== 'undefined') {
return; // Skip on client side
}
// Only run on Node.js runtime (server side)
if (process.env.NEXT_RUNTIME === 'nodejs' || !process.env.NEXT_RUNTIME) {
await getPayload({ config })
}
} Not sure that this is the best way, but at least, works well for my case! More details: https://nextjs.org/docs/app/guides/instrumentation If you know a more elegant solution for this, please share! |
Beta Was this translation helpful? Give feedback.
Found a way to initialize Payload automatically on the Next.js startup - you need to create the
src/instrumentation.ts
file with content like this:Not sure that this is the best way, but at least, works well for my case!
More details: https://nextjs.org/docs/app/guides/instrumentation
If you know a more elegant solution for this, please share!