Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 65 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
const allFrameworkTypes = [
...new Set(Object.values(WebFrameworks).map(({ type }) => type)),
].sort();
Expand Down Expand Up @@ -91,18 +92,18 @@
function memoizeBuild(
dir: string,
build: Framework["build"],
deps: any[],

Check warning on line 95 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
target: string,
context: FrameworkContext,
): ReturnType<Framework["build"]> {
const key = [dir, ...deps];

Check warning on line 99 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe spread of an `any` value in an array
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);

Check warning on line 106 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any[]` assigned to a parameter of type `string[]`
return value;
}

Expand All @@ -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) {

Check warning on line 114 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
return `firebase-frameworks-${site}`;
}

Expand Down Expand Up @@ -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);

Check warning on line 180 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
// 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() });
Expand Down Expand Up @@ -214,11 +215,11 @@
if (selectedSite) {
const { appId } = selectedSite;
if (appId) {
firebaseConfig = isDemoProject

Check warning on line 218 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
? constructDefaultWebSetup(project)
: await getAppConfig(appId, AppPlatform.WEB);
firebaseDefaults ||= {};
firebaseDefaults.config = firebaseConfig;

Check warning on line 222 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
} else {
const defaultConfig = await implicitInit(options);
if (defaultConfig.json) {
Expand All @@ -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);

Check warning on line 231 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
} 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
Expand Down Expand Up @@ -363,7 +364,7 @@

const codebase = generateSSRCodebaseId(site);
const existingFunctionsConfig = options.config.get("functions")
? [].concat(options.config.get("functions"))

Check warning on line 367 in src/frameworks/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `ConcatArray<never>`
: [];
options.config.set("functions", [
...existingFunctionsConfig,
Expand Down Expand Up @@ -538,6 +539,12 @@

// TODO move to templates

if (frameworksBackend && framework === "next") {
if (await isUsingImageOptimization(getProjectPath(), ".next")) {
Copy link
Member

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?

Copy link
Member Author

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 🫠

chalosalvador marked this conversation as resolved.
Show resolved Hide resolved
frameworksBackend.memory = "512MiB";
}
}
Copy link
Member

Choose a reason for hiding this comment

The 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 frameworksBackend overrides from ɵcodegenFunctionsDirectory, @jamesdaniels WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The 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"),
Expand Down
Loading