astro 3.2.2 → 3.2.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.
package/astro.js CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  // ISOMORPHIC FILE: NO TOP-LEVEL IMPORT/REQUIRE() ALLOWED
5
5
  // This file has to run as both ESM and CJS on older Node.js versions
6
- // Needed for Stackblitz: https://github.com/stackblitz/webcontainer-core/issues/281
7
6
 
8
7
  const CI_INSTRUCTIONS = {
9
8
  NETLIFY: 'https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript',
@@ -16,15 +15,11 @@ const CI_INSTRUCTIONS = {
16
15
  const engines = '>=18.14.1';
17
16
  const skipSemverCheckIfAbove = 19;
18
17
 
19
- // HACK (2023-08-18) Stackblitz does not support Node 18 yet, so we'll fake Node 16 support for some time until it's supported
20
- // TODO: Remove when Node 18 is supported on Stackblitz
21
- const isStackblitz = process.env.SHELL === '/bin/jsh' && process.versions.webcontainer != null;
22
-
23
18
  /** `astro *` */
24
19
  async function main() {
25
20
  const version = process.versions.node;
26
21
  // Fast-path for higher Node.js versions
27
- if (!isStackblitz && (parseInt(version) || 0) <= skipSemverCheckIfAbove) {
22
+ if ((parseInt(version) || 0) <= skipSemverCheckIfAbove) {
28
23
  try {
29
24
  const semver = await import('semver');
30
25
  if (!semver.satisfies(version, engines)) {
@@ -37,6 +32,13 @@ async function main() {
37
32
  }
38
33
  }
39
34
 
35
+ // windows drive letters can sometimes be lowercase, which vite cannot process
36
+ if (process.platform === 'win32') {
37
+ const cwd = process.cwd();
38
+ const correctedCwd = cwd.slice(0, 1).toUpperCase() + cwd.slice(1);
39
+ if (correctedCwd !== cwd) process.chdir(correctedCwd);
40
+ }
41
+
40
42
  return import('./dist/cli/index.js')
41
43
  .then(({ cli }) => cli(process.argv))
42
44
  .catch((error) => {
@@ -559,7 +559,7 @@ export interface AstroUserConfig {
559
559
  * @see output
560
560
  * @description
561
561
  *
562
- * Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters for [Netlify](https://docs.astro.build/en/guides/deploy/netlify/#adapter-for-ssredge), [Vercel](https://docs.astro.build/en/guides/deploy/vercel/#adapter-for-ssr), and more to engage Astro SSR.
562
+ * Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters for [Netlify](https://docs.astro.build/en/guides/deploy/netlify/#adapter-for-ssr), [Vercel](https://docs.astro.build/en/guides/deploy/vercel/#adapter-for-ssr), and more to engage Astro SSR.
563
563
  *
564
564
  * [See our Server-side Rendering guide](https://docs.astro.build/en/guides/server-side-rendering/) for more on SSR, and [our deployment guides](https://docs.astro.build/en/guides/deploy/) for a complete list of hosts.
565
565
  *
@@ -1075,10 +1075,10 @@ export interface AstroUserConfig {
1075
1075
  * Pass [rehype plugins](https://github.com/remarkjs/remark-rehype) to customize how your Markdown's output HTML is processed. You can import and apply the plugin function (recommended), or pass the plugin name as a string.
1076
1076
  *
1077
1077
  * ```js
1078
- * import rehypeMinifyHtml from 'rehype-minify';
1078
+ * import { rehypeAccessibleEmojis } from 'rehype-accessible-emojis';
1079
1079
  * {
1080
1080
  * markdown: {
1081
- * rehypePlugins: [rehypeMinifyHtml]
1081
+ * rehypePlugins: [rehypeAccessibleEmojis]
1082
1082
  * }
1083
1083
  * }
1084
1084
  * ```
@@ -65,7 +65,7 @@ async function getImage(options, imageConfig) {
65
65
  rawOptions: resolvedOptions,
66
66
  options: validatedOptions,
67
67
  src: imageURL,
68
- attributes: service.getHTMLAttributes !== void 0 ? service.getHTMLAttributes(validatedOptions, imageConfig) : {}
68
+ attributes: service.getHTMLAttributes !== void 0 ? await service.getHTMLAttributes(validatedOptions, imageConfig) : {}
69
69
  };
70
70
  }
71
71
  export {
@@ -37,7 +37,7 @@ const ASTRO_CONFIG_STUB = `import { defineConfig } from 'astro/config';
37
37
 
38
38
  export default defineConfig({});`;
39
39
  const TAILWIND_CONFIG_STUB = `/** @type {import('tailwindcss').Config} */
40
- module.exports = {
40
+ export default {
41
41
  content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
42
42
  theme: {
43
43
  extend: {},
@@ -58,8 +58,7 @@ const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
58
58
  netlify: "@astrojs/netlify/functions",
59
59
  vercel: "@astrojs/vercel/serverless",
60
60
  cloudflare: "@astrojs/cloudflare",
61
- node: "@astrojs/node",
62
- deno: "@astrojs/deno"
61
+ node: "@astrojs/node"
63
62
  };
64
63
  async function getRegistry() {
65
64
  const packageManager = (await preferredPM(process.cwd()))?.name || "npm";
@@ -134,7 +133,7 @@ async function add(names, { flags }) {
134
133
  "./tailwind.config.mjs",
135
134
  "./tailwind.config.js"
136
135
  ],
137
- defaultConfigFile: "./tailwind.config.cjs",
136
+ defaultConfigFile: "./tailwind.config.mjs",
138
137
  defaultConfigContent: TAILWIND_CONFIG_STUB
139
138
  });
140
139
  }
@@ -27,11 +27,20 @@ async function printInfo({ flags }) {
27
27
  }
28
28
  await copyToClipboard(output.trim());
29
29
  }
30
- const SUPPORTED_SYSTEM = /* @__PURE__ */ new Set(["darwin", "win32"]);
31
30
  async function copyToClipboard(text) {
32
31
  const system = platform();
33
- if (!SUPPORTED_SYSTEM.has(system))
34
- return;
32
+ let command = "";
33
+ if (system === "darwin") {
34
+ command = "pbcopy";
35
+ } else if (system === "win32") {
36
+ command = "clip";
37
+ } else {
38
+ const output = execSync("which xclip", { encoding: "utf8" });
39
+ if (output[0] !== "/") {
40
+ return;
41
+ }
42
+ command = "xclip -sel clipboard -l 1";
43
+ }
35
44
  console.log();
36
45
  const { shouldCopy } = await prompts({
37
46
  type: "confirm",
@@ -41,11 +50,10 @@ async function copyToClipboard(text) {
41
50
  });
42
51
  if (!shouldCopy)
43
52
  return;
44
- const command = system === "darwin" ? "pbcopy" : "clip";
45
53
  try {
46
- execSync(`echo ${JSON.stringify(text.trim())} | ${command}`, {
47
- encoding: "utf8",
48
- stdio: "ignore"
54
+ execSync(command, {
55
+ input: text.trim(),
56
+ encoding: "utf8"
49
57
  });
50
58
  } catch (e) {
51
59
  console.error(
@@ -103,9 +103,15 @@ export const _internal = {
103
103
  }
104
104
  for (const modUrl of viteServer.moduleGraph.urlToModuleMap.keys()) {
105
105
  if (hasContentFlag(modUrl, CONTENT_FLAG) || hasContentFlag(modUrl, DATA_FLAG) || Boolean(getContentRendererByViteId(modUrl, settings))) {
106
- const mod = await viteServer.moduleGraph.getModuleByUrl(modUrl);
107
- if (mod) {
108
- viteServer.moduleGraph.invalidateModule(mod);
106
+ try {
107
+ const mod = await viteServer.moduleGraph.getModuleByUrl(modUrl);
108
+ if (mod) {
109
+ viteServer.moduleGraph.invalidateModule(mod);
110
+ }
111
+ } catch (e) {
112
+ if (e.code === "ERR_CLOSED_SERVER")
113
+ break;
114
+ throw e;
109
115
  }
110
116
  }
111
117
  }
@@ -3,6 +3,7 @@ import type { AstroSettings } from '../../@types/astro.js';
3
3
  export declare function shortHashedName(id: string, ctx: {
4
4
  getModuleInfo: GetModuleInfo;
5
5
  }): string;
6
+ export declare function createNameHash(baseId: string | undefined, hashIds: string[]): string;
6
7
  export declare function createSlugger(settings: AstroSettings): (id: string, ctx: {
7
8
  getModuleInfo: GetModuleInfo;
8
9
  }) => string;
@@ -2,16 +2,22 @@ import crypto from "node:crypto";
2
2
  import npath from "node:path";
3
3
  import { viteID } from "../util.js";
4
4
  import { getTopLevelPages } from "./graph.js";
5
+ const confusingBaseNames = ["404", "500"];
5
6
  function shortHashedName(id, ctx) {
6
7
  const parents = Array.from(getTopLevelPages(id, ctx));
7
- const firstParentId = parents[0]?.[0].id;
8
- const firstParentName = firstParentId ? npath.parse(firstParentId).name : "index";
8
+ return createNameHash(
9
+ getFirstParentId(parents),
10
+ parents.map(([page]) => page.id)
11
+ );
12
+ }
13
+ function createNameHash(baseId, hashIds) {
14
+ const baseName = baseId ? prettifyBaseName(npath.parse(baseId).name) : "index";
9
15
  const hash = crypto.createHash("sha256");
10
- for (const [page] of parents) {
11
- hash.update(page.id, "utf-8");
16
+ for (const id of hashIds) {
17
+ hash.update(id, "utf-8");
12
18
  }
13
19
  const h = hash.digest("hex").slice(0, 8);
14
- const proposedName = firstParentName + "." + h;
20
+ const proposedName = baseName + "." + h;
15
21
  return proposedName;
16
22
  }
17
23
  function createSlugger(settings) {
@@ -22,7 +28,7 @@ function createSlugger(settings) {
22
28
  return function(id, ctx) {
23
29
  const parents = Array.from(getTopLevelPages(id, ctx));
24
30
  const allParentsKey = parents.map(([page]) => page.id).sort().join("-");
25
- const firstParentId = parents[0]?.[0].id || indexPage;
31
+ const firstParentId = getFirstParentId(parents) || indexPage;
26
32
  let dir = firstParentId;
27
33
  let key = "";
28
34
  let i = 0;
@@ -30,7 +36,7 @@ function createSlugger(settings) {
30
36
  if (dir === pagesDir) {
31
37
  break;
32
38
  }
33
- const name2 = npath.parse(npath.basename(dir)).name;
39
+ const name2 = prettifyBaseName(npath.parse(npath.basename(dir)).name);
34
40
  key = key.length ? name2 + sep + key : name2;
35
41
  dir = npath.dirname(dir);
36
42
  i++;
@@ -54,7 +60,23 @@ function createSlugger(settings) {
54
60
  return name;
55
61
  };
56
62
  }
63
+ function getFirstParentId(parents) {
64
+ for (const parent of parents) {
65
+ const id = parent[0].id;
66
+ const baseName = npath.parse(id).name;
67
+ if (!confusingBaseNames.includes(baseName)) {
68
+ return id;
69
+ }
70
+ }
71
+ return parents[0]?.[0].id;
72
+ }
73
+ const charsToReplaceRe = /[.\[\]]/g;
74
+ const underscoresRe = /_+/g;
75
+ function prettifyBaseName(str) {
76
+ return str.replace(charsToReplaceRe, "_").replace(underscoresRe, "_");
77
+ }
57
78
  export {
79
+ createNameHash,
58
80
  createSlugger,
59
81
  shortHashedName
60
82
  };
@@ -1,5 +1,3 @@
1
- import * as crypto from "node:crypto";
2
- import * as npath from "node:path";
3
1
  import {} from "vite";
4
2
  import { isBuildableCSSRequest } from "../../../vite-plugin-astro-server/util.js";
5
3
  import { PROPAGATED_ASSET_FLAG } from "../../../content/consts.js";
@@ -52,7 +50,7 @@ function rollupPluginAstroBuildCSS(options) {
52
50
  getModuleInfo: meta.getModuleInfo
53
51
  })) {
54
52
  if (new URL(pageInfo.id, "file://").searchParams.has(PROPAGATED_ASSET_FLAG)) {
55
- const chunkId2 = createNameHash(id, [id]);
53
+ const chunkId2 = assetName.createNameHash(id, [id]);
56
54
  internals.cssModuleToChunkIdMap.set(id, chunkId2);
57
55
  return chunkId2;
58
56
  }
@@ -148,17 +146,21 @@ function rollupPluginAstroBuildCSS(options) {
148
146
  async generateBundle(_outputOptions, bundle) {
149
147
  const inlineConfig = settings.config.build.inlineStylesheets;
150
148
  const { assetsInlineLimit = 4096 } = settings.config.vite?.build ?? {};
151
- Object.entries(bundle).forEach(([_, stylesheet]) => {
149
+ Object.entries(bundle).forEach(([id, stylesheet]) => {
152
150
  if (stylesheet.type !== "asset" || stylesheet.name?.endsWith(".css") !== true || typeof stylesheet.source !== "string")
153
151
  return;
154
152
  const assetSize = new TextEncoder().encode(stylesheet.source).byteLength;
155
153
  const toBeInlined = inlineConfig === "always" ? true : inlineConfig === "never" ? false : assetSize <= assetsInlineLimit;
156
154
  const sheet = toBeInlined ? { type: "inline", content: stylesheet.source } : { type: "external", src: stylesheet.fileName };
157
155
  const pages = Array.from(eachPageData(internals));
156
+ let sheetAddedToPage = false;
158
157
  pages.forEach((pageData) => {
159
158
  const orderingInfo = pagesToCss[pageData.moduleSpecifier]?.[stylesheet.fileName];
160
- if (orderingInfo !== void 0)
161
- return pageData.styles.push({ ...orderingInfo, sheet });
159
+ if (orderingInfo !== void 0) {
160
+ pageData.styles.push({ ...orderingInfo, sheet });
161
+ sheetAddedToPage = true;
162
+ return;
163
+ }
162
164
  const propagatedPaths = pagesToPropagatedCss[pageData.moduleSpecifier];
163
165
  if (propagatedPaths === void 0)
164
166
  return;
@@ -169,23 +171,22 @@ function rollupPluginAstroBuildCSS(options) {
169
171
  return;
170
172
  const propagatedStyles = pageData.propagatedStyles.get(pageInfoId) ?? pageData.propagatedStyles.set(pageInfoId, /* @__PURE__ */ new Set()).get(pageInfoId);
171
173
  propagatedStyles.add(sheet);
174
+ sheetAddedToPage = true;
172
175
  });
173
176
  });
177
+ if (toBeInlined && sheetAddedToPage) {
178
+ delete bundle[id];
179
+ for (const chunk of Object.values(bundle)) {
180
+ if (chunk.type === "chunk") {
181
+ chunk.viteMetadata?.importedCss?.delete(id);
182
+ }
183
+ }
184
+ }
174
185
  });
175
186
  }
176
187
  };
177
188
  return [cssBuildPlugin, singleCssPlugin, inlineStylesheetsPlugin];
178
189
  }
179
- function createNameHash(baseId, hashIds) {
180
- const baseName = baseId ? npath.parse(baseId).name : "index";
181
- const hash = crypto.createHash("sha256");
182
- for (const id of hashIds) {
183
- hash.update(id, "utf-8");
184
- }
185
- const h = hash.digest("hex").slice(0, 8);
186
- const proposedName = baseName + "." + h;
187
- return proposedName;
188
- }
189
190
  function* getParentClientOnlys(id, ctx, internals) {
190
191
  for (const [info] of walkParentInfos(id, ctx)) {
191
192
  yield* getPageDatasByClientOnlyID(internals, info.id);
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "3.2.2";
1
+ const ASTRO_VERSION = "3.2.4";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -20,7 +20,7 @@ async function dev(inlineConfig) {
20
20
  base: restart.container.settings.config.base
21
21
  })
22
22
  );
23
- const currentVersion = "3.2.2";
23
+ const currentVersion = "3.2.4";
24
24
  if (currentVersion.includes("-")) {
25
25
  logger.warn(null, msg.prerelease({ currentVersion }));
26
26
  }
@@ -15,27 +15,8 @@ type CreateAPIContext = {
15
15
  */
16
16
  export declare function createAPIContext({ request, params, site, props, adapterName, }: CreateAPIContext): APIContext;
17
17
  type ResponseParameters = ConstructorParameters<typeof Response>;
18
- export declare let ResponseWithEncoding: ReturnType<typeof initResponseWithEncoding>;
19
- declare let initResponseWithEncoding: () => {
20
- new (body: ResponseParameters[0], init: ResponseParameters[1], encoding?: BufferEncoding): {
21
- readonly headers: Headers;
22
- readonly ok: boolean;
23
- readonly redirected: boolean;
24
- readonly status: number;
25
- readonly statusText: string;
26
- readonly type: ResponseType;
27
- readonly url: string;
28
- clone(): Response;
29
- readonly body: ReadableStream<Uint8Array> | null;
30
- readonly bodyUsed: boolean;
31
- arrayBuffer(): Promise<ArrayBuffer>;
32
- blob(): Promise<Blob>;
33
- formData(): Promise<FormData>;
34
- json(): Promise<any>;
35
- text(): Promise<string>;
36
- };
37
- error(): Response;
38
- redirect(url: string | URL, status?: number | undefined): Response;
39
- };
18
+ export declare class ResponseWithEncoding extends Response {
19
+ constructor(body: ResponseParameters[0], init: ResponseParameters[1], encoding?: BufferEncoding);
20
+ }
40
21
  export declare function callEndpoint<MiddlewareResult = Response | EndpointOutput>(mod: EndpointHandler, env: Environment, ctx: RenderContext, onRequest?: MiddlewareHandler<MiddlewareResult> | undefined): Promise<Response>;
41
22
  export {};
@@ -14,7 +14,6 @@ function createAPIContext({
14
14
  props,
15
15
  adapterName
16
16
  }) {
17
- initResponseWithEncoding();
18
17
  const context = {
19
18
  cookies: new AstroCookies(request),
20
19
  request,
@@ -61,28 +60,21 @@ function createAPIContext({
61
60
  });
62
61
  return context;
63
62
  }
64
- let ResponseWithEncoding;
65
- let initResponseWithEncoding = () => {
66
- class LocalResponseWithEncoding extends Response {
67
- constructor(body, init, encoding) {
68
- if (typeof body === "string") {
69
- if (typeof Buffer !== "undefined" && Buffer.from) {
70
- body = Buffer.from(body, encoding);
71
- } else if (encoding == null || encoding === "utf8" || encoding === "utf-8") {
72
- body = encoder.encode(body);
73
- }
74
- }
75
- super(body, init);
76
- if (encoding) {
77
- this.headers.set("X-Astro-Encoding", encoding);
63
+ class ResponseWithEncoding extends Response {
64
+ constructor(body, init, encoding) {
65
+ if (typeof body === "string") {
66
+ if (typeof Buffer !== "undefined" && Buffer.from) {
67
+ body = Buffer.from(body, encoding);
68
+ } else if (encoding == null || encoding === "utf8" || encoding === "utf-8") {
69
+ body = encoder.encode(body);
78
70
  }
79
71
  }
72
+ super(body, init);
73
+ if (encoding) {
74
+ this.headers.set("X-Astro-Encoding", encoding);
75
+ }
80
76
  }
81
- ResponseWithEncoding = LocalResponseWithEncoding;
82
- initResponseWithEncoding = () => {
83
- };
84
- return LocalResponseWithEncoding;
85
- };
77
+ }
86
78
  async function callEndpoint(mod, env, ctx, onRequest) {
87
79
  const context = createAPIContext({
88
80
  request: ctx.request,
@@ -1042,7 +1042,7 @@ export declare const ContentSchemaContainsSlugError: {
1042
1042
  /**
1043
1043
  * @docs
1044
1044
  * @message A collection queried via `getCollection()` does not exist.
1045
- * @deprecated Collections that do not exist no longer result in an error. A warning is omitted instead.
1045
+ * @deprecated Collections that do not exist no longer result in an error. A warning is given instead.
1046
1046
  * @description
1047
1047
  * When querying a collection, ensure a collection directory with the requested name exists under `src/content/`.
1048
1048
  */
@@ -50,7 +50,7 @@ function serverStart({
50
50
  base,
51
51
  isRestart = false
52
52
  }) {
53
- const version = "3.2.2";
53
+ const version = "3.2.4";
54
54
  const localPrefix = `${dim("\u2503")} Local `;
55
55
  const networkPrefix = `${dim("\u2503")} Network `;
56
56
  const emptyPrefix = " ".repeat(11);
@@ -235,7 +235,7 @@ function printHelp({
235
235
  message.push(
236
236
  linebreak(),
237
237
  ` ${bgGreen(black(` ${commandName} `))} ${green(
238
- `v${"3.2.2"}`
238
+ `v${"3.2.4"}`
239
239
  )} ${headline}`
240
240
  );
241
241
  }
@@ -1,14 +1,41 @@
1
1
  import { EventEmitter } from "node:events";
2
+ import path from "node:path";
2
3
  function createViteLoader(viteServer) {
3
4
  const events = new EventEmitter();
4
- viteServer.watcher.on("add", (...args) => events.emit("file-add", args));
5
- viteServer.watcher.on("unlink", (...args) => events.emit("file-unlink", args));
6
- viteServer.watcher.on("change", (...args) => events.emit("file-change", args));
7
- wrapMethod(viteServer.ws, "send", (msg) => {
5
+ let isTsconfigUpdated = false;
6
+ function isTsconfigUpdate(filePath) {
7
+ const result = path.basename(filePath) === "tsconfig.json";
8
+ if (result)
9
+ isTsconfigUpdated = true;
10
+ return result;
11
+ }
12
+ viteServer.watcher.on("add", (...args) => {
13
+ if (!isTsconfigUpdate(args[0])) {
14
+ events.emit("file-add", args);
15
+ }
16
+ });
17
+ viteServer.watcher.on("unlink", (...args) => {
18
+ if (!isTsconfigUpdate(args[0])) {
19
+ events.emit("file-unlink", args);
20
+ }
21
+ });
22
+ viteServer.watcher.on("change", (...args) => {
23
+ if (!isTsconfigUpdate(args[0])) {
24
+ events.emit("file-change", args);
25
+ }
26
+ });
27
+ const _wsSend = viteServer.ws.send;
28
+ viteServer.ws.send = function(...args) {
29
+ if (isTsconfigUpdated) {
30
+ isTsconfigUpdated = false;
31
+ return;
32
+ }
33
+ const msg = args[0];
8
34
  if (msg?.type === "error") {
9
35
  events.emit("hmr-error", msg);
10
36
  }
11
- });
37
+ _wsSend.apply(this, args);
38
+ };
12
39
  return {
13
40
  import(src) {
14
41
  return viteServer.ssrLoadModule(src);
@@ -50,13 +77,6 @@ function createViteLoader(viteServer) {
50
77
  events
51
78
  };
52
79
  }
53
- function wrapMethod(object, method, newFn) {
54
- const orig = object[method];
55
- object[method] = function(...args) {
56
- newFn.apply(this, args);
57
- return orig.apply(this, args);
58
- };
59
- }
60
80
  export {
61
81
  createViteLoader
62
82
  };
@@ -1,53 +1,6 @@
1
+ import buffer from "node:buffer";
1
2
  import crypto from "node:crypto";
2
- import {
3
- ByteLengthQueuingStrategy,
4
- CountQueuingStrategy,
5
- ReadableByteStreamController,
6
- ReadableStream,
7
- ReadableStreamBYOBReader,
8
- ReadableStreamBYOBRequest,
9
- ReadableStreamDefaultController,
10
- ReadableStreamDefaultReader,
11
- TransformStream,
12
- WritableStream,
13
- WritableStreamDefaultController,
14
- WritableStreamDefaultWriter
15
- } from "node:stream/web";
16
- import { File, FormData, Headers, Request, Response, fetch } from "undici";
17
- const isStackblitz = process.env.SHELL === "/bin/jsh" && process.versions.webcontainer != null;
18
3
  function apply() {
19
- if (isStackblitz) {
20
- const neededPolyfills = {
21
- ByteLengthQueuingStrategy,
22
- CountQueuingStrategy,
23
- ReadableByteStreamController,
24
- ReadableStream,
25
- ReadableStreamBYOBReader,
26
- ReadableStreamBYOBRequest,
27
- ReadableStreamDefaultController,
28
- ReadableStreamDefaultReader,
29
- TransformStream,
30
- WritableStream,
31
- WritableStreamDefaultController,
32
- WritableStreamDefaultWriter,
33
- File,
34
- FormData,
35
- Headers,
36
- Request,
37
- Response,
38
- fetch
39
- };
40
- for (let polyfillName of Object.keys(neededPolyfills)) {
41
- if (Object.hasOwnProperty.call(globalThis, polyfillName))
42
- continue;
43
- Object.defineProperty(globalThis, polyfillName, {
44
- configurable: true,
45
- enumerable: true,
46
- writable: true,
47
- value: neededPolyfills[polyfillName]
48
- });
49
- }
50
- }
51
4
  if (!globalThis.crypto) {
52
5
  Object.defineProperty(globalThis, "crypto", {
53
6
  value: crypto.webcrypto
@@ -55,7 +8,7 @@ function apply() {
55
8
  }
56
9
  if (!globalThis.File) {
57
10
  Object.defineProperty(globalThis, "File", {
58
- value: File
11
+ value: buffer.File
59
12
  });
60
13
  }
61
14
  }
@@ -7,12 +7,14 @@ export interface HydrationMetadata {
7
7
  value: string;
8
8
  };
9
9
  }
10
+ type Props = Record<string | number | symbol, any>;
10
11
  interface ExtractedProps {
11
12
  isPage: boolean;
12
13
  hydration: HydrationMetadata | null;
13
- props: Record<string | number | symbol, any>;
14
+ props: Props;
15
+ propsWithoutTransitionAttributes: Props;
14
16
  }
15
- export declare function extractDirectives(inputProps: Record<string | number | symbol, any>, clientDirectives: SSRResult['clientDirectives']): ExtractedProps;
17
+ export declare function extractDirectives(inputProps: Props, clientDirectives: SSRResult['clientDirectives']): ExtractedProps;
16
18
  interface HydrateScriptOptions {
17
19
  renderer: SSRLoadedRenderer;
18
20
  result: SSRResult;
@@ -9,7 +9,8 @@ function extractDirectives(inputProps, clientDirectives) {
9
9
  let extracted = {
10
10
  isPage: false,
11
11
  hydration: null,
12
- props: {}
12
+ props: {},
13
+ propsWithoutTransitionAttributes: {}
13
14
  };
14
15
  for (const [key, value] of Object.entries(inputProps)) {
15
16
  if (key.startsWith("server:")) {
@@ -58,10 +59,14 @@ function extractDirectives(inputProps, clientDirectives) {
58
59
  }
59
60
  } else {
60
61
  extracted.props[key] = value;
62
+ if (!transitionDirectivesToCopyOnIsland.includes(key)) {
63
+ extracted.propsWithoutTransitionAttributes[key] = value;
64
+ }
61
65
  }
62
66
  }
63
67
  for (const sym of Object.getOwnPropertySymbols(inputProps)) {
64
68
  extracted.props[sym] = inputProps[sym];
69
+ extracted.propsWithoutTransitionAttributes[sym] = inputProps[sym];
65
70
  }
66
71
  return extracted;
67
72
  }
@@ -69,9 +74,10 @@ async function generateHydrateScript(scriptOptions, metadata) {
69
74
  const { renderer, result, astroId, props, attrs } = scriptOptions;
70
75
  const { hydrate, componentUrl, componentExport } = metadata;
71
76
  if (!componentExport.value) {
72
- throw new Error(
73
- `Unable to resolve a valid export for "${metadata.displayName}"! Please open an issue at https://astro.build/issues!`
74
- );
77
+ throw new AstroError({
78
+ ...AstroErrorData.NoMatchingImport,
79
+ message: AstroErrorData.NoMatchingImport.message(metadata.displayName)
80
+ });
75
81
  }
76
82
  const island = {
77
83
  children: "",
@@ -67,7 +67,10 @@ Did you forget to import the component or is it possible there is a typo?`
67
67
  astroStaticSlot: true,
68
68
  displayName
69
69
  };
70
- const { hydration, isPage, props } = extractDirectives(_props, clientDirectives);
70
+ const { hydration, isPage, props, propsWithoutTransitionAttributes } = extractDirectives(
71
+ _props,
72
+ clientDirectives
73
+ );
71
74
  let html = "";
72
75
  let attrs = void 0;
73
76
  if (hydration) {
@@ -169,7 +172,7 @@ Did you forget to import the component or is it possible there is a typo?`
169
172
  ({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
170
173
  { result },
171
174
  Component,
172
- props,
175
+ propsWithoutTransitionAttributes,
173
176
  children,
174
177
  metadata
175
178
  ));
@@ -194,7 +197,7 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
194
197
  ({ html, attrs } = await renderer.ssr.renderToStaticMarkup.call(
195
198
  { result },
196
199
  Component,
197
- props,
200
+ propsWithoutTransitionAttributes,
198
201
  children,
199
202
  metadata
200
203
  ));
@@ -26,10 +26,6 @@ const announce = () => {
26
26
  };
27
27
  const PERSIST_ATTR = "data-astro-transition-persist";
28
28
  const parser = new DOMParser();
29
- let noopEl;
30
- if (import.meta.env.DEV) {
31
- noopEl = document.createElement("div");
32
- }
33
29
  let currentHistoryIndex = 0;
34
30
  if (history.state) {
35
31
  currentHistoryIndex = history.state.index;
@@ -115,21 +111,29 @@ function isInfinite(animation) {
115
111
  }
116
112
  const updateHistoryAndScrollPosition = (toLocation, replace, intraPage) => {
117
113
  const fresh = !samePage(toLocation);
114
+ let scrolledToTop = false;
118
115
  if (toLocation.href !== location.href) {
119
116
  if (replace) {
120
117
  history.replaceState({ ...history.state }, "", toLocation.href);
121
118
  } else {
122
119
  history.replaceState({ ...history.state, intraPage }, "");
123
- history.pushState({ index: ++currentHistoryIndex, scrollX, scrollY }, "", toLocation.href);
120
+ history.pushState(
121
+ { index: ++currentHistoryIndex, scrollX: 0, scrollY: 0 },
122
+ "",
123
+ toLocation.href
124
+ );
124
125
  }
125
126
  if (fresh) {
126
127
  scrollTo({ left: 0, top: 0, behavior: "instant" });
128
+ scrolledToTop = true;
127
129
  }
128
130
  }
129
131
  if (toLocation.hash) {
130
132
  location.href = toLocation.href;
131
133
  } else {
132
- scrollTo({ left: 0, top: 0, behavior: "instant" });
134
+ if (!scrolledToTop) {
135
+ scrollTo({ left: 0, top: 0, behavior: "instant" });
136
+ }
133
137
  }
134
138
  };
135
139
  async function updateDOM(newDocument, toLocation, options, popState, fallback) {
@@ -143,13 +147,6 @@ async function updateDOM(newDocument, toLocation, options, popState, fallback) {
143
147
  const href = el.getAttribute("href");
144
148
  return newDocument.head.querySelector(`link[rel=stylesheet][href="${href}"]`);
145
149
  }
146
- if (import.meta.env.DEV) {
147
- if (el.tagName === "STYLE" && el.dataset.viteDevId) {
148
- const devId = el.dataset.viteDevId;
149
- return newDocument.querySelector(`style[data-vite-dev-id="${devId}"]`) || // Otherwise, keep it anyways. This is client:only styles.
150
- noopEl;
151
- }
152
- }
153
150
  return null;
154
151
  };
155
152
  const swap = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "3.2.2",
3
+ "version": "3.2.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",
@@ -152,7 +152,6 @@
152
152
  "string-width": "^6.1.0",
153
153
  "strip-ansi": "^7.1.0",
154
154
  "tsconfig-resolver": "^3.0.1",
155
- "undici": "^5.23.0",
156
155
  "unist-util-visit": "^4.1.2",
157
156
  "vfile": "^5.3.7",
158
157
  "vite": "^4.4.9",
@@ -160,9 +159,9 @@
160
159
  "which-pm": "^2.1.1",
161
160
  "yargs-parser": "^21.1.1",
162
161
  "zod": "3.21.1",
163
- "@astrojs/internal-helpers": "0.2.0",
164
- "@astrojs/markdown-remark": "3.2.0",
165
- "@astrojs/telemetry": "3.0.2"
162
+ "@astrojs/internal-helpers": "0.2.1",
163
+ "@astrojs/markdown-remark": "3.2.1",
164
+ "@astrojs/telemetry": "3.0.3"
166
165
  },
167
166
  "optionalDependencies": {
168
167
  "sharp": "^0.32.5"
@@ -214,6 +213,9 @@
214
213
  "node": ">=18.14.1",
215
214
  "npm": ">=6.14.0"
216
215
  },
216
+ "publishConfig": {
217
+ "provenance": true
218
+ },
217
219
  "scripts": {
218
220
  "prebuild": "astro-scripts prebuild --to-string \"src/runtime/server/astro-island.ts\" \"src/runtime/client/{idle,load,media,only,visible}.ts\"",
219
221
  "build": "pnpm run prebuild && astro-scripts build \"src/**/*.{ts,js}\" && tsc && pnpm run postbuild",