astro 2.9.1 → 2.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/astro-jsx.d.ts +1 -0
  2. package/components/ViewTransitions.astro +23 -0
  3. package/dist/assets/image-endpoint.d.ts +1 -1
  4. package/dist/assets/internal.js +2 -2
  5. package/dist/assets/services/service.d.ts +5 -5
  6. package/dist/assets/utils/index.d.ts +3 -0
  7. package/dist/assets/utils/index.js +8 -1
  8. package/dist/assets/vite-plugin-assets.js +0 -54
  9. package/dist/cli/load-settings.js +2 -1
  10. package/dist/config/index.js +1 -1
  11. package/dist/core/config/settings.d.ts +2 -2
  12. package/dist/core/config/settings.js +5 -5
  13. package/dist/core/constants.js +1 -1
  14. package/dist/core/dev/dev.js +1 -1
  15. package/dist/core/dev/restart.js +1 -1
  16. package/dist/core/messages.js +2 -2
  17. package/dist/core/render/result.js +4 -7
  18. package/dist/runtime/server/index.d.ts +1 -1
  19. package/dist/runtime/server/index.js +0 -6
  20. package/dist/runtime/server/jsx.js +4 -13
  21. package/dist/runtime/server/render/any.d.ts +2 -1
  22. package/dist/runtime/server/render/any.js +18 -22
  23. package/dist/runtime/server/render/astro/index.d.ts +1 -1
  24. package/dist/runtime/server/render/astro/index.js +1 -6
  25. package/dist/runtime/server/render/astro/instance.d.ts +3 -2
  26. package/dist/runtime/server/render/astro/instance.js +8 -4
  27. package/dist/runtime/server/render/astro/render-template.d.ts +2 -4
  28. package/dist/runtime/server/render/astro/render-template.js +8 -29
  29. package/dist/runtime/server/render/astro/render.js +4 -24
  30. package/dist/runtime/server/render/common.d.ts +17 -13
  31. package/dist/runtime/server/render/common.js +6 -21
  32. package/dist/runtime/server/render/component.d.ts +10 -4
  33. package/dist/runtime/server/render/component.js +131 -54
  34. package/dist/runtime/server/render/dom.d.ts +1 -1
  35. package/dist/runtime/server/render/index.d.ts +3 -3
  36. package/dist/runtime/server/render/index.js +6 -11
  37. package/dist/runtime/server/render/page.d.ts +2 -7
  38. package/dist/runtime/server/render/page.js +13 -62
  39. package/dist/runtime/server/render/slot.d.ts +2 -1
  40. package/dist/runtime/server/render/slot.js +23 -16
  41. package/dist/runtime/server/render/util.d.ts +0 -18
  42. package/dist/runtime/server/render/util.js +0 -101
  43. package/dist/vite-plugin-astro/compile.js +0 -1
  44. package/dist/vite-plugin-jsx/index.js +0 -1
  45. package/package.json +2 -2
package/astro-jsx.d.ts CHANGED
@@ -901,6 +901,7 @@ declare namespace astroHTML.JSX {
901
901
  crossorigin?: string | undefined | null;
902
902
  defer?: boolean | string | undefined | null;
903
903
  fetchpriority?: 'auto' | 'high' | 'low' | undefined | null;
904
+ referrerpolicy?: HTMLAttributeReferrerPolicy | undefined | null;
904
905
  integrity?: string | undefined | null;
905
906
  nomodule?: boolean | string | undefined | null;
906
907
  nonce?: string | undefined | null;
@@ -25,6 +25,7 @@ const { fallback = 'animate' } = Astro.props as Props;
25
25
  const supportsViewTransitions = !!document.startViewTransition;
26
26
  const transitionEnabledOnThisPage = () =>
27
27
  !!document.querySelector('[name="astro-view-transitions-enabled"]');
28
+ const onload = () => document.dispatchEvent(new Event('astro:load'));
28
29
 
29
30
  async function getHTML(href: string) {
30
31
  const res = await fetch(href);
@@ -40,6 +41,25 @@ const { fallback = 'animate' } = Astro.props as Props;
40
41
  return 'animate';
41
42
  }
42
43
 
44
+ function runScripts() {
45
+ let wait = Promise.resolve();
46
+ for (const script of Array.from(document.scripts)) {
47
+ const s = document.createElement('script');
48
+ s.innerHTML = script.innerHTML;
49
+ for (const attr of script.attributes) {
50
+ if (attr.name === 'src') {
51
+ const p = new Promise((r) => {
52
+ s.onload = r;
53
+ });
54
+ wait = wait.then(() => p as any);
55
+ }
56
+ s.setAttribute(attr.name, attr.value);
57
+ }
58
+ script.replaceWith(s);
59
+ }
60
+ return wait;
61
+ }
62
+
43
63
  const parser = new DOMParser();
44
64
 
45
65
  async function updateDOM(dir: Direction, html: string, fallback?: Fallback) {
@@ -95,6 +115,8 @@ const { fallback = 'animate' } = Astro.props as Props;
95
115
  await finished;
96
116
  } finally {
97
117
  document.documentElement.removeAttribute('data-astro-transition');
118
+ await runScripts();
119
+ onload();
98
120
  }
99
121
  }
