astro 2.9.2 → 2.9.4

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 (51) hide show
  1. package/components/ViewTransitions.astro +37 -2
  2. package/dist/@types/astro.d.ts +1 -0
  3. package/dist/assets/internal.d.ts +2 -0
  4. package/dist/assets/internal.js +9 -0
  5. package/dist/assets/services/squoosh.js +3 -5
  6. package/dist/assets/types.d.ts +1 -1
  7. package/dist/assets/utils/emitAsset.js +21 -11
  8. package/dist/assets/utils/metadata.d.ts +1 -1
  9. package/dist/assets/utils/metadata.js +2 -13
  10. package/dist/cli/add/index.js +1 -1
  11. package/dist/cli/load-settings.js +1 -2
  12. package/dist/config/index.js +1 -1
  13. package/dist/content/runtime.js +2 -2
  14. package/dist/core/build/generate.js +5 -2
  15. package/dist/core/build/index.js +5 -0
  16. package/dist/core/config/settings.d.ts +2 -2
  17. package/dist/core/config/settings.js +5 -6
  18. package/dist/core/constants.js +1 -1
  19. package/dist/core/dev/container.js +4 -0
  20. package/dist/core/dev/dev.js +1 -1
  21. package/dist/core/dev/restart.js +1 -1
  22. package/dist/core/messages.js +2 -2
  23. package/dist/core/render/result.js +6 -8
  24. package/dist/runtime/server/index.d.ts +1 -1
  25. package/dist/runtime/server/index.js +2 -6
  26. package/dist/runtime/server/jsx.js +4 -13
  27. package/dist/runtime/server/render/any.d.ts +2 -1
  28. package/dist/runtime/server/render/any.js +18 -22
  29. package/dist/runtime/server/render/astro/index.d.ts +1 -1
  30. package/dist/runtime/server/render/astro/index.js +1 -6
  31. package/dist/runtime/server/render/astro/instance.d.ts +3 -2
  32. package/dist/runtime/server/render/astro/instance.js +8 -4
  33. package/dist/runtime/server/render/astro/render-template.d.ts +2 -4
  34. package/dist/runtime/server/render/astro/render-template.js +8 -29
  35. package/dist/runtime/server/render/astro/render.js +4 -8
  36. package/dist/runtime/server/render/common.d.ts +17 -13
  37. package/dist/runtime/server/render/common.js +4 -20
  38. package/dist/runtime/server/render/component.d.ts +10 -4
  39. package/dist/runtime/server/render/component.js +131 -54
  40. package/dist/runtime/server/render/dom.d.ts +1 -1
  41. package/dist/runtime/server/render/index.d.ts +4 -4
  42. package/dist/runtime/server/render/index.js +8 -12
  43. package/dist/runtime/server/render/page.d.ts +2 -7
  44. package/dist/runtime/server/render/page.js +13 -62
  45. package/dist/runtime/server/render/slot.d.ts +2 -1
  46. package/dist/runtime/server/render/slot.js +23 -16
  47. package/dist/runtime/server/render/tags.d.ts +1 -0
  48. package/dist/runtime/server/render/tags.js +34 -1
  49. package/dist/runtime/server/render/util.d.ts +0 -18
  50. package/dist/runtime/server/render/util.js +0 -101
  51. package/package.json +2 -2
@@ -1,27 +1,23 @@
1
- import {
2
- createHeadAndContent,
3
- renderAstroTemplateResult,
4
- renderTemplate,
5
- renderToString
6
- } from "./astro/index.js";
7
- import { Fragment, Renderer, stringifyChunk } from "./common.js";
8
- import { renderComponent, renderComponentToIterable } from "./component.js";
1
+ import { createHeadAndContent, renderTemplate, renderToString } from "./astro/index.js";
2
+ import { Fragment, Renderer, chunkToByteArray, chunkToString } from "./common.js";
3
+ import { renderComponent, renderComponentToString } from "./component.js";
9
4
  import { renderHTMLElement } from "./dom.js";
10
5
  import { maybeRenderHead, renderHead } from "./head.js";
11
6
  import { renderPage } from "./page.js";
12
7
  import { renderSlot, renderSlotToString } from "./slot.js";
13
- import { renderScriptElement, renderUniqueStylesheet } from "./tags.js";
8
+ import { renderScriptElement, renderUniqueScriptElement, renderUniqueStylesheet } from "./tags.js";
14
9
  import { addAttribute, defineScriptVars, voidElementNames } from "./util.js";
