Skip to content

feat(appkit): replace React Router's default error page with an AppKit error page - #749

Open
MarioCadenas wants to merge 9 commits into
mainfrom
work/17-replace-react-router-s-default
Open

MarioCadenas wants to merge 9 commits into
mainfrom
work/17-replace-react-router-s-default

Conversation

@MarioCadenas

Copy link
Copy Markdown
Collaborator

What

A route that throws in an AppKit app now shows an AppKit error page instead of React Router's built-in one. React Router's page says "Hey developer 👋" while developing, and in a production build it still shows "Unexpected Application Error!" with the error's message and stack, so deployed apps leaked stack traces.

  • ErrorPage in @databricks/appkit-ui/react (new, packages/appkit-ui/src/react/error-page.tsx):
    • It is built from Empty, Button and lucide icons. It says "Something went wrong" and offers Reload and Back to home.
    • A 404 route error response shows "Page not found", with the same actions.
    • The message and stack show only when import.meta.env.DEV is true. Building them never throws, even for a value String() can't convert, such as Object.create(null).
    • It doesn't depend on any router: pass React Router's useRouteError(), or the error TanStack Router gives an errorComponent. A route error response is recognised by its shape (numeric status, string statusText).
  • App template (template/client/src/App.tsx):
    • The root layout route gets errorElement: <RouteErrorPage />.
    • The page has the same text, actions and dev-only details, built from components the pinned appkit-ui already exports.
    • A 404 route error response shows "Page not found". In development, a route error response's details include its text when that is a string.
    • A route's own errorElement still wins.
  • Design pages (design plugin): the /design router gets ErrorPage as its root ErrorBoundary, for a page that fails to load or doesn't exist.
  • Playground:
    • The root CatchBoundary renders ErrorPage, replacing the playground's own error card, which showed the message in production too.
    • A new /error-page route (under Platform) throws on render to show it.
    • A new Playwright spec, tests/error-page.spec.ts, checks it: the page shows inside the layout, with Reload and Back to home, React Router's text is absent, and the dev server shows the thrown message.
  • Docs: docs/docs/api/appkit-ui/error-page.md covers what the page shows, how the template wires it, and how to replace it.

Why

End users of AppKit apps should never see React Router's developer page, or a stack trace from a deployed app.

Notes for reviewers

  • The template doesn't import ErrorPage. The template pins the published @databricks/appkit-ui, which doesn't export it yet. Importing it fails the template build (TS2305: Module '"@databricks/appkit-ui/react"' has no exported member 'ErrorPage') and with it CI's template deploy-shape jobs. Once a release with ErrorPage is pinned, RouteErrorPage can become <ErrorPage error={useRouteError()} />.
  • New devDependency: react-router@7.18.0, the template's pin, MIT licensed, used by the appkit-ui tests only. They render a real router, which is the only way to show React Router's default text is gone.
  • fix(appkit), design plugin: hasReactRouter() used Node's resolution, which also searches NODE_PATH. pnpm's bin shims point that at the workspace's hidden hoisted packages. With react-router 7 now in the workspace, it "found" a router for an app without one. It now looks only for node_modules/react-router from the design page up, as Vite resolves it.
  • Template layout on error: an error replaces the whole template layout, header included, because the default sits on the layout route.

How it was verified

  • Full check: pnpm install --frozen-lockfile && pnpm run check && pnpm run knip && pnpm build && pnpm run typecheck && pnpm vitest run --changed … passed, 6643 tests.
  • New tests (error-page.test.tsx) use a real React Router and show:
    • a route that throws renders the AppKit page and not React Router's text;
    • a 404 renders it too, with Reload;
    • a thrown Object.create(null) renders, in development and production;
    • details are hidden when DEV is false;
    • a route's own errorElement wins.
  • Playground Playwright suite (mocked): 31 of 31 passed, including the new error-page.spec.ts.
  • Template smoke tests: tools/smoke-test-template.ts --run passed (install, build, start), and so did the --all-plugins run (typecheck and lint).
  • In a browser: I checked a scaffolded template with test routes (a route that throws, a loader 404, a thrown Object.create(null), a route with its own errorElement), in development and production builds, and the playground's /error-page. Details show in development and are hidden in production.