100
122
 
@@ -171,5 +193,6 @@ const { fallback = 'animate' } = Astro.props as Props;
171
193
  { passive: true, capture: true }
172
194
  );
173
195
  });
196
+ addEventListener('load', onload);
174
197
  }
175
198
  </script>
@@ -1,5 +1,5 @@
1
1
  import type { APIRoute } from '../@types/astro.js';
2
2
  /**
3
- * Endpoint used in SSR to serve optimized images
3
+ * Endpoint used in dev and SSR to serve optimized images by the base image services
4
4
  */
5
5
  export declare const get: APIRoute;
@@ -29,8 +29,8 @@ async function getImage(options, serviceConfig) {
29
29
  });
30
30
  }
31
31
  const service = await getConfiguredImageService();
32
- const validatedOptions = service.validateOptions ? service.validateOptions(options, serviceConfig) : options;
33
- let imageURL = service.getURL(validatedOptions, serviceConfig);
32
+ const validatedOptions = service.validateOptions ? await service.validateOptions(options, serviceConfig) : options;
33
+ let imageURL = await service.getURL(validatedOptions, serviceConfig);
34
34
  if (isLocalService(service) && globalThis.astroAsset.addStaticImage) {
35
35
  imageURL = globalThis.astroAsset.addStaticImage(validatedOptions);
36
36
  }
@@ -12,14 +12,14 @@ interface SharedServiceProps {
12
12
  * For external services, this should point to the URL your images are coming from, for instance, `/_vercel/image`
13
13
  *
14
14
  */
15
- getURL: (options: ImageTransform, serviceConfig: Record<string, any>) => string;
15
+ getURL: (options: ImageTransform, serviceConfig: Record<string, any>) => string | Promise<string>;
16
16
  /**
17
17
  * Return any additional HTML attributes separate from `src` that your service requires to show the image properly.
18
18
  *
19
19
  * For example, you might want to return the `width` and `height` to avoid CLS, or a particular `class` or `style`.
20
20
  * In most cases, you'll want to return directly what your user supplied you, minus the attributes that were used to generate the image.
21
21
  */
22
- getHTMLAttributes?: (options: ImageTransform, serviceConfig: Record<string, any>) => Record<string, any>;
22
+ getHTMLAttributes?: (options: ImageTransform, serviceConfig: Record<string, any>) => Record<string, any> | Promise<Record<string, any>>;
23
23
  /**
24
24
  * Validate and return the options passed by the user.
25
25
  *
@@ -28,7 +28,7 @@ interface SharedServiceProps {
28
28
  *
29
29
  * This method should returns options, and can be used to set defaults (ex: a default output format to be used if the user didn't specify one.)
30
30
  */
31
- validateOptions?: (options: ImageTransform, serviceConfig: Record<string, any>) => ImageTransform;
31
+ validateOptions?: (options: ImageTransform, serviceConfig: Record<string, any>) => ImageTransform | Promise<ImageTransform>;
32
32
  }
33
33
  export type ExternalImageService = SharedServiceProps;