15
10
  export {
16
11
  Fragment,
17
12
  Renderer,
18
13
  addAttribute,
14
+ chunkToByteArray,
15
+ chunkToString,
19
16
  createHeadAndContent,
20
17
  defineScriptVars,
21
18
  maybeRenderHead,
22
- renderAstroTemplateResult,
23
19
  renderComponent,
24
- renderComponentToIterable,
20
+ renderComponentToString,
25
21
  renderHTMLElement,
26
22
  renderHead,
27
23
  renderPage,
@@ -30,7 +26,7 @@ export {
30
26
  renderSlotToString,
31
27
  renderTemplate,
32
28
  renderToString,
29
+ renderUniqueScriptElement,
33
30
  renderUniqueStylesheet,
34
- stringifyChunk,
35
31
  voidElementNames
36
32
  };
@@ -1,9 +1,4 @@
1
1
  import type { RouteData, SSRResult } from '../../../@types/astro';
2
+ import { type NonAstroPageComponent } from './component.js';
2
3
  import type { AstroComponentFactory } from './index';
3
- declare const needsHeadRenderingSymbol: unique symbol;
4
- type NonAstroPageComponent = {
5
- name: string;
6
- [needsHeadRenderingSymbol]: boolean;
7
- };
8
- export declare function renderPage(result: SSRResult, componentFactory: AstroComponentFactory | NonAstroPageComponent, props: any, children: any, streaming: boolean, route?: RouteData | undefined): Promise<Response>;
9
- export {};
4
+ export declare function renderPage(result: SSRResult, componentFactory: AstroComponentFactory | NonAstroPageComponent, props: any, children: any, streaming: boolean, route?: RouteData): Promise<Response>;
@@ -1,72 +1,23 @@
1
- import { AstroError } from "../../../core/errors/index.js";
2
- import { isHTMLString } from "../escape.js";
1
+ import { renderComponentToString } from "./component.js";
3
2
  import { createResponse } from "../response.js";
4
- import { isAstroComponentFactory, isAstroComponentInstance } from "./astro/index.js";
3
+ import { isAstroComponentFactory } from "./astro/index.js";
5
4
  import { renderToReadableStream, renderToString } from "./astro/render.js";
6
- import { HTMLParts, encoder } from "./common.js";
7
- import { renderComponent } from "./component.js";
8
- import { maybeRenderHead } from "./head.js";
9
- const needsHeadRenderingSymbol = Symbol.for("astro.needsHeadRendering");
10
- function nonAstroPageNeedsHeadInjection(pageComponent) {
11
- return needsHeadRenderingSymbol in pageComponent && !!pageComponent[needsHeadRenderingSymbol];
12
- }
13
- async function iterableToHTMLBytes(result, iterable, onDocTypeInjection) {
14
- const parts = new HTMLParts();
15
- let i = 0;
16
- for await (const chunk of iterable) {
17
- if (isHTMLString(chunk)) {
18
- if (i === 0) {
19
- i++;
20
- if (!/<!doctype html/i.test(String(chunk))) {
21
- parts.append(`${result.compressHTML ? "<!DOCTYPE html>" : "<!DOCTYPE html>\n"}`, result);
22
- if (onDocTypeInjection) {
23
- await onDocTypeInjection(parts);
24
- }
25
- }
26
- }
27
- }
28
- parts.append(chunk, result);
29
- }
30
- return parts.toArrayBuffer();
31
- }
5
+ import { encoder } from "./common.js";
32
6
  async function renderPage(result, componentFactory, props, children, streaming, route) {
33
7
  var _a, _b;
34
8
  if (!isAstroComponentFactory(componentFactory)) {
35
9
  result._metadata.headInTree = ((_a = result.componentMetadata.get(componentFactory.moduleId)) == null ? void 0 : _a.containsHead) ?? false;
36
10
  const pageProps = { ...props ?? {}, "server:root": true };
37
- let output;
38
- let head = "";
39
- try {
40
- if (nonAstroPageNeedsHeadInjection(componentFactory)) {
41
- const parts = new HTMLParts();
42
- for await (const chunk of maybeRenderHead()) {
43
- parts.append(chunk, result);
44
- }
45
- head = parts.toString();
46
- }
47
- const renderResult = await renderComponent(
48
- result,
49
- componentFactory.name,
50
- componentFactory,
51
- pageProps,
52
- null
53
- );
54
- if (isAstroComponentInstance(renderResult)) {
55
- output = renderResult.render();
56
- } else {
57
- output = renderResult;
58
- }
59
- } catch (e) {
60
- if (AstroError.is(e) && !e.loc) {
61
- e.setLocation({
62
- file: route == null ? void 0 : route.component
63
- });
64
- }
65
- throw e;
66
- }
67
- const bytes = await iterableToHTMLBytes(result, output, async (parts) => {
68
- parts.append(head, result);
69
- });
11
+ const str = await renderComponentToString(
12
+ result,
13
+ componentFactory.name,
14
+ componentFactory,
15
+ pageProps,
16
+ null,
17
+ true,
18
+ route
19
+ );
20
+ const bytes = encoder.encode(str);
70
21
  return new Response(bytes, {
71
22
  headers: new Headers([
72
23
  ["Content-Type", "text/html; charset=utf-8"],
@@ -2,6 +2,7 @@ import type { SSRResult } from '../../../@types/astro.js';
2
2
  import type { renderTemplate } from './astro/render-template.js';
3
3
  import type { RenderInstruction } from './types.js';
4
4
  import { HTMLString } from '../escape.js';
5
+ import { type RenderInstance } from './common.js';
5
6
  type RenderTemplateResult = ReturnType<typeof renderTemplate>;
6
7
  export type ComponentSlots = Record<string, ComponentSlotValue>;
7
8
  export type ComponentSlotValue = (result: SSRResult) => RenderTemplateResult | Promise<RenderTemplateResult>;
@@ -12,7 +13,7 @@ export declare class SlotString extends HTMLString {
12
13
  constructor(content: string, instructions: null | RenderInstruction[]);
13
14
  }
14
15
  export declare function isSlotString(str: string): str is any;
15
- export declare function renderSlot(result: SSRResult, slotted: ComponentSlotValue | RenderTemplateResult, fallback?: ComponentSlotValue | RenderTemplateResult): AsyncGenerator<any, void, undefined>;
16
+ export declare function renderSlot(result: SSRResult, slotted: ComponentSlotValue | RenderTemplateResult, fallback?: ComponentSlotValue | RenderTemplateResult): RenderInstance;
16
17
  export declare function renderSlotToString(result: SSRResult, slotted: ComponentSlotValue | RenderTemplateResult, fallback?: ComponentSlotValue | RenderTemplateResult): Promise<string>;
17
18
  interface RenderSlotsResult {
18
19
  slotInstructions: null | RenderInstruction[];
@@ -1,5 +1,6 @@
1
1
  import { HTMLString, markHTMLString } from "../escape.js";
2
2
  import { renderChild } from "./any.js";
3
+ import { chunkToString } from "./common.js";
3
4
  const slotString = Symbol.for("astro:slot-string");
4
5
  class SlotString extends HTMLString {
5
6
  constructor(content, instructions) {
@@ -12,29 +13,35 @@ slotString;
12
13
  function isSlotString(str) {
13
14
  return !!str[slotString];
14
15
  }
15
- async function* renderSlot(result, slotted, fallback) {
16
- if (slotted) {
17
- let iterator = renderChild(typeof slotted === "function" ? slotted(result) : slotted);
18
- yield* iterator;
19
- }
20
- if (fallback && !slotted) {
21
- yield* renderSlot(result, fallback);
16
+ function renderSlot(result, slotted, fallback) {
17
+ if (!slotted && fallback) {
18
+ return renderSlot(result, fallback);
22
19
  }
20
+ return {
21
+ async render(destination) {
22
+ await renderChild(destination, typeof slotted === "function" ? slotted(result) : slotted);
23
+ }
24
+ };
23
25
  }
24
26
  async function renderSlotToString(result, slotted, fallback) {
25
27
  let content = "";
26
28
  let instructions = null;
27
- let iterator = renderSlot(result, slotted, fallback);
28
- for await (const chunk of iterator) {
29
- if (typeof chunk.type === "string") {
30
- if (instructions === null) {
31
- instructions = [];
29
+ const temporaryDestination = {
30
+ write(chunk) {
31
+ if (chunk instanceof Response)
32
+ return;
33
+ if (typeof chunk === "object" && "type" in chunk && typeof chunk.type === "string") {
34
+ if (instructions === null) {
35
+ instructions = [];
36
+ }
37
+ instructions.push(chunk);
38
+ } else {
39
+ content += chunkToString(result, chunk);
32
40
  }
33
- instructions.push(chunk);
34
- } else {
35
- content += chunk;
36
41
  }
37
- }
42
+ };
43
+ const renderInstance = renderSlot(result, slotted, fallback);
44
+ await renderInstance.render(temporaryDestination);
38
45
  return markHTMLString(new SlotString(content, instructions));
39
46
  }
40
47
  async function renderSlots(result, slots = {}) {
@@ -1,4 +1,5 @@
1
1
  import type { SSRElement, SSRResult } from '../../../@types/astro';
2
2
  import type { StylesheetAsset } from '../../../core/app/types';
3
3
  export declare function renderScriptElement({ props, children }: SSRElement): string;
4
+ export declare function renderUniqueScriptElement(result: SSRResult, { props, children }: SSRElement): string;
4
5
  export declare function renderUniqueStylesheet(result: SSRResult, sheet: StylesheetAsset): string | undefined;
@@ -5,19 +5,52 @@ function renderScriptElement({ props, children }) {
5
5
  children
6
6
  });
7
7
  }
8
+ function renderUniqueScriptElement(result, { props, children }) {
9
+ if (Array.from(result.scripts).some((s) => {
10
+ if (s.props.type === props.type && s.props.src === props.src) {
11
+ return true;
12
+ }
13
+ if (!props.src && s.children === children)
14
+ return true;
15
+ }))
16
+ return "";
17
+ const key = `script-${props.type}-${props.src}-${children}`;
18
+ if (checkOrAddContentKey(result, key))
19
+ return "";
20
+ return renderScriptElement({ props, children });
21
+ }
8
22
  function renderUniqueStylesheet(result, sheet) {
9
23
  if (sheet.type === "external") {
10
24
  if (Array.from(result.styles).some((s) => s.props.href === sheet.src))
11
25
  return "";
12
- return renderElement("link", { props: { rel: "stylesheet", href: sheet.src }, children: "" });
26
+ const key = "link-external-" + sheet.src;
27
+ if (checkOrAddContentKey(result, key))
28
+ return "";
29
+ return renderElement("link", {
30
+ props: {
31
+ rel: "stylesheet",
32
+ href: sheet.src
33
+ },
34
+ children: ""
35
+ });
13
36
  }
14
37
  if (sheet.type === "inline") {
15
38
  if (Array.from(result.styles).some((s) => s.children.includes(sheet.content)))
16
39
  return "";
40
+ const key = `link-inline-` + sheet.content;
41
+ if (checkOrAddContentKey(result, key))
42
+ return "";
17
43
  return renderElement("style", { props: { type: "text/css" }, children: sheet.content });
18
44
  }
19
45
  }
46
+ function checkOrAddContentKey(result, key) {
47
+ if (result._metadata.contentKeys.has(key))
48
+ return true;
49
+ result._metadata.contentKeys.add(key);
50
+ return false;
51
+ }
20
52
  export {
21
53
  renderScriptElement,
54
+ renderUniqueScriptElement,
22
55
  renderUniqueStylesheet
23
56
  };
@@ -6,21 +6,3 @@ export declare function formatList(values: string[]): string;
6
6
  export declare function addAttribute(value: any, key: string, shouldEscape?: boolean): any;
7
7
  export declare function internalSpreadAttributes(values: Record<any, any>, shouldEscape?: boolean): any;
8
8
  export declare function renderElement(name: string, { props: _props, children }: SSRElement, shouldEscape?: boolean): string;
9
- /**
10
- * This will take an array of async iterables and start buffering them eagerly.
11
- * To avoid useless buffering, it will only start buffering the next tick, so the
12
- * first sync iterables won't be buffered.
13
- */
14
- export declare function bufferIterators<T>(iterators: AsyncIterable<T>[]): AsyncIterable<T>[];
15
- export declare class EagerAsyncIterableIterator {
16
- #private;
17
- constructor(iterable: AsyncIterable<any>);
18
- /**
19
- * Starts to eagerly fetch the inner iterator and cache the results.
20
- * Note: This might not be called after next() has been called once, e.g. the iterator is started
21
- */
22
- buffer(): Promise<void>;
23
- next(): Promise<IteratorResult<any, any>>;
24
- isStarted(): boolean;
25
- [Symbol.asyncIterator](): this;
26
- }
@@ -103,109 +103,8 @@ function renderElement(name, { props: _props, children = "" }, shouldEscape = tr
103
103
  }
104
104
  return `<${name}${internalSpreadAttributes(props, shouldEscape)}>${children}</${name}>`;
105
105
  }
106
- const iteratorQueue = [];
107
- function queueIteratorBuffers(iterators) {
108
- if (iteratorQueue.length === 0) {
109
- setTimeout(() => {
110
- iteratorQueue.forEach((its) => its.forEach((it) => !it.isStarted() && it.buffer()));
111
- iteratorQueue.length = 0;
112
- });
113
- }
114
- iteratorQueue.push(iterators);
115
- }
116
- function bufferIterators(iterators) {
117
- const eagerIterators = iterators.map((it) => new EagerAsyncIterableIterator(it));
118
- queueIteratorBuffers(eagerIterators);
119
- return eagerIterators;
120
- }
121
- class EagerAsyncIterableIterator {
122
- #iterable;
123
- #queue = new Queue();
124
- #error = void 0;
125
- #next;
126
- /**
127
- * Whether the proxy is running in buffering or pass-through mode
128
- */
129
- #isBuffering = false;
130
- #gen = void 0;
131
- #isStarted = false;
132
- constructor(iterable) {
133
- this.#iterable = iterable;
134
- }
135
- /**
136
- * Starts to eagerly fetch the inner iterator and cache the results.
137
- * Note: This might not be called after next() has been called once, e.g. the iterator is started
138
- */
139
- async buffer() {
140
- if (this.#gen) {
141
- throw new Error("Cannot not switch from non-buffer to buffer mode");
142
- }
143
- this.#isBuffering = true;
144
- this.#isStarted = true;
145
- this.#gen = this.#iterable[Symbol.asyncIterator]();
146
- let value = void 0;
147
- do {
148
- this.#next = this.#gen.next();
149
- try {
150
- value = await this.#next;
151
- this.#queue.push(value);
152
- } catch (e) {
153
- this.#error = e;
154
- }
155
- } while (value && !value.done);
156
- }
157
- async next() {
158
- if (this.#error) {
159
- throw this.#error;
160
- }
161
- if (!this.#isBuffering) {
162
- if (!this.#gen) {
163
- this.#isStarted = true;
164
- this.#gen = this.#iterable[Symbol.asyncIterator]();
165
- }
166
- return await this.#gen.next();
167
- }
168
- if (!this.#queue.isEmpty()) {
169
- return this.#queue.shift();
170
- }
171
- await this.#next;
172
- return this.#queue.shift();
173
- }
174
- isStarted() {
175
- return this.#isStarted;
176
- }
177
- [Symbol.asyncIterator]() {
178
- return this;
179
- }
180
- }
181
- class Queue {
182
- constructor() {
183
- this.head = void 0;
184
- this.tail = void 0;
185
- }
186
- push(item) {
187
- if (this.head === void 0) {
188
- this.head = { item };
189
- this.tail = this.head;
190
- } else {
191
- this.tail.next = { item };
192
- this.tail = this.tail.next;
193
- }
194
- }
195
- isEmpty() {
196
- return this.head === void 0;
197
- }
198
- shift() {
199
- var _a, _b;
200
- const val = (_a = this.head) == null ? void 0 : _a.item;
201
- this.head = (_b = this.head) == null ? void 0 : _b.next;
202
- return val;
203
- }
204
- }
205
106
  export {
206
- EagerAsyncIterableIterator,
207
107
  addAttribute,
208
- bufferIterators,
209
108
  defineScriptVars,
210
109
  formatList,
211
110
  internalSpreadAttributes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -102,7 +102,7 @@
102
102
  "vendor"
103
103
  ],
104
104
  "dependencies": {
105
- "@astrojs/compiler": "^1.6.0",
105
+ "@astrojs/compiler": "^1.6.3",
106
106
  "@astrojs/internal-helpers": "^0.1.1",
107
107
  "@astrojs/language-server": "^1.0.0",
108
108
  "@astrojs/markdown-remark": "^2.2.1",