Unverified Commit 410c6580 authored by Josh Story's avatar Josh Story Committed by GitHub

Add static error when `unstable_instant` is used without `cacheComponents` (#90793)

`unstable_instant` requires `cacheComponents` to function — without it,
validation is entirely skipped and the config silently does nothing.
This adds a compile-time error in the SWC transform that catches the
misconfiguration early, matching the existing pattern used for segment
configs like `revalidate` that are incompatible with `cacheComponents`
(but inverted — `unstable_instant` requires it rather than being
incompatible with it). The error points directly to the export in the
user's source file.
parent dd4a97e1
......@@ -99,6 +99,7 @@ enum RSCErrorKind {
NextRscErrDeprecatedApi((String, String, Span)),
NextSsrDynamicFalseNotAllowed(Span),
NextRscErrIncompatibleRouteSegmentConfig(Span, String, NextConfigProperty),
NextRscErrRequiresRouteSegmentConfig(Span, String, NextConfigProperty),
NextRscErrTaintWithoutConfig((String, Span)),
}
......@@ -121,6 +122,7 @@ enum InvalidExportKind {
General,
Metadata,
RouteSegmentConfig(NextConfigProperty),
RequiresRouteSegmentConfig(NextConfigProperty),
}
impl<C: Comments> VisitMut for ReactServerComponents<C> {
......@@ -359,6 +361,10 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
format!("Route segment config \"{segment}\" is not compatible with `nextConfig.{property}`. Please remove it."),
vec![span],
),
RSCErrorKind::NextRscErrRequiresRouteSegmentConfig(span, segment, property) => (
format!("Route segment config \"{segment}\" requires `nextConfig.{property}` to be enabled."),
vec![span],
),
RSCErrorKind::NextRscErrTaintWithoutConfig((api_name, span)) => (
format!(
"You're importing `{api_name}` from React which requires `experimental.taint: true` in your Next.js config. Learn more: https://nextjs.org/docs/app/api-reference/config/next-config-js/taint"
......@@ -937,6 +943,19 @@ impl ReactServerComponentValidator {
);
}
}
"unstable_instant" => {
if !self.cache_components_enabled {
possibly_invalid_exports.insert(
export_name.clone(),
(
InvalidExportKind::RequiresRouteSegmentConfig(
NextConfigProperty::CacheComponents,
),
*span,
),
);
}
}
_ => (),
};
......@@ -979,6 +998,17 @@ impl ReactServerComponentValidator {
),
);
}
InvalidExportKind::RequiresRouteSegmentConfig(property) => {
report_error(
&self.app_dir,
&self.filepath,
RSCErrorKind::NextRscErrRequiresRouteSegmentConfig(
*span,
export_name.to_string(),
*property,
),
);
}
InvalidExportKind::Metadata => {
// Client entry can't export `generateMetadata` or `metadata`.
if is_client_entry
......
export const unstable_instant = {
prefetch: 'static'
};
export default function Page() {
return <div>Hello</div>;
}
export const unstable_instant = { prefetch: 'static' }
export default function Page() {
return <div>Hello</div>
}
export const unstable_instant = {
prefetch: 'static'
};
export default function Page() {
return <div>Hello</div>;
}
x Route segment config "unstable_instant" requires `nextConfig.cacheComponents` to be enabled.
,-[input.js:1:1]
1 | export const unstable_instant = { prefetch: 'static' }
: ^^^^^^^^^^^^^^^^
`----
export const unstable_instant = { prefetch: 'static' }
export default function Page() {
return <div>Hello</div>
}
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