Fix basePath issues in Doctocat UI components - #46
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that the Next.js basePath is respected by Doctocat UI elements (index cards and live code previews) by exposing it via environment, wiring it through context, and rewriting URLs accordingly.
- Expose
basePathfrom Next.js config to Doctocat viaNEXT_PUBLIC_DOCTOCAT_BASE_PATH. - Forward
basePathinto React context and apply it to index card links. - Add
codeTransformerand hook it intoReactCodeBlockso previewed images get the correct path.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/theme/doctocat.config.js | Expose basePath to Doctocat via env var |
| packages/theme/components/layout/root-layout/index.tsx | Provide basePath in ConfigContext |
| packages/theme/components/layout/index-cards/IndexCards.tsx | Wrap cards in Next.js Link and prepend basePath to links |
| packages/theme/components/layout/code-block/code-transformer.ts | Utility to rewrite image src with basePath |
| packages/theme/components/layout/code-block/ReactCodeBlock.tsx | Apply codeTransformer to live previews via transformCode |
| packages/theme/components/context/useConfig.tsx | Add basePath field to ConfigContextValue |
| .changeset/warm-teachers-repeat.md, .changeset/chatty-trains-explode.md | Document patch updates for basePath support |
Comments suppressed due to low confidence (3)
packages/theme/components/layout/index-cards/IndexCards.tsx:95
- [nitpick] Using a placeholder href="#" may introduce unintended URL fragments; consider removing the href prop on Card and relying on Next.js Link's passHref behavior, or render Card as via the
asprop.
<Card href="#" hasBorder>
packages/theme/components/layout/index-cards/IndexCards.tsx:94
- Add unit or integration tests to verify that index card links are correctly prefixed with basePath when
NEXT_PUBLIC_DOCTOCAT_BASE_PATHis set.
<Link legacyBehavior passHref href={item.route}>
packages/theme/components/layout/code-block/code-transformer.ts:1
- Introduce unit tests for
codeTransformerto ensure it properly prependsbasePathto various local image src patterns and skips external URLs as intended.
export const codeTransformer = (sourceCode: string, basePath: string): string => {
danielguillan
approved these changes
Jun 20, 2025
…er ones that are impoted through webpack instead
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Towards primer/brand#1059
Fixes 3 bugs: