-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'alternate/cache-definition-instead-of-render' of https:…
…//github.com/astro-expansion/domain-expansion into alternate/cache-definition-instead-of-render
- Loading branch information
Showing
44 changed files
with
2,170 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@domain-expansion/astro": minor | ||
--- | ||
|
||
Add configuration for components using shared state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@domain-expansion/astro": minor | ||
--- | ||
|
||
Eagerly normalize loaded chunks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import type { RenderTemplateResult } from "astro/runtime/server/render/astro/render-template.js"; | ||
import { runtime, type Thunk } from "./utils.ts"; | ||
import type { RenderDestination, RenderDestinationChunk } from "astro/runtime/server/render/common.js"; | ||
import type { HeadAndContent } from "astro/runtime/server/render/astro/head-and-content.js"; | ||
import type { AstroFactoryReturnValue } from "astro/runtime/server/render/astro/factory.js"; | ||
|
||
export namespace FactoryValueClone { | ||
export function makeResultClone( | ||
value: AstroFactoryReturnValue | ||
): Promise<Thunk<AstroFactoryReturnValue>> { | ||
if (value instanceof Response) { | ||
return makeResponseClone(value); | ||
} | ||
|
||
if (runtime.isHeadAndContent(value)) { | ||
return makeHeadAndContentClone(value); | ||
} | ||
|
||
return makeRenderTemplateClone(value); | ||
} | ||
|
||
export async function makeResponseClone(value: Response): Promise<Thunk<Response>> { | ||
const body = await value.arrayBuffer(); | ||
return () => new Response(body, value); | ||
} | ||
|
||
export async function makeRenderTemplateClone( | ||
value: RenderTemplateResult | ||
): Promise<Thunk<RenderTemplateResult>> { | ||
const chunks = await renderTemplateToChunks(value); | ||
return () => renderTemplateFromChunks(chunks); | ||
} | ||
|
||
export async function makeHeadAndContentClone( | ||
value: HeadAndContent, | ||
): Promise<Thunk<HeadAndContent>> { | ||
const chunks = await renderTemplateToChunks(value.content); | ||
return () => runtime.createHeadAndContent(value.head, renderTemplateFromChunks(chunks)); | ||
} | ||
|
||
export function renderTemplateFromChunks( | ||
chunks: RenderDestinationChunk[] | ||
): RenderTemplateResult { | ||
const template = runtime.renderTemplate(Object.assign([], { raw: [] })); | ||
|
||
return Object.assign(template, { | ||
render: (destination: RenderDestination) => { | ||
return new Promise<void>(resolve => { | ||
setImmediate(() => { | ||
for (const chunk of chunks) { | ||
destination.write(chunk); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
} | ||
}) | ||
} | ||
|
||
export async function renderTemplateToChunks(value: RenderTemplateResult): Promise<RenderDestinationChunk[]> { | ||
const chunks: RenderDestinationChunk[] = []; | ||
|
||
const cachedDestination: RenderDestination = { | ||
write(chunk) { | ||
// Drop empty chunks | ||
if (chunk) chunks.push(chunk); | ||
}, | ||
}; | ||
|
||
await value.render(cachedDestination); | ||
|
||
return chunks; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,4 +88,8 @@ export class MemoryCache<T> { | |
this.#cache.delete(key); | ||
}); | ||
} | ||
|
||
public clear(): void { | ||
this.#cache.clear(); | ||
} | ||
} |
Oops, something went wrong.