Repository navigation
Conversation
|
Important This PR includes changes that affect public-facing API. Please ensure you are adding/updating documentation for new features or behavior. Missing ChangesetsThe following package(s) are changed by this PR but do not have a changeset:
See CONTRIBUTING.md for more information about how to add changesets. Changed Packages
|
2fd9992 to
8bd0357
Compare
e7e8647 to
5ca70ae
Compare
Signed-off-by: Paul Schultz <[email protected]>
Signed-off-by: Paul Schultz <[email protected]>
Signed-off-by: Paul Schultz <[email protected]>
Signed-off-by: Paul Schultz <[email protected]>
Signed-off-by: Paul Schultz <[email protected]>
Signed-off-by: Paul Schultz <[email protected]>
Signed-off-by: Paul Schultz <[email protected]>
…zation Re-applies 9bac36e on top of the scoped routing app root: root elements are keyed by their extension ID and rendered in a single fixed position, so finalization no longer remounts the app content. Co-Authored-By: Claude Sonnet 4.5 <[email protected]> Signed-off-by: Paul Schultz <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]> Co-Authored-By: Codex <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
frontend-app-api: preserve compatibility for older routing blueprints
…ckages frontend-adapter-react-router-v6: rename routing adapter packages
Covers the review findings from the scoped-routing merge: the routing compatibility seam applied to v1 named outputs, middleware-replaced outputs, and route refs; empty route mounts with an omitted or null react element; direct history navigation that unmounts the navigating page and navigation callbacks retained past unmount; and the AppRouteSwitch behavior for an empty route table and a crashing not-found page. Signed-off-by: Paul Schultz <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
Signed-off-by: Patrik Oldsberg <[email protected]>
frontend-app-api: fix routing compatibility and app replacement
| const namedSegments = hasSplat ? segments.slice(0, -1) : segments; | ||
|
|
||
| for (const segment of namedSegments) { | ||
| const param = segment.match(/^:([\w-]+)(\?)?(.*)$/); |
…gesets Signed-off-by: Paul Schultz <[email protected]>
Rugvip
left a comment
There was a problem hiding this comment.
It is time 🤯
Biggest change we've shipped.
Leaving old comments around to handle in followups if they still apply.
|
|
||
| Added `TanStackPageRouter` for page-scoped TanStack routing with app-owned history. Use `createTanStackPageRouter` and `TanStackPageContent` to integrate a plugin-owned route tree. | ||
|
|
||
| Install `@tanstack/[email protected]` and `@tanstack/[email protected]` alongside the adapter. Without a page mount or app history, the adapter renders children unchanged. |
There was a problem hiding this comment.
Should we just make these direct deps instead? Given how specific the adapter is it seems low risk and ofc a nice utility
| import { ReactRouterV6PageRouter } from '@backstage/plugin-app-react-router-v6'; | ||
|
|
||
| await renderInTestApp(<EntityHeader />, { | ||
| router: ReactRouterV6PageRouter, |
There was a problem hiding this comment.
Seems a bit redundant, as opposed to just expecting it to be wrapping the subject instead? Or do we need to hook it up in a specific way and does it need specific props in that case?
| routing. They work on every page, whichever library it uses and on pages that | ||
| use none. Try them before reaching for anything else on this page. | ||
|
|
||
| Existing new frontend system pages retain implicit React Router v6 routing. |
| ``` | ||
|
|
||
| The options support `replace` and `state`. This declaration belongs to your app; | ||
| BUI does not set React Aria's global router types for plugins. |
| "@backstage/types": "workspace:^", | ||
| "@backstage/ui": "workspace:^", | ||
| "@backstage/version-bridge": "workspace:^", | ||
| "@remix-run/router": "^1.23.4", |
There was a problem hiding this comment.
Hmm, big extra dep for a small (?) thing. Is it possible to get resolveTo from somewhere else or inline?
| export function useOptionalAppHistory(): AppHistoryApi | undefined { | ||
| return useApiHolder().get(appHistoryApiRef); | ||
| } |
There was a problem hiding this comment.
Still valid? Voting to give this the useAnalytics treatment
| * The `UNSAFE_*` names only exist from React Router v6 stable onwards. The v6 | ||
| * beta this package still supports — see the `'6.0.0-beta.0 || ^6.3.0'` range | ||
| * the migration CLI writes, and the beta arm of `Link.test.tsx` — exports no | ||
| * `UNSAFE_` name at all, so each import is `undefined` there, and handing that | ||
| * to `useContext` throws before any hook below can answer. |
There was a problem hiding this comment.
We removed RR 6 beta support ~18 months ago in the framework, so I think it's alright to drop support here too
| "@backstage/config": "workspace:^", | ||
| "@backstage/core-plugin-api": "workspace:^", | ||
| "@backstage/errors": "workspace:^", | ||
| "@backstage/filter-predicates": "workspace:^", |
| } | ||
|
|
||
| /** Reads live backend state while retaining unchanged snapshot references. */ | ||
| readonly getSnapshot = (): AppHistorySnapshot => this.refresh(); |
There was a problem hiding this comment.
This probably needs a memo or smth
| export const MATCH_ALL_ROUTE: BackstageRouteObject = { | ||
| caseSensitive: false, | ||
| path: '*', | ||
| element: 'match-all', // These elements aren't used, so we add in a bit of debug information |
There was a problem hiding this comment.
Might as well keep these if we can
|
Thank you for contributing to Backstage! The changes in this pull request will be part of the |
Hey, I just made a Pull Request!
Implements RFC #33603.
This gives the new frontend system one app-owned browser history while allowing pages and sub-pages to choose React Router v6, React Router v7, TanStack Router, or no routing library. Different adapters can coexist without creating competing browser histories. Existing React Router v6 pages keep working through implicit compatibility, so plugin migration can happen separately.
This diagram shows ownership rather than React component nesting: adapters project the app history into their own router contexts.
What changed
AppHistoryApiprovidesnavigateandcreateHref, including numeric back/forward traversal, and exposes app history as a synchronous external store throughgetSnapshot()andsubscribe(listener). Cached immutable snapshots containlocationand optionalaction,entry, andlengthmetadata; the store functions can be passed directly touseSyncExternalStore.popstateandhashchangefallback. Adapters delegate navigation to that history.ReactRouterV6PageRouter,ReactRouterV7PageRouter, orTanStackPageRouterinside their lazily loaded React components.createTanStackPageRouteralso supports plugin-owned TanStack route trees.useAppLocationanduseAppSearchParamsread and update the app location and query without requiring a page router. Shared route-reference hooks read framework matches without consuming the implicit compatibility context.BUIProvideraccepts auseNavigationhook returningnavigate,createHref, andpathname. Adapters supply the component-library-neutralNavigationProvider; navigation binds at each consumer's route scope, so relative links use the nearest adapter and active tabs/header links respect the deployment basename.javascript:,data:, andvbscript:targets become inert.Compatibility and migration
Existing new frontend pages do not need to migrate immediately. Pages that consume React Router v6 context without an explicit adapter receive implicit compatibility backed by the same app history, including route parameters, relative links, and nested routes. Development builds warn once per extension per app history instance when that fallback is consumed.
Pages using only framework routing, or no routing at all, need no adapter declaration and receive no migration warning. Converted legacy routes receive the v6 adapter through conversion. Inside an adapter, page-local
Link,useNavigate,useParams, and<Routes>continue to work.Keep adapter imports in the lazy page module and wrap the page’s existing JSX directly. Blueprint loaders only import and render that component. Components that use only Backstage routing need no wrapper.
For absolute or cross-plugin navigation, resolve route refs with
useRouteRefand useuseAppNavigateoruseAppHref.RouteLinkwas removed: useuseRouteRefwith BUILinkfor standard links, orRouterLinkanduseNavigationfor contextual navigation and custom UI integration. Framework hooks require app-absolute paths; contextual navigation follows the nearest adapter for relative targets. Shared hooks fall back to React Router in the old frontend system, which retains its existing root-router support and React 17 compatibility. Plugin adoption is in #35692.In the new frontend system,
RouterBlueprintand theapp/rootrouter input are removed, and converted legacycomponents.Routeroverrides are rejected. Remove plainBrowserRouteroverrides, move global providers toAppRootWrapperBlueprint, and supply custom history through anappHistoryApiReffactory. Upstream-rebase reconciliation aligns app creation withprepareSpecializedApp, updates routing tests for the removal of session-state reuse, and refreshes test-utility API reports; default history remains lazy and is created on first use.The temporary v6 app-chrome projection owns no browser history. Its removal depends on routerless chrome coverage and dependency enforcement; page adapter support is independent of that removal.
Demo and remaining limits
The companion migration PR adds mixed-adapter tabs, nested routes, implicit compatibility, and routerless content at
/nfs-routing-demo,/nfs-routing-demo-v7, and/nfs-routing-demo-tanstack.Regression coverage includes framework history and external-store snapshots, location/query and routing hooks, legacy fallback, adapter navigation, and routing test utilities. The latest changes update these tests and API reports; earlier test counts and local validation results are not presented as validation of the rebased head.
Navigation blockers remain local to the routing library; there is no app-wide blocker contract. TanStack blockers cover local push/replace, not numeric traversal. Custom histories without entry metadata have limited back-availability reporting and entry-based restoration, while traversal still delegates to the host.
Normal app teardown releases browser listeners. Hot reload can create a replacement app without unmounting the previous root, leaving its listener attached until reload.
The adapter pins
@tanstack/react-router1.131.2, which needs no React 18 declaration workaround; downstream apps must use exactly1.131.2to satisfy the router peer (the history peer allows^1.131.2).✔️ Checklist
Signed-off-byline in the message. (more info)