Skip to content

@lessjs/content blog data not available during toSSG() rendering — getPosts()` returns empty/undefined #4

@SisyphusZheng

Description

@SisyphusZheng

Description

When using @lessjs/content for blog posts, getPosts() returns empty data during SSG rendering, causing all blog-dependent pages to crash:

<!-- LessJS ERROR: <home-page> render() threw: Cannot read properties of undefined (reading 'tags') -->
<!-- LessJS ERROR: <blog-index-page> render() threw: Cannot read properties of undefined (reading 'title') -->

Root Cause

In build-ssg.ts, initBlogData() is called (line ~361-374) inside the dynamic routes block, before toSSG(). However, when using resolveAlias to point @lessjs/content to a local source, the module loaded via ssrLoadModule('@lessjs/content') may resolve to a different instance than the one imported by route modules. The initialized data store is not shared across module instances.

In custom SSG scripts using esbuild pre-compilation, the bundled route modules reference a different getPosts() than the one initBlogData() initializes — same function name, different closure.

Severity

P1 — All blog projects using @lessjs/content fail SSG rendering. Related to Issue 2 (module instance duplication).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions