Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/private-apis/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- Allow `@wordpress/storybook` to opt in to private APIs. ([#78814](https://github.com/WordPress/gutenberg/pull/78814))

## 1.47.0 (2026-05-27)

## 1.46.0 (2026-05-14)
Expand Down
1 change: 1 addition & 0 deletions packages/private-apis/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const CORE_MODULES_USING_PRIVATE_APIS = [
'@wordpress/route',
'@wordpress/router',
'@wordpress/routes',
'@wordpress/storybook',
'@wordpress/sync',
'@wordpress/theme',
'@wordpress/dataviews',
Expand Down
27 changes: 27 additions & 0 deletions storybook/decorators/with-router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { privateApis as routePrivateApis } from '@wordpress/route';
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';

const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/storybook'
);

const { createMemoryHistory, createRootRoute, createRouter, RouterProvider } =
unlock( routePrivateApis );

/**
* Storybook decorator that provides a router context.
*
* Wraps stories in a minimal tanstack router (via @wordpress/route private
* APIs) so that components consuming `Link` from `@wordpress/route` can
* render without errors.
*/
export function withRouter( Story: React.ComponentType ) {
const rootRoute = createRootRoute( { component: Story } );
const router = createRouter( {
routeTree: rootRoute,
history: createMemoryHistory( { initialEntries: [ '/' ] } ),
defaultNotFoundComponent: () => null,
} );
return <RouterProvider router={ router } />;
}
Loading
Loading