Commit a8bfade
authored
fix: set basePath from next config as env variable (#15154)
### What
Fix image preview URLs not displaying when `basePath` is set in
`next.config.mjs`.
### Why
When `basePath` is set in `next.config.mjs`, the `withPayload` function
assigns it as an env variable. However, currently the file sets
`basePath` as `baseConfig.env.NEXT_BASE_PATH`, which is only accessible
in Next.js runtime contexts (API routes, server components).
Upload URLs are generated from `formatAdminURL` in the Node.js
environment, where `baseConfig.env.NEXT_BASE_PATH` cannot be accessed.
As a result, it thinks no `basePath` is set and uses the incorrect URL
to render the upload preview.
### Where
`withPayload` now sets both `baseConfig.env.NEXT_BASE_PATH` **and**
`process.env.NEXT_BASE_PATH`, making `basePath` available everywhere.
Previously, users had to manually set `NEXT_BASE_PATH` in `.env` to work
around this.
##### Fixes #151111 parent 88a901c commit a8bfade
2 files changed
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
211 | 212 | | |
212 | 213 | | |
213 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
0 commit comments