34
34
  export type LocalImageTransform = {
@@ -37,11 +37,11 @@ export type LocalImageTransform = {
37
37
  };
38
38
  export interface LocalImageService extends SharedServiceProps {
39
39
  /**
40
- * Parse the requested parameters passed in the URL from `getURL` back into an object to be used later by `transform`
40
+ * Parse the requested parameters passed in the URL from `getURL` back into an object to be used later by `transform`.
41
41
  *
42
42
  * In most cases, this will get query parameters using, for example, `params.get('width')` and return those.
43
43
  */
44
- parseURL: (url: URL, serviceConfig: Record<string, any>) => LocalImageTransform | undefined;
44
+ parseURL: (url: URL, serviceConfig: Record<string, any>) => LocalImageTransform | undefined | Promise<LocalImageTransform> | Promise<undefined>;
45
45
  /**
46
46
  * Performs the image transformations on the input image and returns both the binary data and
47
47
  * final image format of the optimized image.
@@ -1 +1,4 @@
1
1
  export { emitESMImage } from './emitAsset.js';
2
+ export { imageMetadata } from './metadata.js';
3
+ export { getOrigQueryParams } from './queryParams.js';
4
+ export { hashTransform, propsToFilename } from './transformToPath.js';
@@ -1,4 +1,11 @@
1
1
  import { emitESMImage } from "./emitAsset.js";
2
+ import { imageMetadata } from "./metadata.js";
3
+ import { getOrigQueryParams } from "./queryParams.js";
4
+ import { hashTransform, propsToFilename } from "./transformToPath.js";
2
5
  export {
3
- emitESMImage
6
+ emitESMImage,
7
+ getOrigQueryParams,
8
+ hashTransform,
9
+ imageMetadata,
10
+ propsToFilename
4
11
  };
@@ -1,8 +1,5 @@
1
1
  import { bold } from "kleur/colors";
2
2
  import MagicString from "magic-string";
3
- import mime from "mime/lite.js";
4
- import fs from "node:fs/promises";
5
- import { Readable } from "node:stream";
6
3
  import { fileURLToPath } from "node:url";
7
4
  import { normalizePath } from "vite";
8
5
  import { error } from "../core/logger/core.js";
@@ -14,10 +11,7 @@ import {
14
11
  } from "../core/path.js";
15
12
  import { VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
16
13
  import { isESMImportedImage } from "./internal.js";
17
- import { isLocalService } from "./services/service.js";
18
14
  import { emitESMImage } from "./utils/emitAsset.js";
19
- import { imageMetadata } from "./utils/metadata.js";
20
- import { getOrigQueryParams } from "./utils/queryParams.js";
21
15
  import { hashTransform, propsToFilename } from "./utils/transformToPath.js";
22
16
  const resolvedVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
23
17
  const rawRE = /(?:\?|&)raw(?:&|$)/;
@@ -84,54 +78,6 @@ function assets({
84
78
  `;
85
79
  }
86
80
  },
87
- // Handle serving images during development
88
- configureServer(server) {
89
- server.middlewares.use(async (req, res, next) => {
90
- var _a2, _b;
91
- if ((_a2 = req.url) == null ? void 0 : _a2.startsWith("/_image")) {
92
- if (!isLocalService(globalThis.astroAsset.imageService)) {
93
- return next();
94
- }
95
- const url = new URL(req.url, "file:");
96
- if (!url.searchParams.has("href")) {
97
- return next();
98
- }
99
- const filePath = (_b = url.searchParams.get("href")) == null ? void 0 : _b.slice("/@fs".length);
100
- const filePathURL = new URL("." + filePath, "file:");
101
- const file = await fs.readFile(filePathURL);
102
- let meta = getOrigQueryParams(filePathURL.searchParams);
103
- if (!meta) {
104
- meta = await imageMetadata(filePathURL, file);
105
- if (!meta) {
106
- return next();
107
- }
108
- }
109
- const transform = await globalThis.astroAsset.imageService.parseURL(
110
- url,
111
- settings.config.image.service.config
112
- );
113
- if (transform === void 0) {
114
- error(logging, "image", `Failed to parse transform for ${url}`);
115
- }
116
- let data = file;
117
- let format = meta.format;
118
- if (transform) {
119
- const result = await globalThis.astroAsset.imageService.transform(
120
- file,
121
- transform,
122
- settings.config.image.service.config
123
- );
124
- data = result.data;
125
- format = result.format;
126
- }
127
- res.setHeader("Content-Type", mime.getType(format) ?? `image/${format}`);
128
- res.setHeader("Cache-Control", "max-age=360000");
129
- const stream = Readable.from(data);
130
- return stream.pipe(res);
131
- }
132
- return next();
133
- });
134
- },
135
81
  buildStart() {
136
82
  if (mode != "build") {
137
83
  return;
@@ -17,10 +17,11 @@ async function loadSettings({ cmd, flags, logging }) {
17
17
  await handleConfigError(e, { cmd, cwd: root, flags, logging });
18
18
  return {};
19
19
  });
20
+ const mode = cmd === "build" ? "build" : "dev";
20
21
  if (!initialAstroConfig)
21
22
  return;
22
23
  telemetry.record(event.eventCliSession(cmd, initialUserConfig, flags));
23
- return createSettings(initialAstroConfig, root);
24
+ return createSettings(initialAstroConfig, mode, root);
24
25
  }
25
26
  async function handleConfigError(e, { cmd, cwd, flags, logging }) {
26
27
  const path = await resolveConfigPath({ cwd, flags, fs });
@@ -26,7 +26,7 @@ function getViteConfig(inlineConfig) {
26
26
  level: "info"
27
27
  };
28
28
  const { astroConfig: config } = await openConfig({ cmd });
29
- const settings = createSettings(config, inlineConfig.root);
29
+ const settings = createSettings(config, cmd, inlineConfig.root);
30
30
  await runHookConfigSetup({ settings, command: cmd, logging });
31
31
  const viteConfig = await createVite(
32
32
  {
@@ -1,4 +1,4 @@
1
1
  import type { AstroConfig, AstroSettings, AstroUserConfig } from '../../@types/astro';
2
- export declare function createBaseSettings(config: AstroConfig): AstroSettings;
3
- export declare function createSettings(config: AstroConfig, cwd?: string): AstroSettings;
2
+ export declare function createBaseSettings(config: AstroConfig, mode: 'build' | 'dev'): AstroSettings;
3
+ export declare function createSettings(config: AstroConfig, mode: 'build' | 'dev', cwd?: string): AstroSettings;
4
4
  export declare function createDefaultDevSettings(userConfig?: AstroUserConfig, root?: string | URL): Promise<AstroSettings>;
@@ -12,14 +12,14 @@ import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./../constants.js";
12
12
  import { createDefaultDevConfig } from "./config.js";
13
13
  import { AstroTimer } from "./timer.js";
14
14
  import { loadTSConfig } from "./tsconfig.js";
15
- function createBaseSettings(config) {
15
+ function createBaseSettings(config, mode) {
16
16
  const { contentDir } = getContentPaths(config);
17
17
  return {
18
18
  config,
19
19
  tsConfig: void 0,
20
20
  tsConfigPath: void 0,
21
21
  adapter: void 0,
22
- injectedRoutes: config.experimental.assets && isServerLikeOutput(config) ? [{ pattern: "/_image", entryPoint: "astro/assets/image-endpoint", prerender: false }] : [],
22
+ injectedRoutes: config.experimental.assets && (isServerLikeOutput(config) || mode === "dev") ? [{ pattern: "/_image", entryPoint: "astro/assets/image-endpoint", prerender: false }] : [],
23
23
  pageExtensions: [".astro", ".html", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
24
24
  contentEntryTypes: [markdownContentEntryType],
25
25
  dataEntryTypes: [
@@ -92,9 +92,9 @@ function createBaseSettings(config) {
92
92
  timer: new AstroTimer()
93
93
  };
94
94
  }
95
- function createSettings(config, cwd) {
95
+ function createSettings(config, mode, cwd) {
96
96
  const tsconfig = loadTSConfig(cwd);
97
- const settings = createBaseSettings(config);
97
+ const settings = createBaseSettings(config, mode);
98
98
  const watchFiles = (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : [];
99
99
  if (cwd) {
100
100
  watchFiles.push(fileURLToPath(new URL("./package.json", pathToFileURL(cwd))));
@@ -109,7 +109,7 @@ async function createDefaultDevSettings(userConfig = {}, root) {
109
109
  root = fileURLToPath(root);
110
110
  }
111
111
  const config = await createDefaultDevConfig(userConfig, root);
112
- return createBaseSettings(config);
112
+ return createBaseSettings(config, "dev");
113
113
  }
114
114
  export {
115
115
  createBaseSettings,
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.9.1";
1
+ const ASTRO_VERSION = "2.9.3";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -54,7 +54,7 @@ async function dev(settings, options) {
54
54
  isRestart: options.isRestart
55
55
  })
56
56
  );
57
- const currentVersion = "2.9.1";
57
+ const currentVersion = "2.9.3";
58
58
  if (currentVersion.includes("-")) {
59
59
  warn(options.logging, null, msg.prerelease({ currentVersion }));
60
60
  }
@@ -62,7 +62,7 @@ async function restartContainer({
62
62
  });
63
63
  info(logging, "astro", logMsg + "\n");
64
64
  let astroConfig = newConfig.astroConfig;
65
- const settings = createSettings(astroConfig, resolvedRoot);
65
+ const settings = createSettings(astroConfig, "dev", resolvedRoot);
66
66
  await close();
67
67
  return {
68
68
  container: await createRestartedContainer(container, settings, needsStart),
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.9.1";
50
+ const version = "2.9.3";
51
51
  const localPrefix = `${dim("\u2503")} Local `;
52
52
  const networkPrefix = `${dim("\u2503")} Network `;
53
53
  const emptyPrefix = " ".repeat(11);
@@ -233,7 +233,7 @@ function printHelp({
233
233
  message.push(
234
234
  linebreak(),
235
235
  ` ${bgGreen(black(` ${commandName} `))} ${green(
236
- `v${"2.9.1"}`
236
+ `v${"2.9.3"}`
237
237
  )} ${headline}`
238
238
  );
239
239
  }
@@ -1,9 +1,6 @@
1
- import { isHTMLString } from "../../runtime/server/escape.js";
2
- import {
3
- renderSlotToString,
4
- stringifyChunk
5
- } from "../../runtime/server/index.js";
1
+ import { renderSlotToString } from "../../runtime/server/index.js";
6
2
  import { renderJSX } from "../../runtime/server/jsx.js";
3
+ import { chunkToString } from "../../runtime/server/render/index.js";
7
4
  import { AstroCookies } from "../cookies/index.js";
8
5
  import { AstroError, AstroErrorData } from "../errors/index.js";
9
6
  import { warn } from "../logger/core.js";
@@ -62,7 +59,7 @@ class Slots {
62
59
  const component = typeof slotValue === "function" ? await slotValue(result) : await slotValue;
63
60
  const expression = getFunctionExpression(component);
64
61
  if (expression) {
65
- const slot = async () => isHTMLString(await expression) ? expression : expression(...args);
62
+ const slot = async () => typeof expression === "function" ? expression(...args) : expression;
66
63
  return await renderSlotToString(result, slot).then((res) => {
67
64
  return res != null ? String(res) : res;
68
65
  });
@@ -74,7 +71,7 @@ class Slots {
74
71
  }
75
72
  }
76
73
  const content = await renderSlotToString(result, this.#slots[name]);
77
- const outHTML = stringifyChunk(result, content);
74
+ const outHTML = chunkToString(result, content);
78
75
  return outHTML;
79
76
  }
80
77
  }
@@ -3,7 +3,7 @@ export { createAstro } from './astro-global.js';
3
3
  export { renderEndpoint } from './endpoint.js';
4
4
  export { escapeHTML, HTMLBytes, HTMLString, isHTMLString, markHTMLString, unescapeHTML, } from './escape.js';
5
5
  export { renderJSX } from './jsx.js';
6
- export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderTemplate as render, renderAstroTemplateResult as renderAstroComponent, renderComponent, renderComponentToIterable, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderScriptElement, renderSlot, renderSlotToString, renderTemplate, renderToString, renderUniqueStylesheet, stringifyChunk, voidElementNames, } from './render/index.js';
6
+ export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderTemplate as render, renderComponent, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderScriptElement, renderSlot, renderSlotToString, renderTemplate, renderToString, renderUniqueStylesheet, voidElementNames, } from './render/index.js';
7
7
  export type { AstroComponentFactory, AstroComponentInstance, ComponentSlots, RenderInstruction, } from './render/index.js';
8
8
  export { renderTransition } from './transition.js';
9
9
  export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
@@ -17,9 +17,7 @@ import {
17
17
  Fragment,
18
18
  maybeRenderHead,
19
19
  renderTemplate,
20
- renderAstroTemplateResult,
21
20
  renderComponent,
22
- renderComponentToIterable,
23
21
  Renderer,
24
22
  renderHead,
25
23
  renderHTMLElement,
@@ -30,7 +28,6 @@ import {
30
28
  renderTemplate as renderTemplate2,
31
29
  renderToString,
32
30
  renderUniqueStylesheet,
33
- stringifyChunk,
34
31
  voidElementNames
35
32
  } from "./render/index.js";
36
33
  import { renderTransition } from "./transition.js";
@@ -106,9 +103,7 @@ export {
106
103
  maybeRenderHead,
107
104
  mergeSlots,
108
105
  renderTemplate as render,
109
- renderAstroTemplateResult as renderAstroComponent,
110
106
  renderComponent,
111
- renderComponentToIterable,
112
107
  renderEndpoint,
113
108
  renderHTMLElement,
114
109
  renderHead,
@@ -122,7 +117,6 @@ export {
122
117
  renderTransition,
123
118
  renderUniqueStylesheet,
124
119
  spreadAttributes,
125
- stringifyChunk,
126
120
  unescapeHTML,
127
121
  voidElementNames
128
122
  };
@@ -3,12 +3,11 @@ import {
3
3
  HTMLString,
4
4
  escapeHTML,
5
5
  markHTMLString,
6
- renderComponentToIterable,
7
6
  renderToString,
8
7
  spreadAttributes,
9
8
  voidElementNames
10
9
  } from "./index.js";
11
- import { HTMLParts } from "./render/common.js";
10
+ import { renderComponentToString } from "./render/component.js";
12
11
  const ClientOnlyPlaceholder = "astro-client-only";
13
12
  class Skip {
14
13
  constructor(vnode) {
@@ -164,7 +163,7 @@ Did you forget to import the component or is it possible there is a typo?`);
164
163
  props[Skip.symbol] = skip;
165
164
  let output;
166
165
  if (vnode.type === ClientOnlyPlaceholder && vnode.props["client:only"]) {
167
- output = await renderComponentToIterable(
166
+ output = await renderComponentToString(
168
167
  result,
169
168
  vnode.props["client:display-name"] ?? "",
170
169
  null,
@@ -172,7 +171,7 @@ Did you forget to import the component or is it possible there is a typo?`);
172
171
  slots
173
172
  );
174
173
  } else {
175
- output = await renderComponentToIterable(
174
+ output = await renderComponentToString(
176
175
  result,
177
176
  typeof vnode.type === "function" ? vnode.type.name : vnode.type,
178
177
  vnode.type,
@@ -180,15 +179,7 @@ Did you forget to import the component or is it possible there is a typo?`);
180
179
  slots
181
180
  );
182
181
  }
183
- if (typeof output !== "string" && Symbol.asyncIterator in output) {
184
- let parts = new HTMLParts();
185
- for await (const chunk of output) {
186
- parts.append(chunk, result);
187
- }
188
- return markHTMLString(parts.toString());
189
- } else {
190
- return markHTMLString(output);
191
- }
182
+ return markHTMLString(output);
192
183
  }
193
184
  }
194
185
  return markHTMLString(`${vnode}`);
@@ -1 +1,2 @@
1
- export declare function renderChild(child: any): AsyncIterable<any>;
1
+ import { type RenderDestination } from './common.js';
2
+ export declare function renderChild(destination: RenderDestination, child: any): Promise<void>;
@@ -1,40 +1,36 @@
1
1
  import { escapeHTML, isHTMLString, markHTMLString } from "../escape.js";
2
- import {
3
- isAstroComponentInstance,
4
- isRenderTemplateResult,
5
- renderAstroTemplateResult
6
- } from "./astro/index.js";
2
+ import { isAstroComponentInstance, isRenderTemplateResult } from "./astro/index.js";
3
+ import { isRenderInstance } from "./common.js";
7
4
  import { SlotString } from "./slot.js";
8
- import { bufferIterators } from "./util.js";
9
- async function* renderChild(child) {
5
+ async function renderChild(destination, child) {
10
6
  child = await child;
11
7
  if (child instanceof SlotString) {
12
- if (child.instructions) {
13
- yield* child.instructions;
14
- }
15
- yield child;
8
+ destination.write(child);
16
9
  } else if (isHTMLString(child)) {
17
- yield child;
10
+ destination.write(child);
18
11
  } else if (Array.isArray(child)) {
19
- const bufferedIterators = bufferIterators(child.map((c) => renderChild(c)));
20
- for (const value of bufferedIterators) {
21
- yield markHTMLString(await value);
12
+ for (const c of child) {
13
+ await renderChild(destination, c);
22
14
  }
23
15
  } else if (typeof child === "function") {
24
- yield* renderChild(child());
16
+ await renderChild(destination, child());
25
17
  } else if (typeof child === "string") {
26
- yield markHTMLString(escapeHTML(child));
18
+ destination.write(markHTMLString(escapeHTML(child)));
27
19
  } else if (!child && child !== 0) {
20
+ } else if (isRenderInstance(child)) {
21
+ await child.render(destination);
28
22
  } else if (isRenderTemplateResult(child)) {
29
- yield* renderAstroTemplateResult(child);
23
+ await child.render(destination);
30
24
  } else if (isAstroComponentInstance(child)) {
31
- yield* child.render();
25
+ await child.render(destination);
32
26
  } else if (ArrayBuffer.isView(child)) {
33
- yield child;
27
+ destination.write(child);
34
28
  } else if (typeof child === "object" && (Symbol.asyncIterator in child || Symbol.iterator in child)) {
35
- yield* child;
29
+ for await (const value of child) {
30
+ await renderChild(destination, value);
31
+ }
36
32
  } else {
37
- yield child;
33
+ destination.write(child);
38
34
  }
39
35
  }
40
36
  export {
@@ -3,5 +3,5 @@ export { isAstroComponentFactory } from './factory.js';
3
3
  export { createHeadAndContent, isHeadAndContent } from './head-and-content.js';
4
4
  export type { AstroComponentInstance } from './instance';
5
5
  export { createAstroComponentInstance, isAstroComponentInstance } from './instance.js';
6
- export { isRenderTemplateResult, renderAstroTemplateResult, renderTemplate, } from './render-template.js';
6
+ export { isRenderTemplateResult, renderTemplate } from './render-template.js';
7
7
  export { renderToReadableStream, renderToString } from './render.js';
@@ -1,11 +1,7 @@
1
1
  import { isAstroComponentFactory } from "./factory.js";
2
2
  import { createHeadAndContent, isHeadAndContent } from "./head-and-content.js";
3
3
  import { createAstroComponentInstance, isAstroComponentInstance } from "./instance.js";
4
- import {
5
- isRenderTemplateResult,
6
- renderAstroTemplateResult,
7
- renderTemplate
8
- } from "./render-template.js";
4
+ import { isRenderTemplateResult, renderTemplate } from "./render-template.js";
9
5
  import { renderToReadableStream, renderToString } from "./render.js";
10
6
  export {
11
7
  createAstroComponentInstance,
@@ -14,7 +10,6 @@ export {
14
10
  isAstroComponentInstance,
15
11
  isHeadAndContent,
16
12
  isRenderTemplateResult,
17
- renderAstroTemplateResult,
18
13
  renderTemplate,
19
14
  renderToReadableStream,
20
15
  renderToString
@@ -1,6 +1,7 @@
1
1
  import type { SSRResult } from '../../../../@types/astro';
2
2
  import type { ComponentSlots } from '../slot.js';
3
3
  import type { AstroComponentFactory, AstroFactoryReturnValue } from './factory.js';
4
+ import type { RenderDestination } from '../common.js';
4
5
  type ComponentProps = Record<string | number, any>;
5
6
  declare const astroComponentInstanceSym: unique symbol;
6
7
  export declare class AstroComponentInstance {
@@ -12,8 +13,8 @@ export declare class AstroComponentInstance {
12
13
  private returnValue;
13
14
  constructor(result: SSRResult, props: ComponentProps, slots: ComponentSlots, factory: AstroComponentFactory);
14
15
  init(result: SSRResult): Promise<AstroFactoryReturnValue>;
15
- render(): AsyncGenerator<any, void, undefined>;
16
+ render(destination: RenderDestination): Promise<void>;
16
17
  }
17
- export declare function createAstroComponentInstance(result: SSRResult, displayName: string, factory: AstroComponentFactory, props: ComponentProps, slots?: any): AstroComponentInstance;
18
+ export declare function createAstroComponentInstance(result: SSRResult, displayName: string, factory: AstroComponentFactory, props: ComponentProps, slots?: any): Promise<AstroComponentInstance>;
18
19
  export declare function isAstroComponentInstance(obj: unknown): obj is AstroComponentInstance;
19
20
  export {};
@@ -20,7 +20,7 @@ class AstroComponentInstance {
20
20
  this.returnValue = this.factory(result, this.props, this.slotValues);
21
21
  return this.returnValue;
22
22
  }
23
- async *render() {
23
+ async render(destination) {
24
24
  if (this.returnValue === void 0) {
25
25
  await this.init(this.result);
26
26
  }
@@ -29,9 +29,9 @@ class AstroComponentInstance {
29
29
  value = await value;
30
30
  }
31
31
  if (isHeadAndContent(value)) {
32
- yield* value.content;
32
+ await value.content.render(destination);
33
33
  } else {
34
- yield* renderChild(value);
34
+ await renderChild(destination, value);
35
35
  }
36
36
  }
37
37
  }
@@ -47,11 +47,15 @@ function validateComponentProps(props, displayName) {
47
47
  }
48
48
  }
49
49
  }
50
- function createAstroComponentInstance(result, displayName, factory, props, slots = {}) {
50
+ async function createAstroComponentInstance(result, displayName, factory, props, slots = {}) {
51
51
  validateComponentProps(props, displayName);
52
52
  const instance = new AstroComponentInstance(result, props, slots, factory);
53
53
  if (isAPropagatingComponent(result, factory) && !result._metadata.propagators.has(factory)) {
54
54
  result._metadata.propagators.set(factory, instance);
55
+ const returnValue = await instance.init(result);
56
+ if (isHeadAndContent(returnValue)) {
57
+ result._metadata.extraHead.push(returnValue.head);
58
+ }
55
59
  }
56
60
  return instance;
57
61
  }
@@ -1,5 +1,4 @@
1
- import type { RenderInstruction } from '../types';
2
- import { HTMLBytes } from '../../escape.js';
1
+ import type { RenderDestination } from '../common.js';
3
2
  declare const renderTemplateResultSym: unique symbol;
4
3
  export declare class RenderTemplateResult {
5
4
  [renderTemplateResultSym]: boolean;
@@ -7,9 +6,8 @@ export declare class RenderTemplateResult {
7
6
  private expressions;
8
7
  private error;
9
8
  constructor(htmlParts: TemplateStringsArray, expressions: unknown[]);
10
- [Symbol.asyncIterator](): AsyncGenerator<any, void, undefined>;
9
+ render(destination: RenderDestination): Promise<void>;
11
10
  }
12
11
  export declare function isRenderTemplateResult(obj: unknown): obj is RenderTemplateResult;
13
- export declare function renderAstroTemplateResult(component: RenderTemplateResult): AsyncIterable<string | HTMLBytes | RenderInstruction>;
14
12
  export declare function renderTemplate(htmlParts: TemplateStringsArray, ...expressions: any[]): RenderTemplateResult;
15
13
  export {};