JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 41
  • Score
    100M100P100Q45503F
  • License MIT

Core runtime for Coherent.js (SSR framework).

Package Exports

  • @coherent.js/core

Readme

@coherent.js/core

npm version license: MIT Node >= 20

Core runtime for Coherent.js — an object-based SSR framework focused on performance, streaming, and simplicity.

  • ESM-only, Node 20+
  • Pure object rendering to HTML
  • Optional CSS-like scoping for component encapsulation
  • Component system utilities, error boundaries, and performance hooks

For a high-level overview and repository-wide instructions, see the root README: ../../README.md

Installation

pnpm add @coherent.js/core

Requirements:

  • Node.js >= 20
  • ESM module system

Quick start

JavaScript (ESM):

import { renderToString } from '@coherent.js/core';

const html = await renderToString({
  div: { class: 'greeting', text: 'Hello Coherent' }
});

console.log(html);

TypeScript:

import { renderToString } from '@coherent.js/core';

async function main() {
  const html = await renderToString({
    div: { class: 'greeting', text: 'Hello Coherent (TS)' }
  });
  console.log(html);
}

main();

Exports overview

The package uses conditional exports; in development it may resolve to src while production resolves to dist.

Key APIs (selected):

  • Rendering
    • renderToString(input, options?)
    • render(input) (alias of renderToString)
    • renderScopedComponent(input) – applies scoped attributes and style processing
    • renderUnsafe(input) – render without encapsulation
  • Component system (re-exported from internal modules)
    • createComponent, defineComponent, registerComponent, getComponent, getRegisteredComponents
    • State helpers: withState, withStateUtils, createStateManager
    • Lazy: lazy, isLazy, evaluateLazy
  • Error boundaries (selected)
    • createErrorBoundary, withErrorBoundary, createAsyncErrorBoundary
    • createGlobalErrorHandler, GlobalErrorHandler

Tip: When working in the monorepo website/dev flow, imports can resolve to src via exports.development.

Minimal component example

import { createComponent, renderToString } from '@coherent.js/core';

const Counter = createComponent(({ count = 0 }) => ({
  div: {
    class: 'counter',
    children: [
      { span: { text: `Count: ${count}` } }
    ]
  }
}));

const html = await renderToString(Counter({ count: 2 }));

TypeScript:

import { createComponent, renderToString } from '@coherent.js/core';

type Props = { count?: number };

const Counter = createComponent((props: Props) => ({
  div: {
    class: 'counter',
    children: [ { span: { text: `Count: ${props.count ?? 0}` } } ]
  }
}));

const html = await renderToString(Counter({ count: 2 }));

Development

Run tests for this package:

pnpm --filter @coherent.js/core run test

Watch mode:

pnpm --filter @coherent.js/core run test:watch

Type check:

pnpm --filter @coherent.js/core run typecheck

Build (from package dir or via workspace filter):

pnpm --filter @coherent.js/core run build

License

MIT © Coherent.js Team