Skip to content

Conversation

natemoo-re
Copy link
Member

This PR implements a new routing structure for /stories. Closes DE-193.

Previously, all /stories routes were access via a query param with their full path structure such as ?name=app/components/collapsePanel.stories.tsx. With this implementation, it was difficult to navigate via URL without understanding our internal file structure (which can also be subject to change).

To improve routing ergonomics and stability, the foundations and core components now have permalinks like /stories/foundations/colors and /stories/core/button. These are automatically picked up by a client redirect, which makes them backwards-compatible with the existing URL structure.

For shared components/hooks/etc, the existing ?name=app/components/collapsePanel.stories.tsx URL structure is maintained.

Type Before After
foundations /stories/?name=app/styles/colors.mdx /stories/foundations/colors
core component /stories?name=app/components/core/button/index.mdx /stories/core/button
shared /stories/?name=app/utils/useOrganization.stories.tsx /stories/?name=app/utils/useOrganization.stories.tsx

@natemoo-re natemoo-re requested a review from a team July 11, 2025 19:20
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jul 11, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

codecov bot commented Jul 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #95365      +/-   ##
==========================================
- Coverage   77.05%   72.32%   -4.73%     
==========================================
  Files       10493    10493              
  Lines      605919   605915       -4     
  Branches    23704    23703       -1     
==========================================
- Hits       466887   438252   -28635     
- Misses     136609   165240   +28631     
  Partials     2423     2423              

@natemoo-re natemoo-re enabled auto-merge (squash) July 11, 2025 22:39
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Story Redirect Hook Fails for URL Formats

The useStoryRedirect hook fails to redirect correctly due to two issues:

  1. It attempts to access category and topic as query parameters (location.query) instead of path parameters, preventing redirects for new-style URLs (e.g., /stories/foundations/colors).
  2. An early return condition if (location.state?.storyPath ?? location.query.name) incorrectly bails out when location.query.name is present, blocking redirects from legacy URLs (e.g., /stories/?name=...) to the new format.

static/app/stories/view/useStoryRedirect.tsx#L21-L69

export function useStoryRedirect() {
const location = useLocation<StoryQuery>();
const navigate = useNavigate();
const stories = useStoryBookFilesByCategory();
useEffect(() => {
// If we already have a `storyPath` in state, bail out
if (location.state?.storyPath ?? location.query.name) {
return;
}
if (!location.pathname.startsWith('/stories')) {
return;
}
const story = getStoryMeta(location.query, stories);
if (!story) {
return;
}
if (story.category === 'shared') {
navigate(
{pathname: `/stories/`, search: `?name=${encodeURIComponent(story.path)}`},
{replace: true, state: {storyPath: story.path}}
);
} else {
navigate(
{pathname: `/stories/${story.category}/${kebabCase(story.label)}`},
{replace: true, state: {storyPath: story.path}}
);
}
}, [location, navigate, stories]);
}
type StoryCategory = keyof ReturnType<typeof useStoryBookFilesByCategory>;
interface StoryMeta {
category: StoryCategory;
label: string;
path: string;
}
function getStoryMeta(
query: StoryQuery,
stories: ReturnType<typeof useStoryBookFilesByCategory>
) {
if (query.name) {
return legacyGetStoryMetaFromQuery(query, stories);
}
if (query.category && query.topic) {
return getStoryMetaFromQuery(query, stories);
}
return undefined;

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@natemoo-re natemoo-re merged commit 3827265 into master Jul 12, 2025
46 checks passed
@natemoo-re natemoo-re deleted the stories/nm/routes branch July 12, 2025 13:36
andrewshie-sentry pushed a commit that referenced this pull request Jul 14, 2025
This PR implements a new routing structure for `/stories`. Closes
DE-193.

Previously, all `/stories` routes were access via a query param with
their full path structure such as
`?name=app/components/collapsePanel.stories.tsx`. With this
implementation, it was difficult to navigate via URL without
understanding our internal file structure (which can also be subject to
change).

To improve routing ergonomics and stability, the foundations and core
components now have permalinks like `/stories/foundations/colors` and
`/stories/core/button`. These are automatically picked up by a client
redirect, which makes them backwards-compatible with the existing URL
structure.

For shared components/hooks/etc, the existing
`?name=app/components/collapsePanel.stories.tsx` URL structure is
maintained.

| Type | Before | After |
|------|--------|--------|
|foundations| `/stories/?name=app/styles/colors.mdx` |
`/stories/foundations/colors` |
|core component| `/stories?name=app/components/core/button/index.mdx` |
`/stories/core/button` |
|shared| `/stories/?name=app/utils/useOrganization.stories.tsx` |
`/stories/?name=app/utils/useOrganization.stories.tsx` |
natemoo-re added a commit that referenced this pull request Jul 15, 2025
Follow-up to #95365.

Previously, legacy URLs would not be redirected.
Now, legacy URLs force a redirect.

Previously, the sidebar and search pointed to the legacy URLs, which
required a redirect.
Now, the sidebar and search leverage the new URLs and pass along `state`
info.
andrewshie-sentry pushed a commit that referenced this pull request Jul 21, 2025
Follow-up to #95365.

Previously, legacy URLs would not be redirected.
Now, legacy URLs force a redirect.

Previously, the sidebar and search pointed to the legacy URLs, which
required a redirect.
Now, the sidebar and search leverage the new URLs and pass along `state`
info.
@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants