-
Notifications
You must be signed in to change notification settings - Fork 951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increase memory for server function on Next.js with image optimization #7940
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,13 +55,14 @@ | |
import { logger } from "../logger"; | ||
import { WebFrameworks } from "./frameworks"; | ||
import { constructDefaultWebSetup } from "../fetchWebSetup"; | ||
import { isUsingImageOptimization } from "./next/utils"; | ||
|
||
export { WebFrameworks }; | ||
|
||
/** | ||
* | ||
*/ | ||
export async function discover(dir: string, warn = true) { | ||
const allFrameworkTypes = [ | ||
...new Set(Object.values(WebFrameworks).map(({ type }) => type)), | ||
].sort(); | ||
|
@@ -91,18 +92,18 @@ | |
function memoizeBuild( | ||
dir: string, | ||
build: Framework["build"], | ||
deps: any[], | ||
target: string, | ||
context: FrameworkContext, | ||
): ReturnType<Framework["build"]> { | ||
const key = [dir, ...deps]; | ||
for (const existingKey of BUILD_MEMO.keys()) { | ||
if (isDeepStrictEqual(existingKey, key)) { | ||
return BUILD_MEMO.get(existingKey) as ReturnType<Framework["build"]>; | ||
} | ||
} | ||
const value = build(dir, target, context); | ||
BUILD_MEMO.set(key, value); | ||
return value; | ||
} | ||
|
||
|
@@ -110,7 +111,7 @@ | |
* Use a function to ensure the same codebase name is used here and | ||
* during hosting deploy. | ||
*/ | ||
export function generateSSRCodebaseId(site: string) { | ||
return `firebase-frameworks-${site}`; | ||
} | ||
|
||
|
@@ -176,7 +177,7 @@ | |
`Hosting config for site ${site} places server-side content in region ${ssrRegion} which is not known. Valid regions are ${validRegions}`, | ||
); | ||
} | ||
const getProjectPath = (...args: string[]) => join(projectRoot, source, ...args); | ||
// Combined traffic tag (19 chars) and functionId cannot exceed 46 characters. | ||
const functionId = `ssr${site.toLowerCase().replace(/-/g, "").substring(0, 20)}`; | ||
const usesFirebaseAdminSdk = !!findDependency("firebase-admin", { cwd: getProjectPath() }); | ||
|
@@ -214,11 +215,11 @@ | |
if (selectedSite) { | ||
const { appId } = selectedSite; | ||
if (appId) { | ||
firebaseConfig = isDemoProject | ||
? constructDefaultWebSetup(project) | ||
: await getAppConfig(appId, AppPlatform.WEB); | ||
firebaseDefaults ||= {}; | ||
firebaseDefaults.config = firebaseConfig; | ||
} else { | ||
const defaultConfig = await implicitInit(options); | ||
if (defaultConfig.json) { | ||
|
@@ -227,7 +228,7 @@ | |
You can link a Web app to a Hosting site here https://console.firebase.google.com/project/${project}/settings/general/web`, | ||
); | ||
firebaseDefaults ||= {}; | ||
firebaseDefaults.config = JSON.parse(defaultConfig.json); | ||
} else { | ||
// N.B. None of us know when this can ever happen and the deploy would | ||
// still succeed. Maaaaybe if someone tried calling firebase serve | ||
|
@@ -363,7 +364,7 @@ | |
|
||
const codebase = generateSSRCodebaseId(site); | ||
const existingFunctionsConfig = options.config.get("functions") | ||
? [].concat(options.config.get("functions")) | ||
: []; | ||
options.config.set("functions", [ | ||
...existingFunctionsConfig, | ||
|
@@ -538,6 +539,12 @@ | |
|
||
// TODO move to templates | ||
|
||
if (frameworksBackend && framework === "next") { | ||
if (await isUsingImageOptimization(getProjectPath(), ".next")) { | ||
chalosalvador marked this conversation as resolved.
Show resolved
Hide resolved
|
||
frameworksBackend.memory = "512MiB"; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of doing it here, I’d move this to the Next.js files and return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I refactored this to do it in the Next.js file. |
||
|
||
if (packageJson.type === "module") { | ||
await writeFile( | ||
join(functionsDist, "server.js"), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we need to do this only for Next 15?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memory issue is happening on Next 14 and 13 as well 🫠