Package Exports
- @coherent.js/core
- @coherent.js/core/components
- @coherent.js/core/performance
- @coherent.js/core/rendering
- @coherent.js/core/utils
Readme
@coherent.js/core
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/coreRequirements:
- 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 ofrenderToString)renderScopedComponent(input)– applies scoped attributes and style processingrenderUnsafe(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,createAsyncErrorBoundarycreateGlobalErrorHandler,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 testWatch mode:
pnpm --filter @coherent.js/core run test:watchType check:
pnpm --filter @coherent.js/core run typecheckBuild (from package dir or via workspace filter):
pnpm --filter @coherent.js/core run buildLicense
MIT © Coherent.js Team