Skip to content

Commit

Permalink
refactor: use lit readable
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianCataldo committed May 11, 2024
1 parent 341f495 commit d0099a4
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 98 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const tsConfigs = [
'./packages/addons/svg/tsconfig.json',
'./packages/addons/sitemap/tsconfig.json',
'./packages/addons/markdown/tsconfig.json',
// './packages/addons/minify/tsconfig.json',
// './packages/addons/markdown-old/tsconfig.json',
// './packages/addons/labs/minify/tsconfig.json',
'./packages/addons/markdown-preset-marked/tsconfig.json',
'./packages/addons/metadata/tsconfig.json',
'./integration/tsconfig.json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!-- PAGE ASSETS -->
<!-- /PAGE ASSETS -->

<script type="module" crossorigin src="/assets/index-CD_ncSzw.js"></script>
<script type="module" crossorigin src="/assets/index-BoX7nWOj.js"></script>
<link rel="modulepreload" crossorigin href="/assets/modulepreload-polyfill-B5Qt9EMX.js">
</head>

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

6 changes: 5 additions & 1 deletion packages/create-gracile/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ function handleCancel(result: unknown) {

// eslint-disable-next-line no-console
console.log('' /* Blank line */);
clack.intro(c.cyan(`✨🧚 Create your new ${c.bold('Gracile')} project`)); // 🧚🏻‍♀️
clack.intro(
c.cyan(
`✨🧚 Create your new ${c.underline(c.white(c.italic('Gracile')))} project`,
),
); // 🧚🏻‍♀️

if (DEV) clack.log.warn(c.yellow(`Development mode`));
clack.log.info(
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/src/build/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logger } from '@gracile/internal-utils/logger';
import c from 'picocolors';
import type { ViteDevServer } from 'vite';

import { renderRouteTempalte } from '../render/route-template.js';
import { renderRouteTemplate } from '../render/route-template.js';
import { collectRoutes, routes } from '../routes/collect.js';
import { loadForeignRouteObject } from '../routes/load-module.js';

Expand Down Expand Up @@ -94,7 +94,7 @@ export async function renderRoutes(vite: ViteDevServer, root = process.cwd()) {

// MARK: Render

const { output } = await renderRouteTempalte(
const { output } = await renderRouteTemplate(
//
{ url: url.href },
vite,
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/src/dev/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { ViteDevServer } from 'vite';
import { /* errorInline, */ errorPage } from '../errors/templates.js';
import {
type HandlerInfos,
renderRouteTempalte,
renderRouteTemplate,
} from '../render/route-template.js';
import { getRoute, type RouteInfos } from '../routes/match.js';
import { renderSsrTemplate } from '../vite/utils.js';
Expand Down Expand Up @@ -50,7 +50,7 @@ export function createDevRequestHandler(vite: ViteDevServer) {
handlerInfos: HandlerInfos,
routeInfos: RouteInfos,
) {
const { output } = await renderRouteTempalte(
const { output } = await renderRouteTemplate(
requestPonyfilled,
vite,
'dev',
Expand Down
21 changes: 11 additions & 10 deletions packages/engine/src/render/route-template.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Readable } from 'node:stream';

import { html } from '@gracile/internal-utils/dummy-literals';
import { html as LitSsrHtml, render as renderLitSsr } from '@lit-labs/ssr';
import { collectResult } from '@lit-labs/ssr/lib/render-result.js';
import { RenderResultReadable as LitReadable } from '@lit-labs/ssr/lib/render-result-readable.js';
import type { Readable } from 'stream';
import type { ViteDevServer } from 'vite';

import { isLitServerTemplate, isLitTemplate } from '../assertions.js';
Expand Down Expand Up @@ -30,7 +30,7 @@ export const pageAssets = LitSsrHtml`<!--__GRACILE_PAGE_ASSETS__-->`;

export type HandlerInfos = { data: unknown; method: string };

export async function renderRouteTempalte(
export async function renderRouteTemplate(
request: Request | StaticRequest,
vite: ViteDevServer,
mode: 'dev' | 'build',
Expand Down Expand Up @@ -58,8 +58,7 @@ export async function renderRouteTempalte(
`Wrong template result for fragment template ${routeInfos.foundRoute.filePath}.`,
);
const fragmentRender = renderLitSsr(fragmentOutput);
// NOTE: Should use RenderResultReadable instead?
const output = Readable.from(fragmentRender);
const output = LitReadable.from(fragmentRender);

return { output };
}
Expand Down Expand Up @@ -117,8 +116,10 @@ export async function renderRouteTempalte(
: baseDocRenderedWithAssets;

const index = baseDocHtml.indexOf(SSR_OUTLET_MARKER);
const baseDocRenderStreamPre = Readable.from(baseDocHtml.substring(0, index));
const baseDocRenderStreamPost = Readable.from(
const baseDocRenderStreamPre = LitReadable.from(
baseDocHtml.substring(0, index),
);
const baseDocRenderStreamPost = LitReadable.from(
baseDocHtml.substring(index + SSR_OUTLET_MARKER.length + 1),
);

Expand All @@ -133,9 +134,9 @@ export async function renderRouteTempalte(
`Wrong template result for page template ${routeInfos.foundRoute.filePath}.`,
);

const renderStream = Readable.from(renderLitSsr(routeOutput));
const renderStream = LitReadable.from(renderLitSsr(routeOutput));

const output = Readable.from(
const output = LitReadable.from(
concatStreams(
baseDocRenderStreamPre,
renderStream,
Expand All @@ -145,7 +146,7 @@ export async function renderRouteTempalte(

return { output };
}
const output = Readable.from(baseDocHtml);
const output = LitReadable.from(baseDocHtml);

return { output };
}
2 changes: 1 addition & 1 deletion packages/gracile/src/server-html.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { html } from '@lit-labs/ssr';
export { html } from '@lit-labs/ssr/lib/server-template.js';

0 comments on commit d0099a4

Please sign in to comment.