stack/packages/stack-shared/src/utils/monkey-patch.tsx
BilalG1 a64055cfca
Hosted components (#1229)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a new "Hosted Components" app with its own app shell, routing,
auth-aware UI, a handler route, and a welcome page showing the signed-in
user.
* **Chores**
* Added dev tooling and configuration for the new app (build, lint,
typecheck, Vite/TS, package manifest) and updated dev env API URL.
* **Tests**
  * Excluded the new app from the test workspace.
* **Bug Fixes**
* Suppressed noisy console errors for a specific internal sentinel and
clarified related error messaging.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Konstantin Wohlwend <n2d4xc@gmail.com>
2026-03-10 11:29:05 -07:00

30 lines
1.3 KiB
TypeScript

import { createGlobal } from "./globals";
export const NO_SUSPENSE_BOUNDARY_ERROR_SENTINEL = "__stack-no-suspense-boundary-error__";
export function isNoSuspenseBoundaryError(value: unknown): boolean {
return (
typeof value === "object"
&& value !== null
&& (value as Record<string, unknown>).__noSuspenseBoundarySentinel === NO_SUSPENSE_BOUNDARY_ERROR_SENTINEL
);
}
export function ensureMonkeyPatch() {
createGlobal("__console-error-monkey-patch__", () => {
const originalConsoleError = console.error;
console.error = function (...args: unknown[]) {
// React's default error handlers will log all errors to the console, even those that we intentionally use to suppress SSR.
// Next.js among others override the default error handler and will not log SSR errors to the console.
// However, vanilla React and other frameworks like TanStack Start use the default error handler.
// Hence, we suppress the error here if it is a NoSuspenseBoundaryError.
// It's very cursed, but it's really our best option. Talk to @konsti if you want to know more.
if (args.length === 1 && isNoSuspenseBoundaryError(args[0])) {
return;
}
return originalConsoleError.apply(this, args);
};
return true;
});
}