Unverified Commit 37516d95 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: improve suggestions for experimental.reportSystemEnvInlining (#89486)

Some better suggestions
parent 44ab1be4
......@@ -116,22 +116,32 @@ pub fn free_var_references_with_vercel_system_env_warnings(
let message = match public_env_var {
"NEXT_PUBLIC_NEXT_DEPLOYMENT_ID" | "NEXT_PUBLIC_VERCEL_DEPLOYMENT_ID" => {
rcstr!(
"The deployment id is being inlined. Use `process.env.NEXT_DEPLOYMENT_ID` \
instead to access the same value without inlining, for faster deploy times \
and better browser client-side caching."
"The deployment id is being inlined.\nThis variable changes frequently, \
causing slower deploy times and worse browser client-side caching. Use \
`process.env.NEXT_DEPLOYMENT_ID` instead to access the same value without \
inlining, for faster deploy times and better browser client-side caching."
)
}
"NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA" => {
rcstr!(
"The commit hash is being inlined.\nThis variable changes frequently, causing \
slower deploy times and worse browser client-side caching. Consider using \
`process.env.NEXT_DEPLOYMENT_ID` to identify a deployment. Alternatively, \
use `process.env.VERCEL_GIT_COMMIT_SHA` in server side code and for browser \
code, remove it."
)
}
"NEXT_PUBLIC_VERCEL_BRANCH_URL" | "NEXT_PUBLIC_VERCEL_URL" => format!(
"The deployment url system environment variable is being inlined. This variable \
"The deployment url system environment variable is being inlined.\nThis variable \
changes frequently, causing slower deploy times and worse browser client-side \
caching. For server-side code, replace with `process.env.{}` and for browser \
code, read `location.origin` instead.",
code, read `location.host` instead.",
public_env_var.strip_prefix("NEXT_PUBLIC_").unwrap(),
)
.into(),
_ => format!(
"A system environment variable is being inlined. This variable changes on every \
deployment, causing slower deploy times and worse browser client-side caching. \
"A system environment variable is being inlined.\nThis variable changes \
frequently, causing slower deploy times and worse browser client-side caching. \
For server-side code, replace with `process.env.{}` and for browser code, try to \
remove it.",
public_env_var.strip_prefix("NEXT_PUBLIC_").unwrap(),
......
......@@ -16,13 +16,15 @@ import { getRedboxSource, waitForRedbox } from 'next-test-utils'
const error = await getRedboxSource(browser)
expect(error).toMatchInlineSnapshot(`
"./app/foo.tsx (2:14)
error TP1202 A system environment variable is being inlined. This variable changes on every deployment, causing slower deploy times and worse browser client-side caching. For server-side code, replace with \`process.env.VERCEL_GIT_COMMIT_SHA\` and for browser code, try to remove it.
TP1202 The commit hash is being inlined.
1 | export function Foo() {
> 2 | return <p>{process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA}</p>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | }
4 |
This variable changes frequently, causing slower deploy times and worse browser client-side caching. Consider using \`process.env.NEXT_DEPLOYMENT_ID\` to identify a deployment. Alternatively, use \`process.env.VERCEL_GIT_COMMIT_SHA\` in server side code and for browser code, remove it.
Import trace:
Server Component:
./app/foo.tsx
......
......@@ -111,15 +111,16 @@ impl Emitter for IssueEmitter {
.map(|s| s.0.as_ref())
.collect::<Vec<_>>()
.join("");
let code = db.code.as_ref().map(|d| match d {
DiagnosticId::Error(s) => format!("error {s}").into(),
DiagnosticId::Lint(s) => format!("lint {s}").into(),
});
let is_lint = db
.code
.as_ref()
.is_some_and(|d| matches!(d, DiagnosticId::Lint(_)));
let code = db.code.map(|d| match d {
DiagnosticId::Error(s) => s.into(),
DiagnosticId::Lint(s) => format!("lint {s}").into(),
});
let severity = if is_lint {
IssueSeverity::Suggestion
} else {
......@@ -140,8 +141,8 @@ impl Emitter for IssueEmitter {
title = t.clone();
} else {
let mut message_split = message.split('\n');
title = message_split.next().unwrap().to_string().into();
message = message_split.remainder().unwrap_or("").to_string();
title = message_split.next().unwrap().trim().to_string().into();
message = message_split.remainder().unwrap_or("").trim().to_string();
}
let source = db.span.primary_span().map(|span| {
......
warning - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/comptime/define/input/index.js:67:4 error TP1202 WARNED_VALUE is deprecated, use REPLACEMENT_VALUE instead
warning - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/comptime/define/input/index.js:67:4 TP1202 WARNED_VALUE is deprecated, use REPLACEMENT_VALUE instead
63 | console.log(__dirname)
64 |
......
warning - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/comptime/define/input/index.js:66:12 error TP1202 WARNED_VALUE is deprecated, use REPLACEMENT_VALUE instead
warning - [analysis] /turbopack/crates/turbopack-tests/tests/snapshot/comptime/define/input/index.js:66:12 TP1202 WARNED_VALUE is deprecated, use REPLACEMENT_VALUE instead
62 |
63 | console.log(__dirname)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment