Skip to content

fix(blog): fix TOCItems TypeError on direct page visit#646

Merged
zahlekhan merged 1 commit into
mainfrom
fix/blog-toc-typeError
Jun 11, 2026
Merged

fix(blog): fix TOCItems TypeError on direct page visit#646
zahlekhan merged 1 commit into
mainfrom
fix/blog-toc-typeError

Conversation

@zahlekhan

Copy link
Copy Markdown
Contributor

Summary

  • Pass explicit TOCItem children to TOCItems in the blog post page to fix a TypeError: Cannot read properties of undefined (reading '0') crash on direct visit
  • Remove stale docs/pnpm-lock.yaml that was pinning fumadocs-ui@16.6.5 locally while production ran 16.9.1

Root cause

fumadocs-ui was upgraded to 16.9.1 in docs/package.json but docs/pnpm-lock.yaml wasn't updated, causing a version split: Vercel (root workspace lockfile → 16.9.1) vs local (stale docs lockfile → 16.6.5).

In 16.9.1, TOCItems changed from a self-rendering component to a container that expects TOCItem children. Without them:

  1. computed.positions is always [] (no anchor elements found in the DOM)
  2. On direct page load, the IntersectionObserver fires while headings are already visible in the viewport
  3. TocThumb.calculate() runs with startIdx >= 0, accesses computed.positions[startIdx]undefinedundefined[0] → TypeError

Navigation from /blog didn't throw because the observer fires asynchronously after the initial render, so startIdx === -1 and calculate() returns early.

Test plan

  • Visit /blog/state-of-generative-ui-report directly — no TypeError in console
  • Navigate from /blog to a post — no errors
  • TOC sidebar highlights active headings as you scroll

🤖 Generated with Claude Code

fumadocs-ui 16.9.1 changed TOCItems from a self-rendering component to a
container that expects explicit TOCItem children. Without them, positions[]
is always empty; when any heading enters the viewport the IntersectionObserver
fires, TocThumb.calculate() accesses positions[activeIdx] which is undefined,
and throws "Cannot read properties of undefined (reading '0')".

The stale docs/pnpm-lock.yaml was pinning 16.6.5 locally while production
(Vercel uses the root workspace lockfile) ran 16.9.1, hiding the breakage.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zahlekhan zahlekhan enabled auto-merge (squash) June 11, 2026 17:56
@zahlekhan zahlekhan merged commit b138279 into main Jun 11, 2026
1 check passed
@zahlekhan zahlekhan deleted the fix/blog-toc-typeError branch June 11, 2026 17:58
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