fix(docs): expose NEXT_PUBLIC_BASE_PATH so blueprint sample fetch works on GitHub Pages#218
Conversation
…ks on GitHub Pages
There was a problem hiding this comment.
Pull request overview
Fixes GitHub Pages deployment of the Blueprint Codegen “Load Sample” flow by ensuring the client-side fetch uses the correct base path during static export.
Changes:
- Introduce a shared
basePathvariable derived fromGITHUB_ACTIONS. - Reuse
basePathfor bothbasePathandassetPrefix. - Expose
NEXT_PUBLIC_BASE_PATHvianext.config.mjsenvso it’s baked into the static build.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const withMDX = createMDX() | ||
|
|
||
| const isCI = !!process.env.GITHUB_ACTIONS | ||
| const basePath = isCI ? '/evolution-sdk' : '' |
There was a problem hiding this comment.
Hardcoding '/evolution-sdk' makes the docs build fragile for repo renames and forks (GitHub Pages base path is typically /${repoName}). Consider deriving the base path from CI metadata (e.g., process.env.GITHUB_REPOSITORY → /${repoName}) and/or allowing an explicit override via an env var, then use that computed value for basePath, assetPrefix, and env.NEXT_PUBLIC_BASE_PATH.
| const basePath = isCI ? '/evolution-sdk' : '' | |
| const explicitBasePath = process.env.DOCS_BASE_PATH | |
| const inferredBasePath = process.env.GITHUB_REPOSITORY | |
| ? `/${process.env.GITHUB_REPOSITORY.split('/').pop()}` | |
| : '' | |
| const basePath = explicitBasePath ?? (isCI ? inferredBasePath : '') |
| basePath, | ||
| assetPrefix: basePath, | ||
| env: { | ||
| NEXT_PUBLIC_BASE_PATH: basePath, | ||
| }, |
There was a problem hiding this comment.
Hardcoding '/evolution-sdk' makes the docs build fragile for repo renames and forks (GitHub Pages base path is typically /${repoName}). Consider deriving the base path from CI metadata (e.g., process.env.GITHUB_REPOSITORY → /${repoName}) and/or allowing an explicit override via an env var, then use that computed value for basePath, assetPrefix, and env.NEXT_PUBLIC_BASE_PATH.
Problem
The "Load Sample" button on the Blueprint Codegen tool was returning "Failed to load sample blueprint" on the GitHub Pages deployment.
loadSample()fetched${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/sample-blueprint.json, butNEXT_PUBLIC_BASE_PATHwas never set, so it always resolved to/sample-blueprint.json— a 404 on GitHub Pages (where the site lives under/evolution-sdk/).Fix
Extract
basePathinto a variable and expose it viaenv.NEXT_PUBLIC_BASE_PATHinnext.config.mjs. Next.js bakesenv.*values into the static export at build time, so the correct prefix (/evolution-sdk) is now available client-side.History
fetch('/sample-blueprint.json')— worked locally, broken on GH Pages2f2a6d5: hardcoded to/evolution-sdk/sample-blueprint.json— worked on GH Pages, broken locallyNEXT_PUBLIC_BASE_PATH— correct pattern, but the env var was never injected