@flightdev/ui-marko
v1.1.0
Published
Marko SSR adapter for Flight Framework
Maintainers
Readme
@flightdev/ui-marko
Marko SSR adapter for Flight Framework. Streaming SSR with progressive enhancement.
Table of Contents
Installation
npm install @flightdev/ui @flightdev/ui-markoPeer dependencies:
npm install markoQuick Start
import { defineUI } from '@flightdev/ui';
import { marko } from '@flightdev/ui-marko';
const ui = defineUI(marko());
const result = await ui.adapter.renderToString({
component: template,
props: { items: [] },
});
console.log(result.html);Streaming SSR
Marko supports streaming SSR out of the box:
import { marko } from '@flightdev/ui-marko';
const adapter = marko();
const { stream, done } = adapter.renderToStream(
{ component: template, props: { items } },
{ url: request.url }
);
const reader = stream.getReader();
while (true) {
const { done: readerDone, value } = await reader.read();
if (readerDone) break;
response.write(value);
}
response.end();Hydration
Generate hydration scripts for client-side interactivity:
const result = await adapter.renderToString({
component: template,
props: { data },
});
const hydrationScript = adapter.getHydrationScript(result);
const html = `
<!DOCTYPE html>
<html>
<body>
${result.html}
${hydrationScript}
</body>
</html>
`;API Reference
marko(options?)
Create a Marko adapter instance.
function marko(options?: MarkoAdapterOptions): MarkoAdapter;MarkoAdapter
| Method | Description |
|--------|-------------|
| renderToString(component, context?) | Render to HTML string |
| renderToStream(component, context?, options?) | Render to readable stream |
| getHydrationScript(result) | Generate hydration script |
| getClientEntry() | Get client entry code |
Capabilities
| Capability | Supported | |------------|-----------| | Streaming | Yes | | Partial Hydration | No | | Islands | No | | Resumable | No | | SSG | Yes | | CSR | Yes | | Server Components | No |
License
MIT
