astro 2.5.6 → 2.5.7

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.
@@ -1171,6 +1171,12 @@ export interface ContentEntryType {
1171
1171
  viteId: string;
1172
1172
  }): rollup.LoadResult | Promise<rollup.LoadResult>;
1173
1173
  contentModuleTypes?: string;
1174
+ /**
1175
+ * Handle asset propagation for rendered content to avoid bleed.
1176
+ * Ex. MDX content can import styles and scripts, so `handlePropagation` should be true.
1177
+ * @default true
1178
+ */
1179
+ handlePropagation?: boolean;
1174
1180
  }
1175
1181
  type GetContentEntryInfoReturnType = {
1176
1182
  data: Record<string, unknown>;
@@ -5,17 +5,21 @@ function getViteConfig(inlineConfig) {
5
5
  return async ({ mode, command }) => {
6
6
  const cmd = command === "serve" ? "dev" : command;
7
7
  const [
8
+ fs,
8
9
  { mergeConfig },
9
10
  { nodeLogDestination },
10
11
  { openConfig, createSettings },
11
12
  { createVite },
12
- { runHookConfigSetup, runHookConfigDone }
13
+ { runHookConfigSetup, runHookConfigDone },
14
+ { astroContentListenPlugin }
13
15
  ] = await Promise.all([
16
+ import("fs"),
14
17
  import("vite"),
15
18
  import("../core/logger/node.js"),
16
19
  import("../core/config/index.js"),
17
20
  import("../core/create-vite.js"),
18
- import("../integrations/index.js")
21
+ import("../integrations/index.js"),
22
+ import("./vite-plugin-content-listen.js")
19
23
  ]);
20
24
  const logging = {
21
25
  dest: nodeLogDestination,
@@ -29,7 +33,11 @@ function getViteConfig(inlineConfig) {
29
33
  await runHookConfigSetup({ settings, command: cmd, logging });
30
34
  const viteConfig = await createVite(
31
35
  {
32
- mode
36
+ mode,
37
+ plugins: [
38
+ // Initialize the content listener
39
+ astroContentListenPlugin({ settings, logging, fs })
40
+ ]
33
41
  },
34
42
  { settings, logging, mode }
35
43
  );
@@ -0,0 +1,18 @@
1
+ /// <reference types="node" />
2
+ import type fsMod from 'node:fs';
3
+ import type { Plugin } from 'vite';
4
+ import type { AstroSettings } from '../@types/astro';
5
+ import type { LogOptions } from '../core/logger/core.js';
6
+ /**
7
+ * Listen for Astro content directory changes and generate types.
8
+ *
9
+ * This is a separate plugin for `getViteConfig` as the `attachContentServerListeners` API
10
+ * needs to be called at different times in `astro dev` and `getViteConfig`. For `astro dev`,
11
+ * it needs to be called after the Astro server is started (packages/astro/src/core/dev/dev.ts).
12
+ * For `getViteConfig`, it needs to be called after the Vite server is started.
13
+ */
14
+ export declare function astroContentListenPlugin({ settings, logging, fs, }: {
15
+ settings: AstroSettings;
16
+ logging: LogOptions;
17
+ fs: typeof fsMod;
18
+ }): Plugin;
@@ -0,0 +1,26 @@
1
+ import { attachContentServerListeners } from "../content/server-listeners.js";
2
+ function astroContentListenPlugin({
3
+ settings,
4
+ logging,
5
+ fs
6
+ }) {
7
+ let server;
8
+ return {
9
+ name: "astro:content-listen",
10
+ apply: "serve",
11
+ configureServer(_server) {
12
+ server = _server;
13
+ },
14
+ async buildStart() {
15
+ await attachContentServerListeners({
16
+ fs,
17
+ settings,
18
+ logging,
19
+ viteServer: server
20
+ });
21
+ }
22
+ };
23
+ }
24
+ export {
25
+ astroContentListenPlugin
26
+ };
@@ -1,9 +1,10 @@
1
1
  export declare const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
2
+ export declare const CONTENT_RENDER_FLAG = "astroRenderContent";
2
3
  export declare const CONTENT_FLAG = "astroContentCollectionEntry";
3
4
  export declare const DATA_FLAG = "astroDataCollectionEntry";
4
- export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroDataCollectionEntry", "astroPropagatedAssets"];
5
5
  export declare const VIRTUAL_MODULE_ID = "astro:content";
6
6
  export declare const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
7
7
  export declare const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
8
8
  export declare const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
9
+ export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroRenderContent", "astroDataCollectionEntry", "astroPropagatedAssets"];
9
10
  export declare const CONTENT_TYPES_FILE = "types.d.ts";
@@ -1,15 +1,22 @@
1
1
  const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
2
+ const CONTENT_RENDER_FLAG = "astroRenderContent";
2
3
  const CONTENT_FLAG = "astroContentCollectionEntry";
3
4
  const DATA_FLAG = "astroDataCollectionEntry";
4
- const CONTENT_FLAGS = [CONTENT_FLAG, DATA_FLAG, PROPAGATED_ASSET_FLAG];
5
5
  const VIRTUAL_MODULE_ID = "astro:content";
6
6
  const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
7
7
  const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
8
8
  const SCRIPTS_PLACEHOLDER = "@@ASTRO-SCRIPTS@@";
9
+ const CONTENT_FLAGS = [
10
+ CONTENT_FLAG,
11
+ CONTENT_RENDER_FLAG,
12
+ DATA_FLAG,
13
+ PROPAGATED_ASSET_FLAG
14
+ ];
9
15
  const CONTENT_TYPES_FILE = "types.d.ts";
10
16
  export {
11
17
  CONTENT_FLAG,
12
18
  CONTENT_FLAGS,
19
+ CONTENT_RENDER_FLAG,
13
20
  CONTENT_TYPES_FILE,
14
21
  DATA_FLAG,
15
22
  LINKS_PLACEHOLDER,
@@ -184,7 +184,7 @@ async function render({
184
184
  id,
185
185
  renderEntryImport
186
186
  }) {
187
- var _a;
187
+ var _a, _b;
188
188
  const UnexpectedRenderError = new AstroError({
189
189
  ...AstroErrorData.UnknownContentCollectionError,
190
190
  message: `Unexpected error while rendering ${String(collection)} \u2192 ${String(id)}.`
@@ -194,53 +194,70 @@ async function render({
194
194
  const baseMod = await renderEntryImport();
195
195
  if (baseMod == null || typeof baseMod !== "object")
196
196
  throw UnexpectedRenderError;
197
- const { collectedStyles, collectedLinks, collectedScripts, getMod } = baseMod;
198
- if (typeof getMod !== "function")
199
- throw UnexpectedRenderError;
200
- const mod = await getMod();
201
- if (mod == null || typeof mod !== "object")
197
+ const { default: defaultMod } = baseMod;
198
+ if (isPropagatedAssetsModule(defaultMod)) {
199
+ const { collectedStyles, collectedLinks, collectedScripts, getMod } = defaultMod;
200
+ if (typeof getMod !== "function")
201
+ throw UnexpectedRenderError;
202
+ const propagationMod = await getMod();
203
+ if (propagationMod == null || typeof propagationMod !== "object")
204
+ throw UnexpectedRenderError;
205
+ const Content = createComponent({
206
+ factory(result, baseProps, slots) {
207
+ let styles = "", links = "", scripts = "";
208
+ if (Array.isArray(collectedStyles)) {
209
+ styles = collectedStyles.map((style) => {
210
+ return renderUniqueStylesheet(result, {
211
+ type: "inline",
212
+ content: style
213
+ });
214
+ }).join("");
215
+ }
216
+ if (Array.isArray(collectedLinks)) {
217
+ links = collectedLinks.map((link) => {
218
+ return renderUniqueStylesheet(result, {
219
+ type: "external",
220
+ src: prependForwardSlash(link)
221
+ });
222
+ }).join("");
223
+ }
224
+ if (Array.isArray(collectedScripts)) {
225
+ scripts = collectedScripts.map((script) => renderScriptElement(script)).join("");
226
+ }
227
+ let props = baseProps;
228
+ if (id.endsWith("mdx")) {
229
+ props = {
230
+ components: propagationMod.components ?? {},
231
+ ...baseProps
232
+ };
233
+ }
234
+ return createHeadAndContent(
235
+ unescapeHTML(styles + links + scripts),
236
+ renderTemplate`${renderComponent(
237
+ result,
238
+ "Content",
239
+ propagationMod.Content,
240
+ props,
241
+ slots
242
+ )}`
243
+ );
244
+ },
245
+ propagation: "self"
246
+ });
247
+ return {
248
+ Content,
249
+ headings: ((_a = propagationMod.getHeadings) == null ? void 0 : _a.call(propagationMod)) ?? [],
250
+ remarkPluginFrontmatter: propagationMod.frontmatter ?? {}
251
+ };
252
+ } else if (baseMod.Content && typeof baseMod.Content === "function") {
253
+ return {
254
+ Content: baseMod.Content,
255
+ headings: ((_b = baseMod.getHeadings) == null ? void 0 : _b.call(baseMod)) ?? [],
256
+ remarkPluginFrontmatter: baseMod.frontmatter ?? {}
257
+ };
258
+ } else {
202
259
  throw UnexpectedRenderError;
203
- const Content = createComponent({
204
- factory(result, baseProps, slots) {
205
- let styles = "", links = "", scripts = "";
206
- if (Array.isArray(collectedStyles)) {
207
- styles = collectedStyles.map((style) => {
208
- return renderUniqueStylesheet(result, {
209
- type: "inline",
210
- content: style
211
- });
212
- }).join("");
213
- }
214
- if (Array.isArray(collectedLinks)) {
215
- links = collectedLinks.map((link) => {
216
- return renderUniqueStylesheet(result, {
217
- type: "external",
218
- src: prependForwardSlash(link)
219
- });
220
- }).join("");
221
- }
222
- if (Array.isArray(collectedScripts)) {
223
- scripts = collectedScripts.map((script) => renderScriptElement(script)).join("");
224
- }
225
- let props = baseProps;
226
- if (id.endsWith(".mdx")) {
227
- props = {
228
- components: mod.components ?? {},
229
- ...baseProps
230
- };
231
- }
232
- return createHeadAndContent(
233
- unescapeHTML(styles + links + scripts),
234
- renderTemplate`${renderComponent(result, "Content", mod.Content, props, slots)}`
235
- );
236
- },
237
- propagation: "self"
238
- });
239
- return {
240
- Content,
241
- headings: ((_a = mod.getHeadings) == null ? void 0 : _a.call(mod)) ?? [],
242
- remarkPluginFrontmatter: mod.frontmatter ?? {}
243
- };
260
+ }
244
261
  }
245
262
  function createReference({ lookupMap }) {
246
263
  return function reference(collection) {
@@ -271,6 +288,9 @@ function createReference({ lookupMap }) {
271
288
  });
272
289
  };
273
290
  }
291
+ function isPropagatedAssetsModule(module) {
292
+ return typeof module === "object" && module != null && "__astroPropagation" in module;
293
+ }
274
294
  export {
275
295
  createCollectionToGlobResultMap,
276
296
  createGetCollection,
@@ -1,4 +1,5 @@
1
- import { pathToFileURL } from "url";
1
+ import { extname } from "node:path";
2
+ import { pathToFileURL } from "node:url";
2
3
  import { moduleIsTopLevelPage, walkParentInfos } from "../core/build/graph.js";
3
4
  import { getPageDataByViteID } from "../core/build/internal.js";
4
5
  import { createViteLoader } from "../core/module-loader/vite.js";
@@ -6,15 +7,13 @@ import { joinPaths, prependForwardSlash } from "../core/path.js";
6
7
  import { getStylesForURL } from "../core/render/dev/css.js";
7
8
  import { getScriptsForURL } from "../core/render/dev/scripts.js";
8
9
  import {
10
+ CONTENT_RENDER_FLAG,
9
11
  LINKS_PLACEHOLDER,
10
12
  PROPAGATED_ASSET_FLAG,
11
13
  SCRIPTS_PLACEHOLDER,
12
14
  STYLES_PLACEHOLDER
13
15
  } from "./consts.js";
14
- function isPropagatedAsset(viteId) {
15
- const flags = new URLSearchParams(viteId.split("?")[1]);
16
- return flags.has(PROPAGATED_ASSET_FLAG);
17
- }
16
+ import { hasContentFlag } from "./utils.js";
18
17
  function astroContentAssetPropagationPlugin({
19
18
  mode,
20
19
  settings
@@ -22,6 +21,21 @@ function astroContentAssetPropagationPlugin({
22
21
  let devModuleLoader;
23
22
  return {
24
23
  name: "astro:content-asset-propagation",
24
+ enforce: "pre",
25
+ async resolveId(id, importer, opts) {
26
+ if (hasContentFlag(id, CONTENT_RENDER_FLAG)) {
27
+ const base = id.split("?")[0];
28
+ for (const { extensions, handlePropagation = true } of settings.contentEntryTypes) {
29
+ if (handlePropagation && extensions.includes(extname(base))) {
30
+ return this.resolve(`${base}?${PROPAGATED_ASSET_FLAG}`, importer, {
31
+ skipSelf: true,
32
+ ...opts
33
+ });
34
+ }
35
+ }
36
+ return this.resolve(base, importer, { skipSelf: true, ...opts });
37
+ }
38
+ },
25
39
  configureServer(server) {
26
40
  if (mode === "dev") {
27
41
  devModuleLoader = createViteLoader(server);
@@ -29,7 +43,7 @@ function astroContentAssetPropagationPlugin({
29
43
  },
30
44
  async transform(_, id, options) {
31
45
  var _a;
32
- if (isPropagatedAsset(id)) {
46
+ if (hasContentFlag(id, PROPAGATED_ASSET_FLAG)) {
33
47
  const basePath = id.split("?")[0];
34
48
  let stringifiedLinks, stringifiedStyles, stringifiedScripts;
35
49
  if ((options == null ? void 0 : options.ssr) && devModuleLoader) {
@@ -55,12 +69,14 @@ function astroContentAssetPropagationPlugin({
55
69
  stringifiedScripts = JSON.stringify(SCRIPTS_PLACEHOLDER);
56
70
  }
57
71
  const code = `
58
- export async function getMod() {
72
+ async function getMod() {
59
73
  return import(${JSON.stringify(basePath)});
60
74
  }
61
- export const collectedLinks = ${stringifiedLinks};
62
- export const collectedStyles = ${stringifiedStyles};
63
- export const collectedScripts = ${stringifiedScripts};
75
+ const collectedLinks = ${stringifiedLinks};
76
+ const collectedStyles = ${stringifiedStyles};
77
+ const collectedScripts = ${stringifiedScripts};
78
+ const defaultMod = { __astroPropagation: true, getMod, collectedLinks, collectedStyles, collectedScripts };
79
+ export default defaultMod;
64
80
  `;
65
81
  return { code, map: { mappings: "" } };
66
82
  }
@@ -29,15 +29,20 @@ function astroContentVirtualModPlugin({
29
29
  "@@COLLECTION_NAME_BY_REFERENCE_KEY@@",
30
30
  new URL("reference-map.json", contentPaths.cacheDir).pathname
31
31
  ).replace("@@CONTENT_DIR@@", relContentDir).replace(
32
- "@@CONTENT_ENTRY_GLOB_PATH@@",
33
- // [!_] = ignore files starting with "_"
34
- `${relContentDir}**/[!_]*${getExtGlob(contentEntryExts)}`
35
- ).replace("@@DATA_ENTRY_GLOB_PATH@@", `${relContentDir}**/[!_]*${getExtGlob(dataEntryExts)}`).replace(
36
- "@@RENDER_ENTRY_GLOB_PATH@@",
37
- `${relContentDir}**/*${getExtGlob(
38
- /** Note: data collections excluded */
39
- contentEntryExts
40
- )}`
32
+ "'@@CONTENT_ENTRY_GLOB_PATH@@'",
33
+ JSON.stringify(globWithUnderscoresIgnored(relContentDir, contentEntryExts))
34
+ ).replace(
35
+ "'@@DATA_ENTRY_GLOB_PATH@@'",
36
+ JSON.stringify(globWithUnderscoresIgnored(relContentDir, dataEntryExts))
37
+ ).replace(
38
+ "'@@RENDER_ENTRY_GLOB_PATH@@'",
39
+ JSON.stringify(
40
+ globWithUnderscoresIgnored(
41
+ relContentDir,
42
+ /** Note: data collections excluded */
43
+ contentEntryExts
44
+ )
45
+ )
41
46
  );
42
47
  const astroContentVirtualModuleId = "\0" + VIRTUAL_MODULE_ID;
43
48
  return {
@@ -150,6 +155,10 @@ const UnexpectedLookupMapError = new AstroError({
150
155
  ...AstroErrorData.UnknownContentCollectionError,
151
156
  message: `Unexpected error while parsing content entry IDs and slugs.`
152
157
  });
158
+ function globWithUnderscoresIgnored(relContentDir, exts) {
159
+ const extGlob = getExtGlob(exts);
160
+ return [`${relContentDir}/**/*${extGlob}`, `!**/_*/**${extGlob}`, `!**/_*${extGlob}`];
161
+ }
153
162
  export {
154
163
  astroContentVirtualModPlugin,
155
164
  getStringifiedLookupMap
@@ -7,11 +7,12 @@ const clientAddressSymbol = Symbol.for("astro.clientAddress");
7
7
  function createRequestFromNodeRequest(req, body) {
8
8
  var _a;
9
9
  const protocol = req.socket instanceof TLSSocket || req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
10
- let url = `${protocol}://${req.headers.host}${req.url}`;
11
- let rawHeaders = req.headers;
10
+ const hostname = req.headers.host || req.headers[":authority"];
11
+ const url = `${protocol}://${hostname}${req.url}`;
12
+ const rawHeaders = req.headers;
12
13
  const entries = Object.entries(rawHeaders);
13
14
  const method = req.method || "GET";
14
- let request = new Request(url, {
15
+ const request = new Request(url, {
15
16
  method,
16
17
  headers: new Headers(entries),
17
18
  body: ["HEAD", "GET"].includes(method) ? null : body
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.5.6";
1
+ const ASTRO_VERSION = "2.5.7";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -53,7 +53,7 @@ async function dev(settings, options) {
53
53
  isRestart: options.isRestart
54
54
  })
55
55
  );
56
- const currentVersion = "2.5.6";
56
+ const currentVersion = "2.5.7";
57
57
  if (currentVersion.includes("-")) {
58
58
  warn(options.logging, null, msg.prerelease({ currentVersion }));
59
59
  }
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.5.6";
50
+ const version = "2.5.7";
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.5.6"}`
236
+ `v${"2.5.7"}`
237
237
  )} ${headline}`
238
238
  );
239
239
  }
@@ -1,15 +1,13 @@
1
1
  import npath from "path";
2
- import { PROPAGATED_ASSET_FLAG } from "../../../content/consts.js";
3
2
  import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
4
3
  import { unwrapId } from "../../util.js";
5
4
  import { isCSSRequest } from "./util.js";
6
- const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
5
+ const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ".mdoc", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
7
6
  const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
7
+ const ASTRO_PROPAGATED_ASSET_REGEX = /\?astroPropagatedAssets/;
8
8
  async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ new Set()) {
9
9
  const id = unwrapId(_id);
10
10
  const importedModules = /* @__PURE__ */ new Set();
11
- if (new URL(id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG))
12
- return;
13
11
  const moduleEntriesForId = isRootFile ? (
14
12
  // "getModulesByFile" pulls from a delayed module cache (fun implementation detail),
15
13
  // So we can get up-to-date info on initial server load.
@@ -28,19 +26,18 @@ async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ ne
28
26
  scanned.add(id);
29
27
  const entryIsStyle = isCSSRequest(id);
30
28
  for (const importedModule of entry.importedModules) {
29
+ let isPropagationStoppingPoint = false;
31
30
  if (importedModule.id) {
32
31
  const importedModulePathname = importedModule.id.replace(STRIP_QUERY_PARAMS_REGEX, "");
33
32
  if (entryIsStyle && !isCSSRequest(importedModulePathname)) {
34
33
  continue;
35
34
  }
36
- if (fileExtensionsToSSR.has(
37
- npath.extname(
38
- // Use `id` instead of `pathname` to preserve query params.
39
- // Should not SSR a module with an unexpected query param,
40
- // like "?astroPropagatedAssets"
41
- importedModule.id
42
- )
43
- )) {
35
+ const isFileTypeNeedingSSR = fileExtensionsToSSR.has(
36
+ npath.extname(importedModulePathname)
37
+ );
38
+ isPropagationStoppingPoint = ASTRO_PROPAGATED_ASSET_REGEX.test(importedModule.id);
39
+ if (isFileTypeNeedingSSR && // Should not SSR a module with ?astroPropagatedAssets
40
+ !isPropagationStoppingPoint) {
44
41
  const mod = loader.getModuleById(importedModule.id);
45
42
  if (!(mod == null ? void 0 : mod.ssrModule)) {
46
43
  try {
@@ -50,7 +47,9 @@ async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ ne
50
47
  }
51
48
  }
52
49
  }
53
- importedModules.add(importedModule);
50
+ if (!isPropagationStoppingPoint) {
51
+ importedModules.add(importedModule);
52
+ }
54
53
  }
55
54
  }
56
55
  }
@@ -5,6 +5,7 @@ import {
5
5
  renderAstroTemplateResult
6
6
  } from "./astro/index.js";
7
7
  import { SlotString } from "./slot.js";
8
+ import { bufferIterators } from "./util.js";
8
9
  async function* renderChild(child) {
9
10
  child = await child;
10
11
  if (child instanceof SlotString) {
@@ -15,8 +16,9 @@ async function* renderChild(child) {
15
16
  } else if (isHTMLString(child)) {
16
17
  yield child;
17
18
  } else if (Array.isArray(child)) {
18
- for (const value of child) {
19
- yield markHTMLString(await renderChild(value));
19
+ const bufferedIterators = bufferIterators(child.map((c) => renderChild(c)));
20
+ for (const value of bufferedIterators) {
21
+ yield markHTMLString(await value);
20
22
  }
21
23
  } else if (typeof child === "function") {
22
24
  yield* renderChild(child());
@@ -7,7 +7,7 @@ export declare class RenderTemplateResult {
7
7
  private expressions;
8
8
  private error;
9
9
  constructor(htmlParts: TemplateStringsArray, expressions: unknown[]);
10
- [Symbol.asyncIterator](): AsyncGenerator<any, void, unknown>;
10
+ [Symbol.asyncIterator](): AsyncGenerator<any, void, undefined>;
11
11
  }
12
12
  export declare function isRenderTemplateResult(obj: unknown): obj is RenderTemplateResult;
13
13
  export declare function renderAstroTemplateResult(component: RenderTemplateResult): AsyncIterable<string | HTMLBytes | RenderInstruction>;
@@ -2,7 +2,7 @@ var _a;
2
2
  import { markHTMLString } from "../../escape.js";
3
3
  import { isPromise } from "../../util.js";
4
4
  import { renderChild } from "../any.js";
5
- import { EagerAsyncIterableIterator } from "../util.js";
5
+ import { bufferIterators } from "../util.js";
6
6
  const renderTemplateResultSym = Symbol.for("astro.renderTemplateResult");
7
7
  class RenderTemplateResult {
8
8
  constructor(htmlParts, expressions) {
@@ -23,18 +23,14 @@ class RenderTemplateResult {
23
23
  }
24
24
  async *[(_a = renderTemplateResultSym, Symbol.asyncIterator)]() {
25
25
  const { htmlParts, expressions } = this;
26
- let iterables = [];
27
- for (let i = 0; i < htmlParts.length; i++) {
28
- iterables.push(new EagerAsyncIterableIterator(renderChild(expressions[i])));
29
- }
30
- setTimeout(() => {
31
- iterables.forEach((it) => !it.isStarted() && it.buffer());
32
- }, 0);
26
+ let iterables = bufferIterators(expressions.map((e) => renderChild(e)));
33
27
  for (let i = 0; i < htmlParts.length; i++) {
34
28
  const html = htmlParts[i];
35
29
  const iterable = iterables[i];
36
30
  yield markHTMLString(html);
37
- yield* iterable;
31
+ if (iterable) {
32
+ yield* iterable;
33
+ }
38
34
  }
39
35
  }
40
36
  }
@@ -6,6 +6,12 @@ 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>[];
9
15
  export declare class EagerAsyncIterableIterator {
10
16
  #private;
11
17
  constructor(iterable: AsyncIterable<any>);
@@ -96,6 +96,13 @@ function renderElement(name, { props: _props, children = "" }, shouldEscape = tr
96
96
  }
97
97
  return `<${name}${internalSpreadAttributes(props, shouldEscape)}>${children}</${name}>`;
98
98
  }
99
+ function bufferIterators(iterators) {
100
+ const eagerIterators = iterators.map((it) => new EagerAsyncIterableIterator(it));
101
+ setTimeout(() => {
102
+ eagerIterators.forEach((it) => !it.isStarted() && it.buffer());
103
+ }, 0);
104
+ return eagerIterators;
105
+ }
99
106
  class EagerAsyncIterableIterator {
100
107
  #iterable;
101
108
  #queue = new Queue();
@@ -183,6 +190,7 @@ class Queue {
183
190
  export {
184
191
  EagerAsyncIterableIterator,
185
192
  addAttribute,
193
+ bufferIterators,
186
194
  defineScriptVars,
187
195
  formatList,
188
196
  internalSpreadAttributes,
@@ -1,6 +1,6 @@
1
1
  import { getTopLevelPages, walkParentInfos } from "../core/build/graph.js";
2
2
  import { getAstroMetadata } from "../vite-plugin-astro/index.js";
3
- const injectExp = /^\/\/\s*astro-head-inject/;
3
+ const injectExp = /(^\/\/|\/\/!)\s*astro-head-inject/;
4
4
  function configHeadVitePlugin({
5
5
  settings
6
6
  }) {
@@ -10,7 +10,9 @@ const markdownContentEntryType = {
10
10
  slug: parsed.data.slug,
11
11
  rawData: parsed.matter
12
12
  };
13
- }
13
+ },
14
+ // We need to handle propagation for Markdown because they support layouts which will bring in styles.
15
+ handlePropagation: true
14
16
  };
15
17
  const mdxContentEntryType = {
16
18
  extensions: [".mdx"],
@@ -23,6 +25,9 @@ const mdxContentEntryType = {
23
25
  rawData: parsed.matter
24
26
  };
25
27
  },
28
+ // MDX can import scripts and styles,
29
+ // so wrap all MDX files with script / style propagation checks
30
+ handlePropagation: true,
26
31
  contentModuleTypes: `declare module 'astro:content' {
27
32
  interface Render {
28
33
  '.mdx': Promise<{
@@ -7,7 +7,7 @@ import {
7
7
  } from "../core/path.js";
8
8
  import { viteID } from "../core/util.js";
9
9
  function escapeViteEnvReferences(code) {
10
- return code.replace(/import\.meta\.env/g, "import\\u002Emeta.env");
10
+ return code.replace(/import\.meta\.env/g, "import\\u002Emeta.env").replace(/process\.env/g, "process\\u002Eenv");
11
11
  }
12
12
  function getFileInfo(id, config) {
13
13
  const sitePathname = appendForwardSlash(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.5.6",
3
+ "version": "2.5.7",
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",
@@ -46,7 +46,7 @@ function createGlobLookup(glob) {
46
46
  }
47
47
 
48
48
  const renderEntryGlob = import.meta.glob('@@RENDER_ENTRY_GLOB_PATH@@', {
49
- query: { astroPropagatedAssets: true },
49
+ query: { astroRenderContent: true },
50
50
  });
51
51
  const collectionToRenderEntryMap = createCollectionToGlobResultMap({
52
52
  globResult: renderEntryGlob,