You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: deprecates getPayloadHMR in favor of simpler getPayload (#9249)
Deprecates `getPayloadHMR` and simplifies this pattern into a single
`import { getPayload } from 'payload'`.
We will still retain the exported `getPayloadHMR` but it now will throw
a deprecation warning with instructions for how to migrate.
Copy file name to clipboardExpand all lines: docs/local-api/outside-nextjs.mdx
+1-4Lines changed: 1 addition & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,12 +18,9 @@ Payload can be used completely outside of Next.js which is helpful in cases like
18
18
19
19
Payload provides a convenient way to run standalone scripts, which can be useful for tasks like seeding your database or performing one-off operations.
20
20
21
-
In standalone scripts, can simply import the Payload Config and use it right away. If you need an initialized copy of Payload, you can then use the `getPayload` function. This can be useful for tasks like seeding your database or performing other one-off operations.
21
+
In standalone scripts, you can simply import the Payload Config and use it right away. If you need an initialized copy of Payload, you can then use the `getPayload` function. This can be useful for tasks like seeding your database or performing other one-off operations.
22
22
23
23
```ts
24
-
// We are importing `getPayload` because we don't need HMR
25
-
// for a standalone script. For usage of Payload inside Next.js,
26
-
// you should always use `import { getPayloadHMR } from '@payloadcms/next/utilities'` instead.
If you want to import Payload in places where you don't have the option to access it from function arguments or `req`, you can import it and initialize it.
You should import Payload using the first option (`getPayloadHMR`) if you are using Payload inside of Next.js (like route handlers, server components, and similar.)
58
-
59
-
This way, in Next.js development mode, Payload will work with Hot Module Replacement (HMR), and as you make changes to your Payload Config, your usage of Payload will always be in sync with your changes. In production, `getPayloadHMR` simply disables all HMR functionality so you don't need to write your code any differently. We handle optimization for you in production mode.
53
+
If you're working in Next.js' development mode, Payload will work with Hot Module Replacement (HMR), and as you make changes to your Payload Config, your usage of Payload will always be in sync with your changes. In production, `getPayload` simply disables all HMR functionality so you don't need to write your code any differently. We handle optimization for you in production mode.
60
54
61
55
If you are accessing Payload via function arguments or `req.payload`, HMR is automatically supported if you are using it within Next.js.
62
56
63
-
**Option 2 - outside of Next.js**
64
-
65
-
If you are using Payload outside of Next.js, for example in standalone scripts or in other frameworks, you can import Payload with no HMR functionality. Instead of using `getPayloadHMR`, you can use `getPayload`.
66
-
67
-
```ts
68
-
import { getPayload } from'payload'
69
-
importconfigfrom'@payload-config'
70
-
71
-
const payload =awaitgetPayload({ config })
72
-
```
73
-
74
-
Both options function in exactly the same way outside of one having HMR support and the other not. For more information about using Payload outside of Next.js, [click here](./outside-nextjs).
57
+
For more information about using Payload outside of Next.js, [click here](./outside-nextjs).
0 commit comments