Replies: 3 comments 2 replies
-
in module.exports = (phase, { defaultConfig }) => {
return {
...defaultConfig,
env: {
PHASE: phase
}
}
} then you can access this env variable from import db from "@/lib/db";
import TopKPlot from "./components/topk";
import { PHASE_PRODUCTION_BUILD } from "next/constants";
export default function({ params }: { params: any }) {
const { checkpoint } = params;
const topK = db.getTopK(checkpoint);
if (process.env.PHASE === PHASE_PRODUCTION_BUILD) {
// do whatever you want
}
return <TopKPlot checkpoint={checkpoint} y={topK} />;
} more info here |
Beta Was this translation helpful? Give feedback.
-
While it might be tempting to do so, it is perhaps better to let this route be dynamic by using, https://beta.nextjs.org/docs/api-reference/segment-config#dynamic export const dynamic = "force-dynamic" This way the page will behave more like GSSP, and only render when there's a checkpoint. You ought to handle lack of checkpoint data (at runtime) via |
Beta Was this translation helpful? Give feedback.
-
How about: /**
* Check if code is running as a result of `next build`
*/
export function isNextBuild() {
// eslint-disable-next-line turbo/no-undeclared-env-vars
return process.env["NEXT_PHASE"] === "phase-production-build";
} That's probably not a "public API" so could break in future but good enough for me. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the following server component:
I would like to check (inside the component) if
next build
is running. The reason being, ifnext build
is running--it looks like--next will pass in[checkpoint]
as the parameter value, instead of an actual valid parameter value (which makes sense).This causes the
db.getTopK
method to throw, which crashesnext build
.I am wondering how to avoid this scenario.
The obvious way is to check just wrap
getTopK
in a try-catch, but I'm wondering if there's a more elegant solution.More broadly, this would be useful for, e.g, avoiding loading my database when running
next build
. Right now,next build
will result in an import of@/lib/db
, but if I could check that@/lib/db
was running as part ofnext build,
then I would skip the expensive initialization step.Beta Was this translation helpful? Give feedback.
All reactions