Skip to content

Lit SSR adapter registration breaks with Vite module resolution #3

@SisyphusZheng

Description

@SisyphusZheng

Description

Even when installLitAdapter() is called and logs "Lit SSR adapter installed", renderDSD() cannot see the adapter. All Lit components produce the error:

<!-- LessJS ERROR: <about-page> render() returned object, expected string. 
This looks like a Lit TemplateResult — install @lessjs/adapter-lit to handle it. -->

Root Cause

@lessjs/adapter-lit/ssr.ts calls registerAdapter() which writes to a module-scope variable _globalAdapter (from @lessjs/core/render-dsd or @lessjs/core/less-runtime).

When Vite's module resolution resolves @lessjs/adapter-lit and @lessjs/core to different module instances (e.g. via resolveAlias, symlinks, or incomplete ssr.noExternal), registerAdapter() writes to copy A's _globalAdapter, while renderDSD() reads from copy B's _globalAdapter — the adapter is never seen.

Specific Trigger Conditions

  • build-metadata.json has resolveAlias pointing @lessjs/adapter-lit and @lessjs/core to local src-tmp/packages/ source files
  • ssr.noExternal list is incomplete, causing some packages to be externalized
  • Windows + preserveSymlinks: true + JSR node_modules structure creates multiple resolution paths

Suggested Fix

Use globalThis or Symbol.for() as a cross-module-instance bridge for adapter registration, instead of relying on module-scope variable sharing.

Severity

P0 — Projects using resolveAlias (e.g. local development of @lessjs/ui) cannot do SSG rendering at all.

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