This pull request and its description were written by Isaac.

MarioCadenas and others added 9 commits November 25, 2026 13:44
hasReactRouter() resolved react-router with Node's resolution, which also
searches NODE_PATH. pnpm's bin shims point NODE_PATH at the workspace's
hidden hoisted packages, so a copy the app's Vite never resolves could
switch design pages into router mode. Look for node_modules/react-router
from the design page up instead, as Vite does.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
A page to show instead of the router's built-in error page: it says that
something went wrong (for a 404 route error response, that the page was
not found) and offers a reload and the home page. The message and stack
show only in development (import.meta.env.DEV). It takes the error as a
prop, so it works with React Router's useRouteError() or TanStack
Router's errorComponent; route error responses are recognised by shape.

react-router 7.18.0 (the template's pin) is a devDependency for the
tests, which render a real router: a route that throws, a 404, details
hidden outside development, and a route's own errorElement winning.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
…te and design pages

A route that throws showed React Router's built-in page: "Hey developer"
while developing, and the error's message and stack in a deployed app.

The template's root layout route now has an errorElement: a page built
from AppKit UI components that says something went wrong and offers
Reload and Back to home, with the stack only in development; a 404 route
error response renders the existing NotFoundPage. It is defined in
App.tsx rather than importing ErrorPage, because the template pins the
published @databricks/appkit-ui, which doesn't have ErrorPage yet.

Design pages' router gets appkit-ui's ErrorPage as its root
ErrorBoundary, for a page that fails to load or doesn't exist.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
The root CatchBoundary renders appkit-ui's ErrorPage instead of the
playground's own error card (which showed the message in production
too), and a new /error-page route under Platform throws on render to
show it.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
Also regenerates docs/static/appkit-ui/styles.gen.css for the classes
ErrorPage uses.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
…ErrorPage

A 404 route error response now offers Reload as well as Back to home,
as the other errors do. The development details no longer throw for a
value String() can't convert (Object.create(null)): the page renders
"[object Object]" instead of crashing into an outer error boundary.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
The template's RouteErrorPage rendered NotFoundPage for a 404 route
error response, without Reload or development details, and built its
details with String(error) before the development check, so a thrown
Object.create(null) crashed it in production into the outer boundary,
which shows stacks. It now shows "Page not found" with Reload, Back to
home and development-only details, builds the details only in
development without throwing, and links home with a plain anchor (a full
page load, as ErrorPage does).

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
…ails

