gohugoio/hugo · critical
pageMeta.pageMetaSource.pi must be set before creating cache
Error message
pageMeta.pageMetaSource.pi must be set before creating cachedContent
What it means
Panic in pageMeta.newCachedContent when m.pageMetaSource.pi (the page parser / parse info) is nil. cachedContent needs the parsed source to build content scopes and shortcode metadata, so the parser must be initialized first. The message states the required ordering explicitly: pi must be set before creating cachedContent.
Source
Thrown at hugolib/page__content.go:110
NoFrontMatter: m.noFrontMatter,
},
)
if err != nil {
return err
}
m.pi.itemsStep1 = items
if err := m.pi.parseSource(source, m.noFrontMatter); err != nil {
return err
}
return nil
}
func (m *pageMeta) newCachedContent(s *Site) (*cachedContent, error) {
if m.pageMetaSource.pi == nil {
panic("pageMeta.pageMetaSource.pi must be set before creating cachedContent")
}
c := &cachedContent{
pm: s.pageMap,
StaleInfo: m,
pi: m.pi,
enableEmoji: s.conf.EnableEmoji,
scopes: hmaps.NewCache[string, *cachedContentScope](),
}
var hasName predicate.P[string] = m.pi.shortcodeParseInfo.hasName
c.hasShortcode.Store(&hasName)
return c, nil
}
// Content cached for a page instance.
type cachedContent struct {
pm *pageMapView on GitHub (pinned to 52c9bd7908)
Solutions
- Ensure the page's parser (pi) is initialized (e.g. via the parse-source step) before any cachedContent creation.
- Use the standard page-meta construction sequence; do not reorder init steps.
- Upgrade Hugo; report with a reproducer if hit on stock Hugo.
Example fix
// before (fork): cachedContent created before parser m.newCachedContent(s) // pi is nil // after m.pageMetaSource.pi = newPageParseInfo(...) m.parseSource(source, false) m.newCachedContent(s)
Defensive patterns
Strategy: validation
Validate before calling
// Internal ordering invariant: initialize the page parser (pi) before newCachedContent. // In a fork, run parseSource first: // m.pageMetaSource.pi = newPageParseInfo(...) // m.parseSource(source, false) // m.newCachedContent(s)
Prevention
- Do not reorder page-meta initialization.
- Always run the parse step before cachedContent creation.
- Use standard page construction.
- Report stock-Hugo reproducers upstream.
When it happens
Trigger: Calling newCachedContent before the page's source parser (pageMetaSource.pi) was assigned. Reordering in a fork that creates cachedContent too early. A page-construction path that skips parse-source setup. An internal ordering regression.
Common situations: Forking Hugo and changing page initialization order. A bug after refactoring page-meta construction. Headless/content-adapter pages built without running the parse step.
Related errors
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/8db6076b21d8260f.
Report an issue: GitHub.