Skip to content

feat(docs-next): dynamically redirect section URLs to first leaf page#2238

Draft
dancormier wants to merge 7 commits intomainfrom
STACKS-843/section-redirects
Draft

feat(docs-next): dynamically redirect section URLs to first leaf page#2238
dancormier wants to merge 7 commits intomainfrom
STACKS-843/section-redirects

Conversation

@dancormier
Copy link
Copy Markdown
Contributor

Summary

Replaces hardcoded Netlify _redirects entries for section-level URLs (e.g. /system/develop/, /copy/patterns/) with a dynamic SvelteKit server-side redirect. When the active nav node has children (indicating a section rather than a leaf page), the server walks to the first leaf descendant via a recursive helper and issues a 302.

This keeps redirect targets in sync with structure.yaml automatically — no more stale redirects when page order changes.

Related Issue

STACKS-843

Changes

packages/stacks-docs-next/src/routes/[category]/[[section]]/[subsection]/+page.server.ts

  • Import redirect from @sveltejs/kit
  • Add NavItem type and recursive firstLeafSlug(prefix, item) helper
  • Before throwing 404, check parent.active?.items?.length > 0 and redirect to first leaf

packages/stacks-docs-next/_redirects

  • Remove 7 hardcoded section-level entries (/system/develop/, /system/accessibility/, /system/foundation/, /system/base/, /system/forms/, /system/components/, /copy/patterns/)
  • Keep category-level entries (/brand/, /copy/, /system/, etc.) which have no matching SvelteKit route
  • Update comment to reflect the new split of responsibilities

Testing

  • Visit /system/develop — should redirect to /system/develop/using-stacks
  • Visit /system/accessibility — should redirect to /system/accessibility/intro
  • Visit /system/foundation — should redirect to /system/foundation/color-fundamentals
  • Visit /system/base — should redirect to /system/base/backgrounds
  • Visit /copy/patterns — should redirect to /copy/patterns/messages
  • Visit any leaf page — should render normally (no redirect loop)

Changeset

No changeset needed — stacks-docs-next is not a versioned package.


This PR was generated by a developer using an AI agent with the
stacks-v3-dev skill

Previously, section-level URLs like /system/develop or /copy/patterns
would 404 since no MD file or legacy fragment exists for them. These
were handled by hardcoded Netlify _redirects entries that would drift
out of sync with structure.yaml.

Replace those hardcoded entries with a dynamic SvelteKit server-side
redirect: when the active nav node has children (it's a section), the
page server now walks to the first leaf descendant via a recursive
firstLeafSlug helper and issues a 302 to that URL.

The _redirects file retains only category-level redirects (e.g. /brand/,
/system/) which have no matching SvelteKit route.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dancormier dancormier requested a review from a team April 14, 2026 23:08
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 14, 2026

⚠️ No Changeset found

Latest commit: 350909f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 14, 2026

Deploy Preview for stacks ready!

Name Link
🔨 Latest commit 350909f
🔍 Latest deploy log https://app.netlify.com/projects/stacks/deploys/69dfb6073aaeef0008ba5a4f
😎 Deploy Preview https://deploy-preview-2238--stacks.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dancormier dancormier marked this pull request as draft April 14, 2026 23:23
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Verify that we don't need these redirects that have been removed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this can go too, was also ported from v2 Netlify.toml but not needed

# Assets
/assets/img/logo-stacks@2x.png /assets/img/logos/so/logo-stacks@2x.png 302

Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
Comment thread packages/stacks-docs-next/_redirects Outdated
dancormier and others added 6 commits April 15, 2026 11:55
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
Co-authored-by: David Longworth <dlongworth@stackoverflow.com>
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.

2 participants