In development, the template's error page showed only the status of a
route error response; it now adds the response's text when it is a
string (e.g. "No such order" from a loader's 404), as ErrorPage does.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
It opens the route that throws and checks that AppKit's error page shows
inside the playground layout, with Reload and Back to home, that React
Router's text is absent, and that the dev server shows the thrown
message.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: mario.cadenas <mario.cadenas@databricks.com>
@MarioCadenas
MarioCadenas requested a review from a team as a code owner November 25, 2026 16:31
@MarioCadenas
MarioCadenas requested a review from ditadi November 25, 2026 16:31
@github-actions

Copy link
Copy Markdown
Contributor

📦 Bundle size report

Compared against bundle-size-baseline.json (main).

@databricks/appkit

npm tarball (packed): 1.3 MB (+266 B) — gzipped download (dist + bin; excludes release-only docs/NOTICE).

dist raw gzip
JS (runtime) 1.4 MB (+275 B) 501 KB (+120 B)
Type declarations 482 KB 174 KB
Source maps 2.7 MB (+160 B) 931 KB (+86 B)
Other 11 KB 3.7 KB
Total 4.6 MB (+435 B) 1.6 MB (+206 B)
Per-entry composition (own code — deps external (as shipped))
Entry Initial (gz) Lazy (gz) Total (gz) node_modules (min) Own code (min)
. 118 KB 2.4 KB 121 KB external 378 KB
./beta 118 KB (+64 B) 4.5 KB 123 KB (+64 B) external 356 KB (+166 B)
./testing 47 KB 38 KB 85 KB external 246 KB
./tsdown 630 B 0 B 630 B external 1.0 KB
./type-generator 31 KB 0 B 31 KB external 89 KB

Chunks:

Entry Chunk Load Size (gz)
. index.js initial 114 KB
. utils.js initial 4.6 KB
. remote-tunnel-manager.js lazy 2.4 KB
./beta beta.js initial 92 KB
./beta stream-manager.js initial 5.9 KB
./beta define-schema.js initial 5.8 KB
./beta service-context.js initial 4.3 KB
./beta modular.js initial 3.6 KB
./beta databricks.js initial 3.3 KB
./beta wide-event-emitter.js initial 2.8 KB
./beta client.js initial 645 B
./beta index.js initial 20 B
./beta index.js lazy 4.0 KB
./beta supervisor-api.js lazy 201 B
./beta databricks.js lazy 188 B
./beta index.js lazy 124 B
./testing manifest.js initial 33 KB
./testing index.js initial 10 KB
./testing wide-event-emitter.js initial 2.9 KB
./testing index.js lazy 34 KB
./testing remote-tunnel-manager.js lazy 2.4 KB
./testing utils.js lazy 1.8 KB
./tsdown index.js initial 630 B
./type-generator index.js initial 31 KB

@databricks/appkit-ui

npm tarball (packed): 396 KB (+2.8 KB) — gzipped download (dist + bin; excludes release-only docs/NOTICE).

dist raw gzip
JS (runtime) 433 KB (+2.7 KB) 147 KB (+1.2 KB)
Type declarations 251 KB (+1.0 KB) 93 KB (+568 B)
Source maps 842 KB (+4.5 KB) 283 KB (+2.0 KB)
CSS 16 KB 3.2 KB
Total 1.5 MB (+8.3 KB) 526 KB (+3.8 KB)
Per-entry composition (consumer bundle — deps bundled, peerDeps external)
Entry Initial (gz) Lazy (gz) Total (gz) node_modules (min) Own code (min)
./js 5.3 KB 49 KB 55 KB 208 KB 14 KB
./js/beta 2.4 KB 0 B 2.4 KB 0 B 5.3 KB
./react 441 KB (+599 B) 49 KB 490 KB (+599 B) 1.4 MB (+312 B) 181 KB (+1.2 KB)
./react/beta 13 KB 0 B 13 KB 25 KB 13 KB

Chunks:

Entry Chunk Load Size (gz)
./js index.js initial 5.2 KB
./js chunk initial 120 B
./js apache-arrow lazy 49 KB
./js/beta beta.js initial 2.4 KB
./react index.js initial 439 KB
./react tslib initial 2.1 KB
./react apache-arrow lazy 49 KB
./react/beta beta.js initial 13 KB

@github-actions

Copy link
Copy Markdown
Contributor

🤖 AppKit PR bot

🔬 Run evals

Start an eval for this PR from the evals-monitor app: Go to Evals Monitor →

📦 Try this PR's app template

Scaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh auth login — and the Databricks CLI):

gh run download 45654862123 -R databricks/appkit -n appkit-template-0.105.0-pr.f33f099-work-17-replace-react-router-s-default-749 -D appkit-pr-749 \
  && unzip -o "appkit-pr-749/appkit-template-0.105.0-pr.f33f099-work-17-replace-react-router-s-default-749.zip" -d "appkit-pr-749" \
  && databricks apps init --template "appkit-pr-749"

The template pins @databricks/appkit and @databricks/appkit-ui to tarballs built from this branch, so the scaffolded app runs against this PR's code.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant