Skip to content

fix(site): preview lesson docs from the deploy's branch, not always main#289

Merged
rohitg00 merged 1 commit into
mainfrom
fix/branch-aware-doc-fetch
Jun 14, 2026
Merged

fix(site): preview lesson docs from the deploy's branch, not always main#289
rohitg00 merged 1 commit into
mainfrom
fix/branch-aware-doc-fetch

Conversation

@rohitg00

Copy link
Copy Markdown
Owner

Problem

lesson.html hardcoded the raw.githubusercontent main branch when fetching every lesson's markdown:

var rawUrl = 'https://raw.githubusercontent.com/.../main/' + path + '/docs/en.md';

So every deploy (production, PR preview, any branch) always rendered main's content. Content PRs (new lessons, the figure fences) could never be seen on their Vercel preview before merge.

Fix

  • build.js writes site/build-meta.js with the build's git ref: VERCEL_GIT_COMMIT_REF on Vercel, local git rev-parse otherwise, falling back to main.
  • lesson.html loads it and fetches docs + quiz from window.__AIFS_REF instead of a hardcoded main.
  • build-meta.js is deploy-generated and gitignored (same pattern as sitemap.xml / llms.txt).

Production is unchanged: on main, the ref is main. PR previews now fetch from their own branch, so they render their own lesson edits.

Validation (headless, real lesson.html)

  • GitHub raw resolves a branch ref with a slash: .../fix/branch-aware-doc-fetch/.../en.md → 200.
  • window.__AIFS_REF = the branch; the lesson body and its qlearning-gridworld figure render from the branch's doc (mounted=1), zero blocking errors.
  • The only 404 is the optional quiz.json for a quiz-less lesson, handled by the existing .catch (same as before).

After this merges, PR #282 (figures wave 3) and every future content PR will preview correctly on Vercel.

lesson.html hardcoded the raw.githubusercontent main branch for every lesson's
markdown, so PR preview deploys (and any non-main branch) always rendered main's
content. Content PRs could never be previewed before merge.

build.js now writes build-meta.js with the build's git ref (VERCEL_GIT_COMMIT_REF,
or local git, falling back to main); lesson.html reads window.__AIFS_REF and
fetches docs/quiz from that branch. Production (main) is unchanged; PR previews
now render their own lesson edits. build-meta.js is deploy-generated and gitignored.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8b348b03-8e6e-4c77-8610-c3a321c263ab

📥 Commits

Reviewing files that changed from the base of the PR and between 148de36 and e15ad57.

📒 Files selected for processing (3)
  • .gitignore
  • site/build.js
  • site/lesson.html

📝 Walkthrough

Walkthrough

The PR introduces a deployment metadata system that captures which git ref is being deployed and makes it available to the client. The build script generates a metadata file containing the git branch or commit ref, and the lesson page loads this metadata to fetch content from the correct GitHub branch instead of always using hardcoded main.

Changes

Deployment git ref metadata

Layer / File(s) Summary
Build metadata generation and storage
.gitignore, site/build.js
writeBuildMeta() reads VERCEL_GIT_COMMIT_REF environment variable or resolves the current git branch name (defaulting to main if empty or HEAD), then writes site/build-meta.js defining window.__AIFS_REF. The generated file is added to .gitignore.
Client-side metadata loading and usage
site/lesson.html
The lesson HTML loads build-meta.js before other scripts, enabling fetchLesson to construct GitHub raw content and quiz URLs using the dynamic ref from window.__AIFS_REF instead of hardcoded main branch paths.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: enabling lesson docs to be fetched from the deploy's branch instead of always using main.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, solution, and validation for branch-aware lesson content fetching.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/branch-aware-doc-fetch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rohitg00 rohitg00 merged commit 831f93e into main Jun 14, 2026
6 checks passed
@rohitg00 rohitg00 deleted the fix/branch-aware-doc-fetch branch June 14, 2026 16:42
nickhildpac pushed a commit to nickhildpac/ai-engineering-from-scratch that referenced this pull request Jun 29, 2026
…ain (rohitg00#289)

lesson.html hardcoded the raw.githubusercontent main branch for every lesson's
markdown, so PR preview deploys (and any non-main branch) always rendered main's
content. Content PRs could never be previewed before merge.

build.js now writes build-meta.js with the build's git ref (VERCEL_GIT_COMMIT_REF,
or local git, falling back to main); lesson.html reads window.__AIFS_REF and
fetches docs/quiz from that branch. Production (main) is unchanged; PR previews
now render their own lesson edits. build-meta.js is deploy-generated and gitignored.
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.

1 participant