Skip to content

Commit d0b70c9

Browse files
committed
Minify "no fallback UI specified" error in prod
This error message wasn't being minified because it doesn't use invariant. The reason it didn't use invariant is because this particular error is created without begin thrown — it doesn't need to be thrown because it's located inside the error handling part of the runtime. Now that the error minification script supports Error constructors, we can minify it by assigning it a production error code in `scripts/error-codes/codes.json`. To support the use of Error constructors more generally, I will add a lint rule that enforces each message has a corresponding error code.
1 parent b45acaa commit d0b70c9

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

packages/react-reconciler/src/ReactFiberThrow.new.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ function throwException(
474474
return;
475475
} else {
476476
// No boundary was found. Fallthrough to error mode.
477-
// TODO: Use invariant so the message is stripped in prod?
477+
// TODO: We should never call getComponentNameFromFiber in production.
478+
// Log a warning or something to prevent us from accidentally bundling it.
478479
value = new Error(
479480
(getComponentNameFromFiber(sourceFiber) || 'A React component') +
480481
' suspended while rendering, but no fallback UI was specified.\n' +

packages/react-reconciler/src/ReactFiberThrow.old.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ function throwException(
474474
return;
475475
} else {
476476
// No boundary was found. Fallthrough to error mode.
477-
// TODO: Use invariant so the message is stripped in prod?
477+
// TODO: We should never call getComponentNameFromFiber in production.
478+
// Log a warning or something to prevent us from accidentally bundling it.
478479
value = new Error(
479480
(getComponentNameFromFiber(sourceFiber) || 'A React component') +
480481
' suspended while rendering, but no fallback UI was specified.\n' +

scripts/error-codes/codes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,5 +394,6 @@
394394
"405": "hydrateRoot(...): Target container is not a DOM element.",
395395
"406": "act(...) is not supported in production builds of React.",
396396
"407": "Missing getServerSnapshot, which is required for server-rendered content. Will revert to client rendering.",
397-
"408": "Missing getServerSnapshot, which is required for server-rendered content."
397+
"408": "Missing getServerSnapshot, which is required for server-rendered content.",
398+
"409": "%s suspended while rendering, but no fallback UI was specified.\n\nAdd a <Suspense fallback=...> component higher in the tree to provide a loading indicator or placeholder to display."
398399
}

0 commit comments

Comments
 (0)