payload-react-router 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +263 -2
- package/dist/client/PayloadRootProviders.d.ts +22 -0
- package/dist/client/PayloadRootProviders.js +29 -0
- package/dist/client/PayloadRootProviders.js.map +1 -0
- package/dist/client/RouterAdapter.d.ts +14 -0
- package/dist/client/RouterAdapter.js +64 -0
- package/dist/client/RouterAdapter.js.map +1 -0
- package/dist/client/navigation.d.ts +11 -0
- package/dist/client/navigation.js +31 -0
- package/dist/client/navigation.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +3 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/server.d.ts +10 -0
- package/dist/exports/server.js +11 -0
- package/dist/exports/server.js.map +1 -0
- package/dist/exports/vite.d.ts +1 -0
- package/dist/exports/vite.js +2 -0
- package/dist/exports/vite.js.map +1 -0
- package/dist/server/adminPage.d.ts +50 -0
- package/dist/server/adminPage.js +136 -0
- package/dist/server/adminPage.js.map +1 -0
- package/dist/server/auth.d.ts +16 -0
- package/dist/server/auth.js +17 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/cookies.d.ts +3 -0
- package/dist/server/cookies.js +27 -0
- package/dist/server/cookies.js.map +1 -0
- package/dist/server/graphql.d.ts +9 -0
- package/dist/server/graphql.js +114 -0
- package/dist/server/graphql.js.map +1 -0
- package/dist/server/initAdminContext.d.ts +17 -0
- package/dist/server/initAdminContext.js +39 -0
- package/dist/server/initAdminContext.js.map +1 -0
- package/dist/server/layout.d.ts +28 -0
- package/dist/server/layout.js +37 -0
- package/dist/server/layout.js.map +1 -0
- package/dist/server/middleware.d.ts +16 -0
- package/dist/server/middleware.js +35 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/requestStore.d.ts +29 -0
- package/dist/server/requestStore.js +54 -0
- package/dist/server/requestStore.js.map +1 -0
- package/dist/server/rest.d.ts +34 -0
- package/dist/server/rest.js +54 -0
- package/dist/server/rest.js.map +1 -0
- package/dist/server/searchParams.d.ts +6 -0
- package/dist/server/searchParams.js +13 -0
- package/dist/server/searchParams.js.map +1 -0
- package/dist/server/serverAdapter.d.ts +28 -0
- package/dist/server/serverAdapter.js +79 -0
- package/dist/server/serverAdapter.js.map +1 -0
- package/dist/server/serverFunctions.d.ts +21 -0
- package/dist/server/serverFunctions.js +25 -0
- package/dist/server/serverFunctions.js.map +1 -0
- package/dist/vite/config/external.d.ts +43 -0
- package/dist/vite/config/external.js +102 -0
- package/dist/vite/config/external.js.map +1 -0
- package/dist/vite/config/optimizeDeps.d.ts +24 -0
- package/dist/vite/config/optimizeDeps.js +162 -0
- package/dist/vite/config/optimizeDeps.js.map +1 -0
- package/dist/vite/config/scss.d.ts +13 -0
- package/dist/vite/config/scss.js +29 -0
- package/dist/vite/config/scss.js.map +1 -0
- package/dist/vite/devConfigReload.d.ts +13 -0
- package/dist/vite/devConfigReload.js +74 -0
- package/dist/vite/devConfigReload.js.map +1 -0
- package/dist/vite/devConfigReload.server.d.ts +1 -0
- package/dist/vite/devConfigReload.server.js +62 -0
- package/dist/vite/devConfigReload.server.js.map +1 -0
- package/dist/vite/devConfigReloadEvent.d.ts +8 -0
- package/dist/vite/devConfigReloadEvent.js +9 -0
- package/dist/vite/devConfigReloadEvent.js.map +1 -0
- package/dist/vite/index.d.ts +31 -0
- package/dist/vite/index.js +148 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/workarounds/clientModuleResolution.d.ts +13 -0
- package/dist/vite/workarounds/clientModuleResolution.js +80 -0
- package/dist/vite/workarounds/clientModuleResolution.js.map +1 -0
- package/dist/vite/workarounds/reactDomServerInRsc.d.ts +26 -0
- package/dist/vite/workarounds/reactDomServerInRsc.js +84 -0
- package/dist/vite/workarounds/reactDomServerInRsc.js.map +1 -0
- package/dist/vite/workarounds/stripDistStyleImports.d.ts +20 -0
- package/dist/vite/workarounds/stripDistStyleImports.js +140 -0
- package/dist/vite/workarounds/stripDistStyleImports.js.map +1 -0
- package/dist/vite/workarounds/stubPrettierInClient.d.ts +12 -0
- package/dist/vite/workarounds/stubPrettierInClient.js +32 -0
- package/dist/vite/workarounds/stubPrettierInClient.js.map +1 -0
- package/dist/vite/workarounds/wrapCjsForClient.d.ts +14 -0
- package/dist/vite/workarounds/wrapCjsForClient.js +104 -0
- package/dist/vite/workarounds/wrapCjsForClient.js.map +1 -0
- package/package.json +79 -4
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
/**
|
|
5
|
+
* SCSS `@import`/`@use` importers applied for every Payload consumer.
|
|
6
|
+
*
|
|
7
|
+
* Resolves webpack-style `~@payloadcms/...` tilde specifiers (emitted by
|
|
8
|
+
* first-party Payload package styles, e.g. `@payloadcms/richtext-slate`) to the
|
|
9
|
+
* installed package via Node resolution. Because it goes through the package's
|
|
10
|
+
* `exports` map, it picks the workspace `src` scss in the monorepo and the
|
|
11
|
+
* published `dist` scss in a consumer install automatically — no per-app
|
|
12
|
+
* `findFileUrl` shim needed.
|
|
13
|
+
*/
|
|
14
|
+
export const payloadScssImporters = [
|
|
15
|
+
{
|
|
16
|
+
findFileUrl(url) {
|
|
17
|
+
if (!url.startsWith('~@payloadcms/')) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return pathToFileURL(require.resolve(url.slice(1)));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
//# sourceMappingURL=scss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scss.js","sourceRoot":"","sources":["../../../src/vite/config/scss.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC;QACE,WAAW,CAAC,GAAW;YACrB,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;gBACrC,OAAO,IAAI,CAAA;YACb,CAAC;YACD,IAAI,CAAC;gBACH,OAAO,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACrD,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;KACF;CACF,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Reloads Payload when `payload.config.ts`, or anything it imports, changes.
|
|
4
|
+
*
|
|
5
|
+
* Vite re-evaluates the config module on its own, but `getPayload` keeps
|
|
6
|
+
* serving its cached instance until a `DevReloadStrategy` marks it stale. This
|
|
7
|
+
* plugin only broadcasts the change; `devConfigReload.server.ts` subscribes
|
|
8
|
+
* from inside the server runtime and marks the instance, which `getPayload`
|
|
9
|
+
* then reloads on its next call.
|
|
10
|
+
*/
|
|
11
|
+
export declare function payloadDevConfigReload({ payloadConfigPath, }: {
|
|
12
|
+
payloadConfigPath: string;
|
|
13
|
+
}): PluginOption;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { normalizePath } from 'vite';
|
|
3
|
+
import { PAYLOAD_CONFIG_CHANGED_EVENT } from "./devConfigReloadEvent.js";
|
|
4
|
+
/**
|
|
5
|
+
* Reloads Payload when `payload.config.ts`, or anything it imports, changes.
|
|
6
|
+
*
|
|
7
|
+
* Vite re-evaluates the config module on its own, but `getPayload` keeps
|
|
8
|
+
* serving its cached instance until a `DevReloadStrategy` marks it stale. This
|
|
9
|
+
* plugin only broadcasts the change; `devConfigReload.server.ts` subscribes
|
|
10
|
+
* from inside the server runtime and marks the instance, which `getPayload`
|
|
11
|
+
* then reloads on its next call.
|
|
12
|
+
*/
|
|
13
|
+
export function payloadDevConfigReload({ payloadConfigPath, }) {
|
|
14
|
+
const configFile = normalizePath(path.resolve(payloadConfigPath));
|
|
15
|
+
let server;
|
|
16
|
+
// Vite runs `hotUpdate` once per environment (client, ssr, rsc) per change,
|
|
17
|
+
// sharing one timestamp; without this the notice prints three times.
|
|
18
|
+
let lastHandled = '';
|
|
19
|
+
return {
|
|
20
|
+
name: 'payload:dev-config-reload',
|
|
21
|
+
apply: 'serve',
|
|
22
|
+
configureServer(devServer) {
|
|
23
|
+
server = devServer;
|
|
24
|
+
},
|
|
25
|
+
hotUpdate({ file, modules, timestamp }) {
|
|
26
|
+
if (!server) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const changeKey = `${file}:${timestamp}`;
|
|
30
|
+
if (changeKey === lastHandled) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!affectsPayloadConfig({ configFile, file, modules })) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
lastHandled = changeKey;
|
|
37
|
+
server.config.logger.info(`payload config changed, reloading Payload (${path.basename(file)})`, { timestamp: true });
|
|
38
|
+
// Broadcast to every environment rather than just `this.environment`: the
|
|
39
|
+
// changed module may only be in the graph of the environment that saw it,
|
|
40
|
+
// while the Payload instance was built in another. Each environment's
|
|
41
|
+
// runtime subscribes with its own copy of `payload`, and environments with
|
|
42
|
+
// no subscriber (e.g. `client`) simply ignore the event.
|
|
43
|
+
for (const environment of Object.values(server.environments)) {
|
|
44
|
+
environment.hot.send({ type: 'custom', event: PAYLOAD_CONFIG_CHANGED_EVENT });
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether `file` is the Payload config or something it imports. Walks *up*
|
|
51
|
+
* through importers, since the config sits at the root of that subtree.
|
|
52
|
+
*/
|
|
53
|
+
function affectsPayloadConfig({ configFile, file, modules, }) {
|
|
54
|
+
if (normalizePath(file) === configFile) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
const seen = new Set();
|
|
58
|
+
const queue = [...modules];
|
|
59
|
+
while (queue.length > 0) {
|
|
60
|
+
const mod = queue.pop();
|
|
61
|
+
if (seen.has(mod)) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
seen.add(mod);
|
|
65
|
+
if (mod.file && normalizePath(mod.file) === configFile) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
for (const importer of mod.importers) {
|
|
69
|
+
queue.push(importer);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=devConfigReload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devConfigReload.js","sourceRoot":"","sources":["../../src/vite/devConfigReload.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAEpC,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAExE;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,iBAAiB,GAGlB;IACC,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAA;IAEjE,IAAI,MAAiC,CAAA;IAErC,4EAA4E;IAC5E,qEAAqE;IACrE,IAAI,WAAW,GAAG,EAAE,CAAA;IAEpB,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,KAAK,EAAE,OAAO;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CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,EAAG,CAAA;QAExB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,SAAQ;QACV,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEb,IAAI,GAAG,CAAC,IAAI,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;YACvD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,KAAK,MAAM,QAAQ,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;YACrC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { registerDevReloadStrategy } from 'payload';
|
|
2
|
+
import { PAYLOAD_CONFIG_CHANGED_EVENT } from "./devConfigReloadEvent.js";
|
|
3
|
+
/**
|
|
4
|
+
* Subscribes the Payload instance to the config-changed event that the
|
|
5
|
+
* `payload:dev-config-reload` Vite plugin broadcasts.
|
|
6
|
+
*
|
|
7
|
+
* Imported for its side effect by `initAdminContext.server.ts`, the adapter's only
|
|
8
|
+
* `getPayload` call site, so the strategy is registered before an instance can
|
|
9
|
+
* be built. Registration is module-scoped on both ends: this runs inside the
|
|
10
|
+
* app's server graph and so resolves the same copy of `payload` that
|
|
11
|
+
* `getPayload` is called on, and each Vite environment (`ssr`, `rsc`) registers
|
|
12
|
+
* its own listener against its own copy.
|
|
13
|
+
*
|
|
14
|
+
* Vite re-evaluates this module on a program reload, which drops the listeners
|
|
15
|
+
* the previous instance had collected. `getPayload` reconnects on its next call
|
|
16
|
+
* because the registered strategy is a new object - see `connectDevReload`.
|
|
17
|
+
*
|
|
18
|
+
* `import.meta.hot` is only defined during dev serve, so this is inert in a
|
|
19
|
+
* production build.
|
|
20
|
+
*/
|
|
21
|
+
const hot = import.meta.hot;
|
|
22
|
+
if (hot) {
|
|
23
|
+
registerDevReloadStrategy(createConfigChangedStrategy({ hot }));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Builds a dev reload strategy that forwards the config-changed event to every
|
|
27
|
+
* connected instance.
|
|
28
|
+
*
|
|
29
|
+
* After a program reload, the first request to re-import this module replaces
|
|
30
|
+
* the old listener with a new one, but the cached Payload instance only connects
|
|
31
|
+
* to it on its next `getPayload` call - and a request such as a frontend page
|
|
32
|
+
* render may never make one. An event that lands in that gap has no one to
|
|
33
|
+
* notify, so it is held and replayed to the next connection instead of being
|
|
34
|
+
* dropped - which would otherwise leave the instance serving the old config
|
|
35
|
+
* indefinitely.
|
|
36
|
+
*/
|
|
37
|
+
function createConfigChangedStrategy({ hot }) {
|
|
38
|
+
const listeners = new Set();
|
|
39
|
+
let hasPendingReload = false;
|
|
40
|
+
hot.on(PAYLOAD_CONFIG_CHANGED_EVENT, () => {
|
|
41
|
+
if (listeners.size === 0) {
|
|
42
|
+
hasPendingReload = true;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
for (const onReload of listeners) {
|
|
46
|
+
onReload();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
connect: (onReload) => {
|
|
51
|
+
listeners.add(onReload);
|
|
52
|
+
if (hasPendingReload) {
|
|
53
|
+
hasPendingReload = false;
|
|
54
|
+
onReload();
|
|
55
|
+
}
|
|
56
|
+
return () => {
|
|
57
|
+
listeners.delete(onReload);
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=devConfigReload.server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devConfigReload.server.js","sourceRoot":"","sources":["../../src/vite/devConfigReload.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AAExE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,GAAG,GAAI,MAAM,CAAC,IAA4C,CAAC,GAAG,CAAA;AAEpE,IAAI,GAAG,EAAE,CAAC;IACR,yBAAyB,CAAC,2BAA2B,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;AACjE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,2BAA2B,CAAC,EAAE,GAAG,EAA2B;IAGnE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;IACvC,IAAI,gBAAgB,GAAG,KAAK,CAAA;IAE5B,GAAG,CAAC,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACxC,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACzB,gBAAgB,GAAG,IAAI,CAAA;YACvB,OAAM;QACR,CAAC;QAED,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,QAAQ,EAAE,CAAA;QACZ,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE;YACpB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YAEvB,IAAI,gBAAgB,EAAE,CAAC;gBACrB,gBAAgB,GAAG,KAAK,CAAA;gBACxB,QAAQ,EAAE,CAAA;YACZ,CAAC;YAED,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Vite HMR event the `payload:dev-config-reload` plugin broadcasts when
|
|
3
|
+
* the Payload config (or anything it imports) changes on disk.
|
|
4
|
+
*
|
|
5
|
+
* Kept in its own module so the Vite plugin can name the event without pulling
|
|
6
|
+
* in the server runtime — and therefore the whole CMS — when `vite.config.ts` loads.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PAYLOAD_CONFIG_CHANGED_EVENT = "payload:config-changed";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Vite HMR event the `payload:dev-config-reload` plugin broadcasts when
|
|
3
|
+
* the Payload config (or anything it imports) changes on disk.
|
|
4
|
+
*
|
|
5
|
+
* Kept in its own module so the Vite plugin can name the event without pulling
|
|
6
|
+
* in the server runtime — and therefore the whole CMS — when `vite.config.ts` loads.
|
|
7
|
+
*/
|
|
8
|
+
export const PAYLOAD_CONFIG_CHANGED_EVENT = 'payload:config-changed';
|
|
9
|
+
//# sourceMappingURL=devConfigReloadEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devConfigReloadEvent.js","sourceRoot":"","sources":["../../src/vite/devConfigReloadEvent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
export type PayloadVitePluginOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Extra packages kept external during `vite dev` only. List CommonJS deps that
|
|
5
|
+
* fail with `__cjs_module_runner_transform` under the RSC plugin.
|
|
6
|
+
*/
|
|
7
|
+
devServerExternalPackages?: string[];
|
|
8
|
+
/** Path to `payload.config.ts`; aliased as `@payload-config`. */
|
|
9
|
+
payloadConfigPath: string;
|
|
10
|
+
/** Drop Vite warnings about third-party sourcemaps. Defaults to `true`. */
|
|
11
|
+
silenceDependencyWarnings?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Vite plugin that makes Payload's admin panel build and run under React
|
|
15
|
+
* Router's RSC framework mode. Add it before React Router's plugins:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { unstable_reactRouterRSC as reactRouterRSC } from '@react-router/dev/vite'
|
|
19
|
+
* import rsc from '@vitejs/plugin-rsc'
|
|
20
|
+
* import { payload } from 'payload-react-router/vite'
|
|
21
|
+
*
|
|
22
|
+
* export default defineConfig({
|
|
23
|
+
* plugins: [payload({ payloadConfigPath: './payload.config.ts' }), reactRouterRSC(), rsc()],
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* The config mirrors `withPayload` from `@payloadcms/tanstack-start`: the
|
|
28
|
+
* `@payload-config` alias, SCSS importers, SSR externals, the optimizer
|
|
29
|
+
* allow/deny lists, and the Vite-level workarounds (all framework-agnostic).
|
|
30
|
+
*/
|
|
31
|
+
export declare function payload(options: PayloadVitePluginOptions): PluginOption[];
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createLogger } from 'vite';
|
|
3
|
+
import { buildExternalPackages, payloadNoExternalPatterns, ssrExternalPackages, } from "./config/external.js";
|
|
4
|
+
import { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from "./config/optimizeDeps.js";
|
|
5
|
+
import { payloadScssImporters } from "./config/scss.js";
|
|
6
|
+
import { payloadDevConfigReload } from "./devConfigReload.js";
|
|
7
|
+
import { clientModuleResolution } from "./workarounds/clientModuleResolution.js";
|
|
8
|
+
import { reactDomServerInRsc } from "./workarounds/reactDomServerInRsc.js";
|
|
9
|
+
import { ssrStripDistStyleImports } from "./workarounds/stripDistStyleImports.js";
|
|
10
|
+
import { stubPrettierInClient } from "./workarounds/stubPrettierInClient.js";
|
|
11
|
+
import { wrapCjsForClient } from "./workarounds/wrapCjsForClient.js";
|
|
12
|
+
const suppressibleWarningPatterns = [
|
|
13
|
+
'points to missing source files',
|
|
14
|
+
'Sourcemap for',
|
|
15
|
+
'Failed to load source map',
|
|
16
|
+
'references a map file outside its package',
|
|
17
|
+
];
|
|
18
|
+
function quietLogger() {
|
|
19
|
+
const logger = createLogger();
|
|
20
|
+
const shouldSuppress = (msg) => suppressibleWarningPatterns.some((pattern) => msg.includes(pattern));
|
|
21
|
+
const warn = logger.warn.bind(logger);
|
|
22
|
+
const warnOnce = logger.warnOnce.bind(logger);
|
|
23
|
+
logger.warn = (msg, options) => {
|
|
24
|
+
if (!shouldSuppress(msg)) {
|
|
25
|
+
warn(msg, options);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
logger.warnOnce = (msg, options) => {
|
|
29
|
+
if (!shouldSuppress(msg)) {
|
|
30
|
+
warnOnce(msg, options);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return logger;
|
|
34
|
+
}
|
|
35
|
+
const PUBLIC_ENV_PREFIXES = ['NEXT_PUBLIC_', 'PAYLOAD_PUBLIC_'];
|
|
36
|
+
/**
|
|
37
|
+
* Makes Payload's browser code safe to run without a `process` global:
|
|
38
|
+
* - `process.cwd()` → `"/"` (shared modules call it);
|
|
39
|
+
* - `process.env.X` → inlined value for `NEXT_PUBLIC_*` / `PAYLOAD_PUBLIC_*`,
|
|
40
|
+
* `undefined` otherwise — what Next.js does. `@payloadcms/ui`'s client bundle
|
|
41
|
+
* reads `process.env.NEXT_PUBLIC_ENABLE_ROUTER_CACHE_REFRESH`, which throws
|
|
42
|
+
* `ReferenceError: process is not defined` in a plain Vite client.
|
|
43
|
+
* `NODE_ENV` is left to Vite.
|
|
44
|
+
*/
|
|
45
|
+
function processInClient() {
|
|
46
|
+
return {
|
|
47
|
+
name: 'payload:process-in-client',
|
|
48
|
+
transform(code, id) {
|
|
49
|
+
const envName = this.environment?.name;
|
|
50
|
+
if (envName !== 'client' || !code.includes('process.')) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (id.includes('node_modules/.vite')) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const transformed = code
|
|
57
|
+
.replace(/process\.cwd\(\)/g, '"/"')
|
|
58
|
+
.replace(/process\.env\.([A-Z_][A-Z0-9_]*)/g, (match, name) => {
|
|
59
|
+
if (name === 'NODE_ENV') {
|
|
60
|
+
return match;
|
|
61
|
+
}
|
|
62
|
+
const isPublic = PUBLIC_ENV_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
63
|
+
return isPublic ? JSON.stringify(process.env[name]) ?? 'undefined' : 'undefined';
|
|
64
|
+
});
|
|
65
|
+
return transformed === code ? undefined : { code: transformed, map: null };
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Vite plugin that makes Payload's admin panel build and run under React
|
|
71
|
+
* Router's RSC framework mode. Add it before React Router's plugins:
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { unstable_reactRouterRSC as reactRouterRSC } from '@react-router/dev/vite'
|
|
75
|
+
* import rsc from '@vitejs/plugin-rsc'
|
|
76
|
+
* import { payload } from 'payload-react-router/vite'
|
|
77
|
+
*
|
|
78
|
+
* export default defineConfig({
|
|
79
|
+
* plugins: [payload({ payloadConfigPath: './payload.config.ts' }), reactRouterRSC(), rsc()],
|
|
80
|
+
* })
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* The config mirrors `withPayload` from `@payloadcms/tanstack-start`: the
|
|
84
|
+
* `@payload-config` alias, SCSS importers, SSR externals, the optimizer
|
|
85
|
+
* allow/deny lists, and the Vite-level workarounds (all framework-agnostic).
|
|
86
|
+
*/
|
|
87
|
+
export function payload(options) {
|
|
88
|
+
const { devServerExternalPackages = [], payloadConfigPath, silenceDependencyWarnings = true, } = options;
|
|
89
|
+
const configPlugin = {
|
|
90
|
+
name: 'payload:config',
|
|
91
|
+
config(_userConfig, env) {
|
|
92
|
+
const isBuild = env.command === 'build';
|
|
93
|
+
// `pluralize` ships a UMD wrapper that breaks under the dev SSR transform
|
|
94
|
+
// (kept external in dev), but must be bundled in the build because pnpm
|
|
95
|
+
// does not hoist it next to the server output.
|
|
96
|
+
const noExternal = isBuild ? [...payloadNoExternalPatterns, 'pluralize'] : payloadNoExternalPatterns;
|
|
97
|
+
const external = isBuild
|
|
98
|
+
? buildExternalPackages
|
|
99
|
+
: [...ssrExternalPackages, ...devServerExternalPackages];
|
|
100
|
+
const serverEnvironment = {
|
|
101
|
+
build: { rollupOptions: { external: buildExternalPackages } },
|
|
102
|
+
resolve: { external, noExternal },
|
|
103
|
+
};
|
|
104
|
+
const config = {
|
|
105
|
+
build: {
|
|
106
|
+
// lightningcss fails on the nested `@keyframes` in Payload's CSS.
|
|
107
|
+
cssMinify: 'esbuild',
|
|
108
|
+
},
|
|
109
|
+
css: {
|
|
110
|
+
preprocessorOptions: {
|
|
111
|
+
scss: {
|
|
112
|
+
importers: payloadScssImporters,
|
|
113
|
+
silenceDeprecations: ['import', 'global-builtin'],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
define: { global: 'globalThis' },
|
|
118
|
+
environments: {
|
|
119
|
+
rsc: serverEnvironment,
|
|
120
|
+
ssr: serverEnvironment,
|
|
121
|
+
},
|
|
122
|
+
optimizeDeps: {
|
|
123
|
+
exclude: optimizeDepsExcludeDefaults,
|
|
124
|
+
include: optimizeDepsIncludeDefaults,
|
|
125
|
+
},
|
|
126
|
+
resolve: {
|
|
127
|
+
alias: [{ find: '@payload-config', replacement: path.resolve(payloadConfigPath) }],
|
|
128
|
+
dedupe: ['react', 'react-dom', 'scheduler', '@payloadcms/ui', '@payloadcms/richtext-lexical'],
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
if (silenceDependencyWarnings) {
|
|
132
|
+
config.customLogger = quietLogger();
|
|
133
|
+
}
|
|
134
|
+
return config;
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
return [
|
|
138
|
+
configPlugin,
|
|
139
|
+
clientModuleResolution(),
|
|
140
|
+
wrapCjsForClient(),
|
|
141
|
+
ssrStripDistStyleImports(),
|
|
142
|
+
reactDomServerInRsc(),
|
|
143
|
+
stubPrettierInClient(),
|
|
144
|
+
processInClient(),
|
|
145
|
+
payloadDevConfigReload({ payloadConfigPath }),
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAA;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAA;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAA;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAA;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAcpE,MAAM,2BAA2B,GAAG;IAClC,gCAAgC;IAChC,eAAe;IACf,2BAA2B;IAC3B,2CAA2C;CAC5C,CAAA;AAED,SAAS,WAAW;IAClB,MAAM,MAAM,GAAG,YAAY,EAAE,CAAA;IAC7B,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE,CACrC,2BAA2B,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAA;IACtE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CA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,MAAM,GAAe;gBACzB,KAAK,EAAE;oBACL,kEAAkE;oBAClE,SAAS,EAAE,SAAS;iBACrB;gBACD,GAAG,EAAE;oBACH,mBAAmB,EAAE;wBACnB,IAAI,EAAE;4BACJ,SAAS,EAAE,oBAAoB;4BAC/B,mBAAmB,EAAE,CAAC,QAAQ,EAAE,gBAAgB,CAAC;yBACvB;qBAC7B;iBACF;gBACD,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE;gBAChC,YAAY,EAAE;oBACZ,GAAG,EAAE,iBAAiB;oBACtB,GAAG,EAAE,iBAAiB;iBACvB;gBACD,YAAY,EAAE;oBACZ,OAAO,EAAE,2BAA2B;oBACpC,OAAO,EAAE,2BAA2B;iBACrC;gBACD,OAAO,EAAE;oBACP,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;oBAClF,MAAM,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,8BAA8B,CAAC;iBAC9F;aACF,CAAA;YAED,IAAI,yBAAyB,EAAE,CAAC;gBAC9B,MAAM,CAAC,YAAY,GAAG,WAAW,EAAE,CAAA;YACrC,CAAC;YAED,OAAO,MAAM,CAAA;QACf,CAAC;KACF,CAAA;IAED,OAAO;QACL,YAAY;QACZ,sBAAsB,EAAE;QACxB,gBAAgB,EAAE;QAClB,wBAAwB,EAAE;QAC1B,mBAAmB,EAAE;QACrB,oBAAoB,EAAE;QACtB,eAAe,EAAE;QACjB,sBAAsB,CAAC,EAAE,iBAAiB,EAAE,CAAC;KAC9C,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Client-side module resolution:
|
|
4
|
+
* 1. Stubs RSC modules (`@payloadcms/.../rsc`) with no-op components so the
|
|
5
|
+
* Vite optimizer never tries to bundle their server implementations.
|
|
6
|
+
* 2. Redirects bare `payload` imports made from user code (outside of
|
|
7
|
+
* `node_modules` and our own packages) to `payload/shared`. The main
|
|
8
|
+
* `payload` entry has top-level side effects requiring Node.js APIs.
|
|
9
|
+
* 3. Resolves `/client` subpath exports for `@payloadcms/plugin-*` and
|
|
10
|
+
* `@payloadcms/storage-*` packages when normal Vite resolution fails in
|
|
11
|
+
* monorepo dev (no `dist/` built yet).
|
|
12
|
+
*/
|
|
13
|
+
export declare function clientModuleResolution(): PluginOption;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Client-side module resolution:
|
|
5
|
+
* 1. Stubs RSC modules (`@payloadcms/.../rsc`) with no-op components so the
|
|
6
|
+
* Vite optimizer never tries to bundle their server implementations.
|
|
7
|
+
* 2. Redirects bare `payload` imports made from user code (outside of
|
|
8
|
+
* `node_modules` and our own packages) to `payload/shared`. The main
|
|
9
|
+
* `payload` entry has top-level side effects requiring Node.js APIs.
|
|
10
|
+
* 3. Resolves `/client` subpath exports for `@payloadcms/plugin-*` and
|
|
11
|
+
* `@payloadcms/storage-*` packages when normal Vite resolution fails in
|
|
12
|
+
* monorepo dev (no `dist/` built yet).
|
|
13
|
+
*/
|
|
14
|
+
export function clientModuleResolution() {
|
|
15
|
+
const stubPrefix = '\0payload:server-stub:';
|
|
16
|
+
const serverOnlyPatterns = [
|
|
17
|
+
/^@payloadcms\/richtext-lexical\/rsc$/,
|
|
18
|
+
/^@payloadcms\/richtext-slate\/rsc$/,
|
|
19
|
+
/^@payloadcms\/next\/rsc$/,
|
|
20
|
+
];
|
|
21
|
+
const serverOnlyExports = {
|
|
22
|
+
'@payloadcms/next/rsc': ['CollectionCards', 'HierarchyTypeFieldServer'],
|
|
23
|
+
'@payloadcms/richtext-lexical/rsc': [
|
|
24
|
+
'RscEntryLexicalCell',
|
|
25
|
+
'RscEntryLexicalField',
|
|
26
|
+
'LexicalDiffComponent',
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
name: 'payload:client-module-resolution',
|
|
31
|
+
enforce: 'pre',
|
|
32
|
+
load(id) {
|
|
33
|
+
if (!id.startsWith(stubPrefix)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const specifier = id.slice(stubPrefix.length);
|
|
37
|
+
const exports = serverOnlyExports[specifier];
|
|
38
|
+
if (exports) {
|
|
39
|
+
return exports.map((name) => `export const ${name} = () => null;`).join('\n');
|
|
40
|
+
}
|
|
41
|
+
return `export default null;`;
|
|
42
|
+
},
|
|
43
|
+
async resolveId(id, importer, options) {
|
|
44
|
+
if (options?.ssr) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (serverOnlyPatterns.some((p) => p.test(id))) {
|
|
48
|
+
return stubPrefix + id;
|
|
49
|
+
}
|
|
50
|
+
if (id === 'payload' && importer && !importer.includes('/node_modules/')) {
|
|
51
|
+
const isPayloadPackage = /\/packages\/(?:payload|ui|richtext-|next)\//.test(importer);
|
|
52
|
+
if (!isPayloadPackage) {
|
|
53
|
+
return this.resolve('payload/shared', importer, { ...options, skipSelf: true });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (/^@payloadcms\/(?:plugin|storage)-[^/]+\/client$/.test(id)) {
|
|
57
|
+
const resolved = await this.resolve(id, importer, { ...options, skipSelf: true });
|
|
58
|
+
if (resolved) {
|
|
59
|
+
return resolved;
|
|
60
|
+
}
|
|
61
|
+
const pkgName = id.replace(/\/client$/, '');
|
|
62
|
+
const pkgResolved = await this.resolve(pkgName, importer, { ...options, skipSelf: true });
|
|
63
|
+
if (pkgResolved) {
|
|
64
|
+
const pkgDir = path.dirname(pkgResolved.id);
|
|
65
|
+
const candidates = [
|
|
66
|
+
path.resolve(pkgDir, 'src', 'exports', 'client.ts'),
|
|
67
|
+
path.resolve(pkgDir, 'src', 'exports', 'client.js'),
|
|
68
|
+
path.resolve(pkgDir, 'dist', 'exports', 'client.js'),
|
|
69
|
+
];
|
|
70
|
+
for (const candidate of candidates) {
|
|
71
|
+
if (fs.existsSync(candidate)) {
|
|
72
|
+
return candidate;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=clientModuleResolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientModuleResolution.js","sourceRoot":"","sources":["../../../src/vite/workarounds/clientModuleResolution.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,UAAU,GAAG,wBAAwB,CAAA;IAE3C,MAAM,kBAAkB,GAAa;QACnC,sCAAsC;QACtC,oCAAoC;QACpC,0BAA0B;KAE3B,CAAA;IAED,MAAM,iBAAiB,GAA6B;QAClD,sBAAsB,EAAE,CAAC,iBAAiB,EAAE,0BAA0B,CAAC;QACvE,kCAAkC,EAAE;YAClC,qBAAqB;YACrB,sBAAsB;YACtB,sBAAsB;SACvB;KACF,CAAA;IAED,OAAO;QACL,IAAI,EAAE,kCAAkC;QACxC,OAAO,EAAE,KAAK;QACd,IAAI,CAAC,EAAE;YACL,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/B,OAAM;YACR,CAAC;YACD,MAAM,SAAS,GAAG,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;YAC7C,MAAM,OAAO,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAA;YAC5C,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,IAAI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AAQ,EAAE,IAAI,EAAE,CAAC,CAAA;gBACzF,IAAI,WAAW,EAAE,CAAC;oBAChB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;oBAC3C,MAAM,UAAU,GAAG;wBACjB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC;wBACnD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC;wBACnD,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC;qBACrD,CAAA;oBACD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;wBACnC,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;4BAC7B,OAAO,SAAS,CAAA;wBAClB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Provides a working `react-dom/server` inside the RSC environment.
|
|
4
|
+
*
|
|
5
|
+
* Payload's version-diff converters (`@payloadcms/richtext-lexical`'s
|
|
6
|
+
* `field/Diff/converters/*` and `@payloadcms/ui`'s `Version/RenderFieldsToDiff`)
|
|
7
|
+
* call `renderToStaticMarkup` while rendering a Server Component. In the RSC
|
|
8
|
+
* environment Vite activates the `react-server` export condition, under which
|
|
9
|
+
* every `react-dom/server*` subpath resolves to `server.react-server.js` — a
|
|
10
|
+
* stub that throws `react-dom/server is not supported in React Server
|
|
11
|
+
* Components`. Force-resolving past the condition isn't enough either: the
|
|
12
|
+
* static renderer reads the *client* React internals
|
|
13
|
+
* (`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`), which
|
|
14
|
+
* the `react-server` build of `react` doesn't expose.
|
|
15
|
+
*
|
|
16
|
+
* So we pre-bundle a self-contained `react-dom/server` with client React
|
|
17
|
+
* inlined (esbuild, deliberately WITHOUT the `react-server` condition) and
|
|
18
|
+
* redirect `react-dom/server` to it in the RSC graph only. The bundle is fully
|
|
19
|
+
* self-contained, so the RSC environment's `react-server` condition can't
|
|
20
|
+
* reach into it. JSX elements created by the RSC-graph React stay renderable
|
|
21
|
+
* because React identifies elements via a process-global `Symbol.for(...)`.
|
|
22
|
+
*
|
|
23
|
+
* Delete this once `react-dom/server` (or an equivalent static renderer) is
|
|
24
|
+
* usable from the `react-server` condition without a separate bundle.
|
|
25
|
+
*/
|
|
26
|
+
export declare function reactDomServerInRsc(): PluginOption;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const REACT_DOM_SERVER_RE = /^react-dom\/server(?:\.(?:edge|node|browser))?$/;
|
|
4
|
+
/**
|
|
5
|
+
* Provides a working `react-dom/server` inside the RSC environment.
|
|
6
|
+
*
|
|
7
|
+
* Payload's version-diff converters (`@payloadcms/richtext-lexical`'s
|
|
8
|
+
* `field/Diff/converters/*` and `@payloadcms/ui`'s `Version/RenderFieldsToDiff`)
|
|
9
|
+
* call `renderToStaticMarkup` while rendering a Server Component. In the RSC
|
|
10
|
+
* environment Vite activates the `react-server` export condition, under which
|
|
11
|
+
* every `react-dom/server*` subpath resolves to `server.react-server.js` — a
|
|
12
|
+
* stub that throws `react-dom/server is not supported in React Server
|
|
13
|
+
* Components`. Force-resolving past the condition isn't enough either: the
|
|
14
|
+
* static renderer reads the *client* React internals
|
|
15
|
+
* (`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`), which
|
|
16
|
+
* the `react-server` build of `react` doesn't expose.
|
|
17
|
+
*
|
|
18
|
+
* So we pre-bundle a self-contained `react-dom/server` with client React
|
|
19
|
+
* inlined (esbuild, deliberately WITHOUT the `react-server` condition) and
|
|
20
|
+
* redirect `react-dom/server` to it in the RSC graph only. The bundle is fully
|
|
21
|
+
* self-contained, so the RSC environment's `react-server` condition can't
|
|
22
|
+
* reach into it. JSX elements created by the RSC-graph React stay renderable
|
|
23
|
+
* because React identifies elements via a process-global `Symbol.for(...)`.
|
|
24
|
+
*
|
|
25
|
+
* Delete this once `react-dom/server` (or an equivalent static renderer) is
|
|
26
|
+
* usable from the `react-server` condition without a separate bundle.
|
|
27
|
+
*/
|
|
28
|
+
export function reactDomServerInRsc() {
|
|
29
|
+
const RESOLVED_ID = '\0payload:react-dom-server-rsc';
|
|
30
|
+
let bundledCode;
|
|
31
|
+
const buildBundle = () => {
|
|
32
|
+
if (bundledCode !== undefined) {
|
|
33
|
+
return bundledCode;
|
|
34
|
+
}
|
|
35
|
+
// esbuild is always present as a Vite dependency. Typed loosely because it
|
|
36
|
+
// isn't a direct dependency of this package.
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const esbuild = require('esbuild');
|
|
39
|
+
const result = esbuild.buildSync({
|
|
40
|
+
banner: {
|
|
41
|
+
// The bundled CJS React DOM server build does `require('util')` etc.
|
|
42
|
+
// esbuild's ESM output otherwise emits a stub that throws "Dynamic
|
|
43
|
+
// require of ... is not supported" inside Vite's module runner, so wire
|
|
44
|
+
// up a real `require` for Node built-ins.
|
|
45
|
+
js: "import { createRequire as __pl_cr } from 'node:module';const require = __pl_cr(import.meta.url);",
|
|
46
|
+
},
|
|
47
|
+
bundle: true,
|
|
48
|
+
// Resolve react/react-dom to their CLIENT builds — NOT the `react-server`
|
|
49
|
+
// condition the RSC environment would otherwise apply.
|
|
50
|
+
conditions: ['node', 'import', 'default'],
|
|
51
|
+
define: { 'process.env.NODE_ENV': JSON.stringify('production') },
|
|
52
|
+
format: 'esm',
|
|
53
|
+
platform: 'node',
|
|
54
|
+
stdin: {
|
|
55
|
+
contents: [
|
|
56
|
+
"import * as ReactDOMServer from 'react-dom/server'",
|
|
57
|
+
"export * from 'react-dom/server'",
|
|
58
|
+
'export default ReactDOMServer',
|
|
59
|
+
].join('\n'),
|
|
60
|
+
loader: 'js',
|
|
61
|
+
resolveDir: process.cwd(),
|
|
62
|
+
},
|
|
63
|
+
write: false,
|
|
64
|
+
});
|
|
65
|
+
const code = result.outputFiles[0].text;
|
|
66
|
+
bundledCode = code;
|
|
67
|
+
return code;
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
name: 'payload:react-dom-server-in-rsc',
|
|
71
|
+
enforce: 'pre',
|
|
72
|
+
load(id) {
|
|
73
|
+
if (id === RESOLVED_ID) {
|
|
74
|
+
return buildBundle();
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
resolveId(id) {
|
|
78
|
+
if (this.environment?.name === 'rsc' && REACT_DOM_SERVER_RE.test(id)) {
|
|
79
|
+
return RESOLVED_ID;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=reactDomServerInRsc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactDomServerInRsc.js","sourceRoot":"","sources":["../../../src/vite/workarounds/reactDomServerInRsc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C,MAAM,mBAAmB,GAAG,iDAAiD,CAAA;AAE7E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,WAAW,GAAG,gCAAgC,CAAA;IACpD,IAAI,WAA+B,CAAA;IAEnC,MAAM,WAAW,GAAG,GAAW,EAAE;QAC/B,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,WAAW,CAAA;QACpB,CAAC;QACD,2EAA2E;Q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