Skip to content

Instantly share code, notes, and snippets.

@r1tsuu
Last active July 1, 2024 00:34
Show Gist options
  • Save r1tsuu/27cb56223d166620966edbcff44e6842 to your computer and use it in GitHub Desktop.
Save r1tsuu/27cb56223d166620966edbcff44e6842 to your computer and use it in GitHub Desktop.
Patch next with PR adds experimental serverOnlyDependencies property https://github.com/vercel/next.js/pull/65415
import { withPayload } from '@payloadcms/next/withPayload';
import { resolve } from 'path';
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverOnlyDependencies: [resolve(import.meta.dirname, 'payload.config.proxy.ts')],
},
};
export default withPayload(nextConfig);
diff --git a/dist/build/webpack/plugins/flight-client-entry-plugin.d.ts b/dist/build/webpack/plugins/flight-client-entry-plugin.d.ts
index 8f857af48d72f7b9f47f06c00748af5a14723271..860094a88efe78577860a51c8c27292abd7535ff 100644
--- a/dist/build/webpack/plugins/flight-client-entry-plugin.d.ts
+++ b/dist/build/webpack/plugins/flight-client-entry-plugin.d.ts
@@ -6,6 +6,7 @@ interface Options {
appDir: string;
isEdgeServer: boolean;
encryptionKey: string;
+ ignore: string[]
}
type Actions = {
[actionId: string]: {
@@ -25,6 +26,7 @@ export type ActionManifest = {
export declare class FlightClientEntryPlugin {
dev: boolean;
appDir: string;
+ ignore: string[]
encryptionKey: string;
isEdgeServer: boolean;
assetPrefix: string;
diff --git a/dist/build/webpack/plugins/flight-client-entry-plugin.js b/dist/build/webpack/plugins/flight-client-entry-plugin.js
index 6d3991896e21d38068c6c21a0592277de5d8471b..89e810bc5261dd5776745a70db6c5b933c3819b5 100644
--- a/dist/build/webpack/plugins/flight-client-entry-plugin.js
+++ b/dist/build/webpack/plugins/flight-client-entry-plugin.js
@@ -106,6 +106,7 @@ class FlightClientEntryPlugin {
constructor(options){
this.dev = options.dev;
this.appDir = options.appDir;
+ this.ignore = options.ignore
this.isEdgeServer = options.isEdgeServer;
this.assetPrefix = !this.dev && !this.isEdgeServer ? '../' : '';
this.encryptionKey = options.encryptionKey;
@@ -428,7 +429,7 @@ class FlightClientEntryPlugin {
if ((_mod_matchResource = mod.matchResource) == null ? void 0 : _mod_matchResource.startsWith(_constants1.BARREL_OPTIMIZATION_PREFIX)) {
modRequest = mod.matchResource + ':' + modRequest;
}
- if (!modRequest) return;
+ if (!modRequest || this.ignore.includes(modRequest)) return;
if (visited.has(modRequest)) {
if (clientComponentImports[modRequest]) {
addClientImport(mod, modRequest, clientComponentImports, importedIdentifiers, false);
diff --git a/dist/build/webpack-config.js b/dist/build/webpack-config.js
index 8cee018bbdbb82c0f84ca1659307155f2f73f360..e7c759a9c1071a1697b82de24a924b7460b31198 100644
--- a/dist/build/webpack-config.js
+++ b/dist/build/webpack-config.js
@@ -1518,7 +1518,8 @@ async function getBaseWebpackConfig(dir, { buildId, encryptionKey, config, compi
appDir,
dev,
isEdgeServer,
- encryptionKey
+ encryptionKey,
+ ignore: config.experimental.serverOnlyDependencies ?? [],
})),
hasAppDir && !isClient && new _nexttypesplugin.NextTypesPlugin({
dir,
diff --git a/dist/server/config-schema.js b/dist/server/config-schema.js
index 86fbccfca8f53d674b4fc880b9d70e2b2d5233f6..c5808c4c864e055cacabee4aea537e372c7522c2 100644
--- a/dist/server/config-schema.js
+++ b/dist/server/config-schema.js
@@ -281,6 +281,7 @@ const configSchema = _zod.z.lazy(()=>_zod.z.strictObject({
taint: _zod.z.boolean().optional(),
prerenderEarlyExit: _zod.z.boolean().optional(),
proxyTimeout: _zod.z.number().gte(0).optional(),
+ serverOnlyDependencies: _zod.z.array(_zod.z.string()).optional(),
scrollRestoration: _zod.z.boolean().optional(),
sri: _zod.z.object({
algorithm: _zod.z.enum([
diff --git a/dist/server/config-shared.d.ts b/dist/server/config-shared.d.ts
index c196d0f28ab2c83a6e1b1357241a2734ca93ee5f..1ae2ade2a63a4a9dfacee0440d5eef1581f522ee 100644
--- a/dist/server/config-shared.d.ts
+++ b/dist/server/config-shared.d.ts
@@ -235,6 +235,10 @@ export interface ExperimentalConfig {
adjustFontFallbacks?: boolean;
adjustFontFallbacksWithSizeAdjust?: boolean;
webVitalsAttribution?: Array<(typeof WEB_VITALS)[number]>;
+ /**
+ * A list of imports that should completely disable any client dependencies from being added to generated client JS.
+ */
+ serverOnlyDependencies?: string[]
/**
* Automatically apply the "modularizeImports" optimization to imports of the specified packages.
*/
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
}
// import config from here instead of @payload-config outside of app/(admin)
import config from './payload.config';
export default config;
@chmielulu
Copy link

thank you @r1tsuu @richardbutler!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment