1
0
mirror of synced 2026-02-04 12:08:33 -05:00

Compare commits

...

11 Commits

Author SHA1 Message Date
Brandon Bayer
e08e9a348a fixes 2023-06-09 12:38:56 -04:00
Siddharth Suresh
f0f66c6214 make code cleaner 2023-06-09 21:16:45 +05:30
Siddharth Suresh
37e7614f0c Update .changeset/good-oranges-pretend.md 2023-06-09 19:33:32 +05:30
Siddharth Suresh
617f20fb21 imporve the changelog 2023-06-09 19:08:27 +05:30
Siddharth Suresh
a5bbfe2187 make vercel default to true 2023-06-09 19:03:03 +05:30
Siddharth Suresh
d89c3ac8cf add resolversDynamicImport configuration 2023-06-08 20:38:59 +05:30
Siddharth Suresh
d0e4308d81 Merge branch 'main' into jayu-fix-dev-server-memory 2023-06-06 19:07:38 +05:30
Siddharth Suresh
5203e7e6ff Merge branch 'main' into jayu-fix-dev-server-memory 2023-06-05 19:34:29 +05:30
Siddharth Suresh
860d21bea3 Merge branch 'main' into jayu-fix-dev-server-memory 2023-06-05 19:30:15 +05:30
Jakub Mazurek (@jayu)
f3c64ffbaf chore: add changeset file 2023-05-22 20:44:01 +02:00
Jakub Mazurek
44169979ef fix: enormous dev server memory consumption 2023-05-22 20:24:59 +02:00
7 changed files with 46 additions and 18 deletions

View File

@@ -0,0 +1,26 @@
---
"@blitzjs/rpc": patch
---
Fixes enormous memory consumption of the dev server by changing the default import strategy to "require" instead of "import" which in webpack causes multiple chunks to be created for each import.
## Blitz Configuration
To configure this behaviour, you can add the following to your next.config.js:
```js
/**
* @type {import('@blitzjs/next').BlitzConfig}
**/
const config = {
blitz: {
resolversDynamicImport: true,
},
}
```
When `resolversDynamicImport` is set to `true`, the import strategy will be "import" instead of "require".
### On Vercel
If you are using Vercel, `resolversDynamicImport` will be set to `true` by default, since it is better for the separate chunks to be create for serverless lambdas.

View File

@@ -6,6 +6,9 @@ const { withBlitz } = require("@blitzjs/next")
**/
const config = {
reactStrictMode: true,
blitz: {
resolversDynamicImport: true,
},
}
module.exports = withBlitz(withNextAuthAdapter(config))

View File

@@ -230,6 +230,7 @@ export const setupBlitzServer = <TPlugins extends readonly BlitzServerPlugin<obj
export interface BlitzConfig extends NextConfig {
blitz?: {
resolverPath?: ResolverPathOptions
resolversDynamicImport?: boolean
includeRPCFolders?: string[]
customServer?: {
hotReload?: boolean
@@ -261,6 +262,8 @@ export function withBlitz(nextConfig: BlitzConfig = {}): NextConfig {
webpackConfig: config,
webpackRuleOptions: {
resolverPath: nextConfig.blitz?.resolverPath,
resolversDynamicImport:
nextConfig.blitz?.resolversDynamicImport ?? Boolean(process.env.VERCEL),
includeRPCFolders: nextConfig.blitz?.includeRPCFolders,
},
})

View File

@@ -3,6 +3,7 @@ import {NextApiRequest, NextApiResponse} from "next"
import {deserialize, parse, serialize as superjsonSerialize} from "superjson"
import {resolve} from "path"
import chalk from "chalk"
import {LoaderOptions} from "./server/loader/utils/loader-utils"
// TODO - optimize end user server bundles by not exporting all client stuff here
export * from "./index-browser"
@@ -60,16 +61,11 @@ const loaderClient = resolve(dir, "./loader-client.cjs")
const loaderServer = resolve(dir, "./loader-server.cjs")
const loaderServerResolvers = resolve(dir, "./loader-server-resolvers.cjs")
interface WebpackRuleOptions {
resolverPath: ResolverPathOptions | undefined
includeRPCFolders: string[] | undefined
}
interface WebpackRule {
test: RegExp
use: Array<{
loader: string
options: WebpackRuleOptions
options: LoaderOptions
}>
}
@@ -84,7 +80,7 @@ export interface InstallWebpackConfigOptions {
rules: WebpackRule[]
}
}
webpackRuleOptions: WebpackRuleOptions
webpackRuleOptions: LoaderOptions
}
export function installWebpackConfig({
@@ -165,6 +161,7 @@ export function rpcHandler(config: RpcConfig) {
const routePath = "/" + relativeRoutePath
const log = baseLogger().getSubLogger({
name: "blitz-rpc",
prefix: [routePath.replace(/(\/api\/rpc)?\//, "") + "()"],
})
const customChalk = new chalk.Instance({
@@ -220,7 +217,7 @@ export function rpcHandler(config: RpcConfig) {
const startTime = Date.now()
const result = await resolver(data, (res as any).blitzCtx)
const resolverDuration = Date.now() - startTime
log.debug(customChalk.dim("Result:"), result ? result : JSON.stringify(result))
log.info(customChalk.dim("Result:"), result ? result : JSON.stringify(result))
const serializerStartTime = Date.now()
const serializedResult = superjsonSerialize(result)
@@ -242,7 +239,7 @@ export function rpcHandler(config: RpcConfig) {
const serializerDuration = Date.now() - serializerStartTime
const duration = Date.now() - startTime
log.info(
log.debug(
customChalk.dim(
`Finished: resolver:${prettyMs(resolverDuration)} serializer:${prettyMs(
serializerDuration,

View File

@@ -64,12 +64,14 @@ export async function transformBlitzRpcServer(
extraRpcBasePaths: options?.includeRPCFolders,
})
code += `__internal_addBlitzRpcResolver('${routePath}',() => import('${slash(
const importStrategy = options?.resolversDynamicImport ? "import" : "require"
code += `__internal_addBlitzRpcResolver('${routePath}',() => ${importStrategy}('${slash(
resolverFilePath,
)}'));`
code += "\n"
}
// console.log("NEW CODE", code)
return code
}

View File

@@ -5,6 +5,7 @@ import {ResolverPathOptions} from "../../../index-server"
export interface LoaderOptions {
resolverPath: ResolverPathOptions
includeRPCFolders?: string[]
resolversDynamicImport?: boolean
}
export interface Loader {

View File

@@ -22,15 +22,11 @@ export const baseLogger = (options: BlitzLoggerSettings = {}): Logger<ILogObj> =
export const BlitzLogger = (settings: BlitzLoggerSettings = {}) => {
const baseLogger = new Logger({
minLevel: 3,
type: "pretty",
prettyLogTemplate:
process.env.NODE_ENV === "production"
? "{{yyyy}}-{{mm}}-{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}"
: "{{hh}}:{{MM}}:{{ss}}:{{ms}}",
prettyLogTimeZone: process.env.NODE_ENV === "production" ? "UTC" : "local",
maskValuesOfKeys: ["password", "passwordConfirmation", "currentPassword"],
// exposeErrorCodeFrame: process.env.NODE_ENV !== "production",
type: process.env.NODE_ENV === "production" ? "json" : "pretty",
prettyLogTemplate:
"{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t[{{filePathWithLine}}{{name}}]\t",
...settings,
})