astro 3.4.4 → 3.5.0

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 (141) hide show
  1. package/client.d.ts +86 -0
  2. package/components/Code.astro +15 -2
  3. package/components/Picture.astro +2 -1
  4. package/components/ViewTransitions.astro +39 -38
  5. package/content-module.template.mjs +4 -14
  6. package/dist/@types/astro.d.ts +222 -5
  7. package/dist/assets/build/generate.d.ts +2 -1
  8. package/dist/assets/build/generate.js +16 -5
  9. package/dist/assets/consts.d.ts +1 -0
  10. package/dist/assets/consts.js +2 -0
  11. package/dist/assets/endpoint/generic.js +6 -2
  12. package/dist/assets/internal.js +9 -2
  13. package/dist/assets/services/service.d.ts +8 -3
  14. package/dist/assets/services/service.js +2 -1
  15. package/dist/assets/services/vendor/squoosh/image-pool.d.ts +1 -2
  16. package/dist/assets/types.d.ts +9 -5
  17. package/dist/assets/utils/emitAsset.js +5 -0
  18. package/dist/assets/utils/metadata.d.ts +1 -2
  19. package/dist/assets/utils/proxy.d.ts +1 -0
  20. package/dist/assets/utils/proxy.js +16 -0
  21. package/dist/assets/utils/queryParams.d.ts +1 -1
  22. package/dist/assets/utils/transformToPath.d.ts +1 -1
  23. package/dist/assets/utils/transformToPath.js +8 -3
  24. package/dist/assets/vite-plugin-assets.js +26 -11
  25. package/dist/cli/build/index.js +1 -1
  26. package/dist/content/consts.d.ts +1 -0
  27. package/dist/content/consts.js +2 -0
  28. package/dist/content/runtime-assets.d.ts +9 -1
  29. package/dist/content/runtime-assets.js +1 -1
  30. package/dist/content/runtime.d.ts +1 -0
  31. package/dist/content/runtime.js +8 -2
  32. package/dist/content/utils.d.ts +1 -0
  33. package/dist/content/utils.js +9 -0
  34. package/dist/content/vite-plugin-content-assets.js +49 -23
  35. package/dist/content/vite-plugin-content-imports.js +9 -3
  36. package/dist/content/vite-plugin-content-virtual-mod.d.ts +17 -12
  37. package/dist/content/vite-plugin-content-virtual-mod.js +136 -57
  38. package/dist/core/app/index.js +19 -4
  39. package/dist/core/app/types.d.ts +7 -1
  40. package/dist/core/build/buildPipeline.js +17 -4
  41. package/dist/core/build/common.js +2 -0
  42. package/dist/core/build/generate.js +64 -34
  43. package/dist/core/build/index.d.ts +0 -8
  44. package/dist/core/build/index.js +9 -2
  45. package/dist/core/build/internal.d.ts +11 -1
  46. package/dist/core/build/internal.js +23 -1
  47. package/dist/core/build/page-data.js +46 -18
  48. package/dist/core/build/plugin.d.ts +12 -10
  49. package/dist/core/build/plugin.js +14 -22
  50. package/dist/core/build/plugins/index.js +4 -0
  51. package/dist/core/build/plugins/plugin-alias-resolve.js +1 -1
  52. package/dist/core/build/plugins/plugin-analyzer.js +1 -1
  53. package/dist/core/build/plugins/plugin-chunks.d.ts +4 -0
  54. package/dist/core/build/plugins/plugin-chunks.js +31 -0
  55. package/dist/core/build/plugins/plugin-component-entry.js +1 -1
  56. package/dist/core/build/plugins/plugin-content.d.ts +4 -0
  57. package/dist/core/build/plugins/plugin-content.js +273 -0
  58. package/dist/core/build/plugins/plugin-css.js +9 -4
  59. package/dist/core/build/plugins/plugin-hoisted-scripts.js +1 -1
  60. package/dist/core/build/plugins/plugin-internals.js +1 -1
  61. package/dist/core/build/plugins/plugin-manifest.js +14 -5
  62. package/dist/core/build/plugins/plugin-middleware.d.ts +1 -3
  63. package/dist/core/build/plugins/plugin-middleware.js +5 -57
  64. package/dist/core/build/plugins/plugin-pages.js +3 -3
  65. package/dist/core/build/plugins/plugin-prerender.js +2 -5
  66. package/dist/core/build/plugins/plugin-renderers.js +1 -1
  67. package/dist/core/build/plugins/plugin-ssr.js +6 -5
  68. package/dist/core/build/plugins/util.d.ts +3 -3
  69. package/dist/core/build/static-build.d.ts +2 -1
  70. package/dist/core/build/static-build.js +52 -28
  71. package/dist/core/build/types.d.ts +1 -1
  72. package/dist/core/build/util.d.ts +7 -0
  73. package/dist/core/build/util.js +37 -1
  74. package/dist/core/compile/compile.js +1 -0
  75. package/dist/core/config/config.js +3 -0
  76. package/dist/core/config/schema.d.ts +208 -0
  77. package/dist/core/config/schema.js +55 -2
  78. package/dist/core/config/settings.js +1 -0
  79. package/dist/core/constants.js +1 -1
  80. package/dist/core/create-vite.js +9 -3
  81. package/dist/core/dev/dev.js +1 -1
  82. package/dist/core/endpoint/index.d.ts +4 -3
  83. package/dist/core/endpoint/index.js +29 -3
  84. package/dist/core/errors/errors-data.d.ts +11 -0
  85. package/dist/core/errors/errors-data.js +17 -0
  86. package/dist/core/messages.js +2 -2
  87. package/dist/core/middleware/index.d.ts +7 -3
  88. package/dist/core/middleware/index.js +3 -2
  89. package/dist/core/middleware/loadMiddleware.d.ts +1 -2
  90. package/dist/core/middleware/loadMiddleware.js +3 -4
  91. package/dist/core/middleware/sequence.d.ts +2 -2
  92. package/dist/core/middleware/sequence.js +3 -2
  93. package/dist/core/middleware/vite-plugin.d.ts +9 -0
  94. package/dist/core/middleware/vite-plugin.js +101 -0
  95. package/dist/core/pipeline.d.ts +1 -1
  96. package/dist/core/pipeline.js +6 -4
  97. package/dist/core/redirects/helpers.d.ts +1 -0
  98. package/dist/core/redirects/helpers.js +4 -0
  99. package/dist/core/render/context.d.ts +24 -1
  100. package/dist/core/render/context.js +96 -2
  101. package/dist/core/render/core.d.ts +2 -14
  102. package/dist/core/render/core.js +12 -52
  103. package/dist/core/render/index.d.ts +2 -3
  104. package/dist/core/render/index.js +3 -4
  105. package/dist/core/render/params-and-props.d.ts +1 -1
  106. package/dist/core/render/params-and-props.js +5 -2
  107. package/dist/core/render/result.d.ts +1 -0
  108. package/dist/core/render/result.js +23 -0
  109. package/dist/core/render/route-cache.d.ts +1 -1
  110. package/dist/core/render/route-cache.js +17 -11
  111. package/dist/core/routing/manifest/create.js +118 -4
  112. package/dist/core/sync/index.d.ts +2 -24
  113. package/dist/i18n/index.d.ts +54 -0
  114. package/dist/i18n/index.js +91 -0
  115. package/dist/i18n/middleware.d.ts +2 -0
  116. package/dist/i18n/middleware.js +62 -0
  117. package/dist/i18n/vite-plugin-i18n.d.ts +7 -0
  118. package/dist/i18n/vite-plugin-i18n.js +62 -0
  119. package/dist/integrations/astroFeaturesValidation.js +4 -1
  120. package/dist/integrations/index.js +12 -0
  121. package/dist/prefetch/index.d.ts +31 -0
  122. package/dist/prefetch/index.js +176 -0
  123. package/dist/prefetch/vite-plugin-prefetch.d.ts +5 -0
  124. package/dist/prefetch/vite-plugin-prefetch.js +43 -0
  125. package/dist/runtime/client/dev-overlay/plugins/audit.js +17 -9
  126. package/dist/runtime/server/index.d.ts +0 -2
  127. package/dist/runtime/server/render/component.js +3 -5
  128. package/dist/transitions/router.d.ts +1 -0
  129. package/dist/transitions/router.js +9 -4
  130. package/dist/transitions/vite-plugin-transitions.d.ts +4 -1
  131. package/dist/transitions/vite-plugin-transitions.js +7 -1
  132. package/dist/vite-plugin-astro-server/devPipeline.d.ts +1 -0
  133. package/dist/vite-plugin-astro-server/devPipeline.js +2 -0
  134. package/dist/vite-plugin-astro-server/plugin.js +11 -1
  135. package/dist/vite-plugin-astro-server/route.js +113 -51
  136. package/dist/vite-plugin-head/index.js +1 -1
  137. package/dist/vite-plugin-markdown/index.js +1 -0
  138. package/package.json +7 -5
  139. package/tsconfigs/base.json +1 -1
  140. package/dist/core/endpoint/dev/index.d.ts +0 -2
  141. package/dist/core/endpoint/dev/index.js +0 -17
@@ -94,6 +94,18 @@ async function runHookConfigSetup({
94
94
  }
95
95
  addedClientDirectives.set(name, buildClientDirectiveEntrypoint(name, entrypoint));
96
96
  },
97
+ addMiddleware: ({ order, entrypoint }) => {
98
+ if (typeof updatedSettings.middlewares[order] === "undefined") {
99
+ throw new Error(
100
+ `The "${integration.name}" integration is trying to add middleware but did not specify an order.`
101
+ );
102
+ }
103
+ logger.debug(
104
+ "middleware",
105
+ `The integration ${integration.name} has added middleware that runs ${order === "pre" ? "before" : "after"} any application middleware you define.`
106
+ );
107
+ updatedSettings.middlewares[order].push(entrypoint);
108
+ },
97
109
  logger: integrationLogger
98
110
  };
99
111
  Object.defineProperty(hooks, "addPageExtension", {
@@ -0,0 +1,31 @@
1
+ interface InitOptions {
2
+ defaultStrategy?: string;
3
+ prefetchAll?: boolean;
4
+ }
5
+ /**
6
+ * Initialize the prefetch script, only works once.
7
+ *
8
+ * @param defaultOpts Default options for prefetching if not already set by the user config.
9
+ */
10
+ export declare function init(defaultOpts?: InitOptions): void;
11
+ export interface PrefetchOptions {
12
+ /**
13
+ * How the prefetch should prioritize the URL. (default `'link'`)
14
+ * - `'link'`: use `<link rel="prefetch">`, has lower loading priority.
15
+ * - `'fetch'`: use `fetch()`, has higher loading priority.
16
+ */
17
+ with?: 'link' | 'fetch';
18
+ }
19
+ /**
20
+ * Prefetch a URL so it's cached when the user navigates to it.
21
+ *
22
+ * @param url A full or partial URL string based on the current `location.href`. They are only fetched if:
23
+ * - The user is online
24
+ * - The user is not in data saver mode
25
+ * - The URL is within the same origin
26
+ * - The URL is not the current page
27
+ * - The URL has not already been prefetched
28
+ * @param opts Additional options for prefetching.
29
+ */
30
+ export declare function prefetch(url: string, opts?: PrefetchOptions): void;
31
+ export {};
@@ -0,0 +1,176 @@
1
+ const debug = import.meta.env.DEV ? console.debug : void 0;
2
+ const inBrowser = import.meta.env.SSR === false;
3
+ const prefetchedUrls = /* @__PURE__ */ new Set();
4
+ const listenedAnchors = /* @__PURE__ */ new WeakSet();
5
+ let prefetchAll = __PREFETCH_PREFETCH_ALL__;
6
+ let defaultStrategy = __PREFETCH_DEFAULT_STRATEGY__;
7
+ let inited = false;
8
+ function init(defaultOpts) {
9
+ if (!inBrowser)
10
+ return;
11
+ if (inited)
12
+ return;
13
+ inited = true;
14
+ debug?.(`[astro] Initializing prefetch script`);
15
+ prefetchAll ??= defaultOpts?.prefetchAll ?? false;
16
+ defaultStrategy ??= defaultOpts?.defaultStrategy ?? "hover";
17
+ initTapStrategy();
18
+ initHoverStrategy();
19
+ initViewportStrategy();
20
+ }
21
+ function initTapStrategy() {
22
+ for (const event of ["touchstart", "mousedown"]) {
23
+ document.body.addEventListener(
24
+ event,
25
+ (e) => {
26
+ if (elMatchesStrategy(e.target, "tap")) {
27
+ prefetch(e.target.href, { with: "fetch" });
28
+ }
29
+ },
30
+ { passive: true }
31
+ );
32
+ }
33
+ }
34
+ function initHoverStrategy() {
35
+ let timeout;
36
+ document.body.addEventListener(
37
+ "focusin",
38
+ (e) => {
39
+ if (elMatchesStrategy(e.target, "hover")) {
40
+ handleHoverIn(e);
41
+ }
42
+ },
43
+ { passive: true }
44
+ );
45
+ document.body.addEventListener("focusout", handleHoverOut, { passive: true });
46
+ onPageLoad(() => {
47
+ for (const anchor of document.getElementsByTagName("a")) {
48
+ if (listenedAnchors.has(anchor))
49
+ continue;
50
+ if (elMatchesStrategy(anchor, "hover")) {
51
+ listenedAnchors.add(anchor);
52
+ anchor.addEventListener("mouseenter", handleHoverIn, { passive: true });
53
+ anchor.addEventListener("mouseleave", handleHoverOut, { passive: true });
54
+ }
55
+ }
56
+ });
57
+ function handleHoverIn(e) {
58
+ const href = e.target.href;
59
+ if (timeout) {
60
+ clearTimeout(timeout);
61
+ }
62
+ timeout = setTimeout(() => {
63
+ prefetch(href, { with: "fetch" });
64
+ }, 80);
65
+ }
66
+ function handleHoverOut() {
67
+ if (timeout) {
68
+ clearTimeout(timeout);
69
+ timeout = 0;
70
+ }
71
+ }
72
+ }
73
+ function initViewportStrategy() {
74
+ let observer;
75
+ onPageLoad(() => {
76
+ for (const anchor of document.getElementsByTagName("a")) {
77
+ if (listenedAnchors.has(anchor))
78
+ continue;
79
+ if (elMatchesStrategy(anchor, "viewport")) {
80
+ listenedAnchors.add(anchor);
81
+ observer ??= createViewportIntersectionObserver();
82
+ observer.observe(anchor);
83
+ }
84
+ }
85
+ });
86
+ }
87
+ function createViewportIntersectionObserver() {
88
+ const timeouts = /* @__PURE__ */ new WeakMap();
89
+ return new IntersectionObserver((entries, observer) => {
90
+ for (const entry of entries) {
91
+ const anchor = entry.target;
92
+ const timeout = timeouts.get(anchor);
93
+ if (entry.isIntersecting) {
94
+ if (timeout) {
95
+ clearTimeout(timeout);
96
+ }
97
+ timeouts.set(
98
+ anchor,
99
+ setTimeout(() => {
100
+ observer.unobserve(anchor);
101
+ timeouts.delete(anchor);
102
+ prefetch(anchor.href, { with: "link" });
103
+ }, 300)
104
+ );
105
+ } else {
106
+ if (timeout) {
107
+ clearTimeout(timeout);
108
+ timeouts.delete(anchor);
109
+ }
110
+ }
111
+ }
112
+ });
113
+ }
114
+ function prefetch(url, opts) {
115
+ if (!canPrefetchUrl(url))
116
+ return;
117
+ prefetchedUrls.add(url);
118
+ const priority = opts?.with ?? "link";
119
+ debug?.(`[astro] Prefetching ${url} with ${priority}`);
120
+ if (priority === "link") {
121
+ const link = document.createElement("link");
122
+ link.rel = "prefetch";
123
+ link.setAttribute("href", url);
124
+ document.head.append(link);
125
+ } else {
126
+ fetch(url).catch((e) => {
127
+ console.log(`[astro] Failed to prefetch ${url}`);
128
+ console.error(e);
129
+ });
130
+ }
131
+ }
132
+ function canPrefetchUrl(url) {
133
+ if (!navigator.onLine)
134
+ return false;
135
+ if ("connection" in navigator) {
136
+ const conn = navigator.connection;
137
+ if (conn.saveData || /(2|3)g/.test(conn.effectiveType))
138
+ return false;
139
+ }
140
+ try {
141
+ const urlObj = new URL(url, location.href);
142
+ return location.origin === urlObj.origin && location.pathname !== urlObj.pathname && !prefetchedUrls.has(url);
143
+ } catch {
144
+ }
145
+ return false;
146
+ }
147
+ function elMatchesStrategy(el, strategy) {
148
+ if (el?.tagName !== "A")
149
+ return false;
150
+ const attrValue = el.dataset.astroPrefetch;
151
+ if (attrValue === "false") {
152
+ return false;
153
+ }
154
+ if (attrValue == null && prefetchAll || attrValue === "") {
155
+ return strategy === defaultStrategy;
156
+ }
157
+ if (attrValue === strategy) {
158
+ return true;
159
+ }
160
+ return false;
161
+ }
162
+ function onPageLoad(cb) {
163
+ cb();
164
+ let firstLoad = false;
165
+ document.addEventListener("astro:page-load", () => {
166
+ if (!firstLoad) {
167
+ firstLoad = true;
168
+ return;
169
+ }
170
+ cb();
171
+ });
172
+ }
173
+ export {
174
+ init,
175
+ prefetch
176
+ };
@@ -0,0 +1,5 @@
1
+ import * as vite from 'vite';
2
+ import type { AstroSettings } from '../@types/astro.js';
3
+ export default function astroPrefetch({ settings }: {
4
+ settings: AstroSettings;
5
+ }): vite.Plugin;
@@ -0,0 +1,43 @@
1
+ import * as vite from "vite";
2
+ const virtualModuleId = "astro:prefetch";
3
+ const resolvedVirtualModuleId = "\0" + virtualModuleId;
4
+ const prefetchInternalModuleFsSubpath = "astro/dist/prefetch/index.js";
5
+ const prefetchCode = `import { init } from 'astro/prefetch';init()`;
6
+ function astroPrefetch({ settings }) {
7
+ const prefetchOption = settings.config.prefetch;
8
+ const prefetch = prefetchOption ? typeof prefetchOption === "object" ? prefetchOption : {} : void 0;
9
+ if (prefetch && settings.scripts.every((s) => s.content !== prefetchCode)) {
10
+ settings.scripts.push({
11
+ stage: "page",
12
+ content: `import { init } from 'astro/prefetch';init()`
13
+ });
14
+ }
15
+ const throwPrefetchNotEnabledError = () => {
16
+ throw new Error("You need to enable the `prefetch` Astro config to import `astro:prefetch`");
17
+ };
18
+ return {
19
+ name: "astro:prefetch",
20
+ async resolveId(id) {
21
+ if (id === virtualModuleId) {
22
+ if (!prefetch)
23
+ throwPrefetchNotEnabledError();
24
+ return resolvedVirtualModuleId;
25
+ }
26
+ },
27
+ load(id) {
28
+ if (id === resolvedVirtualModuleId) {
29
+ if (!prefetch)
30
+ throwPrefetchNotEnabledError();
31
+ return `export { prefetch } from "astro/prefetch";`;
32
+ }
33
+ },
34
+ transform(code, id) {
35
+ if (id.includes(prefetchInternalModuleFsSubpath)) {
36
+ return code.replace("__PREFETCH_PREFETCH_ALL__", JSON.stringify(prefetch?.prefetchAll)).replace("__PREFETCH_DEFAULT_STRATEGY__", JSON.stringify(prefetch?.defaultStrategy));
37
+ }
38
+ }
39
+ };
40
+ }
41
+ export {
42
+ astroPrefetch as default
43
+ };
@@ -84,12 +84,12 @@ var audit_default = {
84
84
  }
85
85
  const rect = originalElement.getBoundingClientRect();
86
86
  const highlight = createHighlight(rect, "warning");
87
- const tooltip = buildAuditTooltip(rule);
87
+ const tooltip = buildAuditTooltip(rule, originalElement);
88
88
  attachTooltipToHighlight(highlight, tooltip, originalElement);
89
89
  canvas.append(highlight);
90
90
  audits.push({ highlightElement: highlight, auditedElement: originalElement });
91
91
  }
92
- function buildAuditTooltip(rule) {
92
+ function buildAuditTooltip(rule, element) {
93
93
  const tooltip = document.createElement("astro-dev-overlay-tooltip");
94
94
  tooltip.sections = [
95
95
  {
@@ -99,14 +99,22 @@ var audit_default = {
99
99
  {
100
100
  content: rule.message
101
101
  }
102
- // TODO: Add a link to the file
103
- // Needs https://github.com/withastro/compiler/pull/375
104
- // {
105
- // content: '/src/somewhere/component.astro',
106
- // clickDescription: 'Click to go to file',
107
- // clickAction() {},
108
- // },
109
102
  ];
103
+ const elementFile = element.getAttribute("data-astro-source-file");
104
+ const elementPosition = element.getAttribute("data-astro-source-loc");
105
+ if (elementFile) {
106
+ const elementFileWithPosition = elementFile + (elementPosition ? ":" + elementPosition : "");
107
+ tooltip.sections.push({
108
+ content: elementFileWithPosition.slice(
109
+ window.__astro_dev_overlay__.root.length - 1
110
+ // We want to keep the final slash, so minus one.
111
+ ),
112
+ clickDescription: "Click to go to file",
113
+ async clickAction() {
114
+ await fetch("/__open-in-editor?file=" + encodeURIComponent(elementFileWithPosition));
115
+ }
116
+ });
117
+ }
110
118
  return tooltip;
111
119
  }
112
120
  function initStyle() {
@@ -7,8 +7,6 @@ export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRe
7
7
  export type { AstroComponentFactory, AstroComponentInstance, ComponentSlots, RenderInstruction, } from './render/index.js';
8
8
  export { createTransitionScope, renderTransition } from './transition.js';
9
9
  export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
10
- /** @internal Associate JSX components with a specific renderer (see /src/vite-plugin-jsx/tag.ts) */
11
- export declare function __astro_tag_component__(Component: unknown, rendererName: string): void;
12
10
  export declare function spreadAttributes(values?: Record<any, any>, _name?: string, { class: scopedClassName }?: {
13
11
  class?: string;
14
12
  }): any;
@@ -6,11 +6,9 @@ import { extractDirectives, generateHydrateScript } from "../hydration.js";
6
6
  import { serializeProps } from "../serialize.js";
7
7
  import { shorthash } from "../shorthash.js";
8
8
  import { isPromise } from "../util.js";
9
- import {
10
- createAstroComponentInstance,
11
- isAstroComponentFactory,
12
- renderTemplate
13
- } from "./astro/index.js";
9
+ import { isAstroComponentFactory } from "./astro/factory.js";
10
+ import { renderTemplate } from "./astro/index.js";
11
+ import { createAstroComponentInstance } from "./astro/instance.js";
14
12
  import {
15
13
  Fragment,
16
14
  Renderer,
@@ -2,6 +2,7 @@ export type Fallback = 'none' | 'animate' | 'swap';
2
2
  export type Direction = 'forward' | 'back';
3
3
  export type Options = {
4
4
  history?: 'auto' | 'push' | 'replace';
5
+ formData?: FormData;
5
6
  };
6
7
  export declare const supportsViewTransitions: boolean;
7
8
  export declare const transitionEnabledOnThisPage: () => boolean;
@@ -53,9 +53,9 @@ const throttle = (cb, delay) => {
53
53
  }, delay);
54
54
  };
55
55
  };
56
- async function fetchHTML(href) {
56
+ async function fetchHTML(href, init) {
57
57
  try {
58
- const res = await fetch(href);
58
+ const res = await fetch(href, init);
59
59
  const mediaType = res.headers.get("content-type")?.replace(/;.*$/, "");
60
60
  if (mediaType !== "text/html" && mediaType !== "application/xhtml+xml") {
61
61
  return null;
@@ -253,7 +253,12 @@ async function updateDOM(newDocument, toLocation, options, popState, fallback) {
253
253
  async function transition(direction, toLocation, options, popState) {
254
254
  let finished;
255
255
  const href = toLocation.href;
256
- const response = await fetchHTML(href);
256
+ const init = {};
257
+ if (options.formData) {
258
+ init.method = "POST";
259
+ init.body = options.formData;
260
+ }
261
+ const response = await fetchHTML(href, init);
257
262
  if (response === null) {
258
263
  location.href = href;
259
264
  return;
@@ -264,7 +269,7 @@ async function transition(direction, toLocation, options, popState) {
264
269
  parser ??= new DOMParser();
265
270
  const newDocument = parser.parseFromString(response.html, response.mediaType);
266
271
  newDocument.querySelectorAll("noscript").forEach((el) => el.remove());
267
- if (!newDocument.querySelector('[name="astro-view-transitions-enabled"]')) {
272
+ if (!newDocument.querySelector('[name="astro-view-transitions-enabled"]') && !options.formData) {
268
273
  location.href = href;
269
274
  return;
270
275
  }
@@ -1,2 +1,5 @@
1
1
  import * as vite from 'vite';
2
- export default function astroTransitions(): vite.Plugin;
2
+ import type { AstroSettings } from '../@types/astro.js';
3
+ export default function astroTransitions({ settings }: {
4
+ settings: AstroSettings;
5
+ }): vite.Plugin;
@@ -3,7 +3,7 @@ const virtualModuleId = "astro:transitions";
3
3
  const resolvedVirtualModuleId = "\0" + virtualModuleId;
4
4
  const virtualClientModuleId = "astro:transitions/client";
5
5
  const resolvedVirtualClientModuleId = "\0" + virtualClientModuleId;
6
- function astroTransitions() {
6
+ function astroTransitions({ settings }) {
7
7
  return {
8
8
  name: "astro:transitions",
9
9
  async resolveId(id) {
@@ -26,6 +26,12 @@ function astroTransitions() {
26
26
  export * from "astro/transitions/router";
27
27
  `;
28
28
  }
29
+ },
30
+ transform(code, id) {
31
+ if (id.includes("ViewTransitions.astro") && id.endsWith(".ts")) {
32
+ const prefetchDisabled = settings.config.prefetch === false;
33
+ return code.replace("__PREFETCH_DISABLED__", JSON.stringify(prefetchDisabled));
34
+ }
29
35
  }
30
36
  };
31
37
  }
@@ -18,4 +18,5 @@ export default class DevPipeline extends Pipeline {
18
18
  get logger(): Readonly<Logger>;
19
19
  loadRenderers(): Promise<void>;
20
20
  static createDevelopmentEnvironment(manifest: SSRManifest, settings: AstroSettings, logger: Logger, loader: ModuleLoader): Environment;
21
+ handleFallback(): Promise<void>;
21
22
  }
@@ -61,6 +61,8 @@ class DevPipeline extends Pipeline {
61
61
  async #handleEndpointResult(_, response) {
62
62
  return response;
63
63
  }
64
+ async handleFallback() {
65
+ }
64
66
  }
65
67
  export {
66
68
  DevPipeline as default
@@ -59,6 +59,15 @@ function createVitePluginAstroServer({
59
59
  };
60
60
  }
61
61
  function createDevelopmentManifest(settings) {
62
+ let i18nManifest = void 0;
63
+ if (settings.config.experimental.i18n) {
64
+ i18nManifest = {
65
+ fallback: settings.config.experimental.i18n.fallback,
66
+ routingStrategy: settings.config.experimental.i18n.routingStrategy,
67
+ defaultLocale: settings.config.experimental.i18n.defaultLocale,
68
+ locales: settings.config.experimental.i18n.locales
69
+ };
70
+ }
62
71
  return {
63
72
  compressHTML: settings.config.compressHTML,
64
73
  assets: /* @__PURE__ */ new Set(),
@@ -70,7 +79,8 @@ function createDevelopmentManifest(settings) {
70
79
  base: settings.config.base,
71
80
  assetsPrefix: settings.config.build.assetsPrefix,
72
81
  site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : settings.config.site,
73
- componentMetadata: /* @__PURE__ */ new Map()
82
+ componentMetadata: /* @__PURE__ */ new Map(),
83
+ i18n: i18nManifest
74
84
  };
75
85
  }
76
86
  export {
@@ -1,10 +1,15 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import { AstroErrorData, isAstroError } from "../core/errors/index.js";
3
+ import { sequence } from "../core/middleware/index.js";
3
4
  import { loadMiddleware } from "../core/middleware/loadMiddleware.js";
4
- import { createRenderContext, getParamsAndProps } from "../core/render/index.js";
5
+ import {
6
+ createRenderContext,
7
+ getParamsAndProps
8
+ } from "../core/render/index.js";
5
9
  import { createRequest } from "../core/request.js";
6
10
  import { matchAllRoutes } from "../core/routing/index.js";
7
11
  import { isPage, resolveIdToUrl } from "../core/util.js";
12
+ import { createI18nMiddleware } from "../i18n/middleware.js";
8
13
  import { getSortedPreloadedMatches } from "../prerender/routing.js";
9
14
  import { isServerLikeOutput } from "../prerender/utils.js";
10
15
  import { PAGE_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
@@ -22,7 +27,7 @@ function getCustom404Route(manifestData) {
22
27
  async function matchRoute(pathname, manifestData, pipeline) {
23
28
  const env = pipeline.getEnvironment();
24
29
  const { routeCache, logger } = env;
25
- const matches = matchAllRoutes(pathname, manifestData);
30
+ let matches = matchAllRoutes(pathname, manifestData);
26
31
  const preloadedMatches = await getSortedPreloadedMatches({
27
32
  pipeline,
28
33
  matches,
@@ -96,67 +101,124 @@ async function handleRoute({
96
101
  manifest
97
102
  }) {
98
103
  const env = pipeline.getEnvironment();
99
- const settings = pipeline.getSettings();
100
104
  const config = pipeline.getConfig();
101
105
  const moduleLoader = pipeline.getModuleLoader();
102
106
  const { logger } = env;
103
- if (!matchedRoute) {
107
+ if (!matchedRoute && !config.experimental.i18n) {
104
108
  return handle404Response(origin, incomingRequest, incomingResponse);
105
109
  }
106
- const filePath = matchedRoute.filePath;
107
- const { route, preloadedComponent } = matchedRoute;
108
110
  const buildingToSSR = isServerLikeOutput(config);
109
- const request = createRequest({
110
- url,
111
- headers: buildingToSSR ? incomingRequest.headers : new Headers(),
112
- method: incomingRequest.method,
113
- body,
114
- logger,
115
- ssr: buildingToSSR,
116
- clientAddress: buildingToSSR ? incomingRequest.socket.remoteAddress : void 0,
117
- locals: Reflect.get(incomingRequest, clientLocalsSymbol)
118
- // Allows adapters to pass in locals in dev mode.
119
- });
120
- for (const [name, value] of Object.entries(config.server.headers ?? {})) {
121
- if (value)
122
- incomingResponse.setHeader(name, value);
123
- }
124
- const options = {
125
- env,
126
- filePath,
127
- preload: preloadedComponent,
128
- pathname,
129
- request,
130
- route
131
- };
132
- const middleware = await loadMiddleware(moduleLoader, settings.config.srcDir);
133
- if (middleware) {
134
- options.middleware = middleware;
111
+ let request;
112
+ let renderContext;
113
+ let mod = void 0;
114
+ let options = void 0;
115
+ let route;
116
+ const middleware = await loadMiddleware(moduleLoader);
117
+ if (!matchedRoute) {
118
+ if (config.experimental.i18n) {
119
+ const locales = config.experimental.i18n.locales;
120
+ const pathNameHasLocale = pathname.split("/").filter(Boolean).some((segment) => {
121
+ return locales.includes(segment);
122
+ });
123
+ if (!pathNameHasLocale && pathname !== "/") {
124
+ return handle404Response(origin, incomingRequest, incomingResponse);
125
+ }
126
+ request = createRequest({
127
+ url,
128
+ headers: buildingToSSR ? incomingRequest.headers : new Headers(),
129
+ logger,
130
+ ssr: buildingToSSR
131
+ });
132
+ route = {
133
+ component: "",
134
+ generate(_data) {
135
+ return "";
136
+ },
137
+ params: [],
138
+ pattern: new RegExp(""),
139
+ prerender: false,
140
+ segments: [],
141
+ type: "fallback",
142
+ route: ""
143
+ };
144
+ renderContext = await createRenderContext({
145
+ request,
146
+ pathname,
147
+ env,
148
+ mod,
149
+ route
150
+ });
151
+ } else {
152
+ return handle404Response(origin, incomingRequest, incomingResponse);
153
+ }
154
+ } else {
155
+ const filePath = matchedRoute.filePath;
156
+ const { preloadedComponent } = matchedRoute;
157
+ route = matchedRoute.route;
158
+ request = createRequest({
159
+ url,
160
+ headers: buildingToSSR ? incomingRequest.headers : new Headers(),
161
+ method: incomingRequest.method,
162
+ body,
163
+ logger,
164
+ ssr: buildingToSSR,
165
+ clientAddress: buildingToSSR ? incomingRequest.socket.remoteAddress : void 0,
166
+ locals: Reflect.get(incomingRequest, clientLocalsSymbol)
167
+ // Allows adapters to pass in locals in dev mode.
168
+ });
169
+ for (const [name, value] of Object.entries(config.server.headers ?? {})) {
170
+ if (value)
171
+ incomingResponse.setHeader(name, value);
172
+ }
173
+ options = {
174
+ env,
175
+ filePath,
176
+ preload: preloadedComponent,
177
+ pathname,
178
+ request,
179
+ route
180
+ };
181
+ if (middleware) {
182
+ options.middleware = middleware;
183
+ }
184
+ mod = options.preload;
185
+ const { scripts, links, styles, metadata } = await getScriptsAndStyles({
186
+ pipeline,
187
+ filePath: options.filePath
188
+ });
189
+ const i18n = pipeline.getConfig().experimental.i18n;
190
+ renderContext = await createRenderContext({
191
+ request: options.request,
192
+ pathname: options.pathname,
193
+ scripts,
194
+ links,
195
+ styles,
196
+ componentMetadata: metadata,
197
+ route: options.route,
198
+ mod,
199
+ env,
200
+ locales: i18n ? i18n.locales : void 0
201
+ });
135
202
  }
136
- const mod = options.preload;
137
- const { scripts, links, styles, metadata } = await getScriptsAndStyles({
138
- pipeline,
139
- filePath: options.filePath
140
- });
141
- const renderContext = await createRenderContext({
142
- request: options.request,
143
- pathname: options.pathname,
144
- scripts,
145
- links,
146
- styles,
147
- componentMetadata: metadata,
148
- route: options.route,
149
- mod,
150
- env
151
- });
152
- const onRequest = options.middleware?.onRequest;
153
- if (onRequest) {
203
+ const onRequest = middleware?.onRequest;
204
+ if (config.experimental.i18n) {
205
+ const i18Middleware = createI18nMiddleware(config.experimental.i18n, config.base);
206
+ if (i18Middleware) {
207
+ if (onRequest) {
208
+ pipeline.setMiddlewareFunction(sequence(i18Middleware, onRequest));
209
+ } else {
210
+ pipeline.setMiddlewareFunction(i18Middleware);
211
+ }
212
+ } else if (onRequest) {
213
+ pipeline.setMiddlewareFunction(onRequest);
214
+ }
215
+ } else if (onRequest) {
154
216
  pipeline.setMiddlewareFunction(onRequest);
155
217
  }
156
218
  let response = await pipeline.renderRoute(renderContext, mod);
157
219
  if (response.status === 404 && has404Route(manifestData)) {
158
220
  const fourOhFourRoute = await matchRoute("/404", manifestData, pipeline);
159
- if (fourOhFourRoute?.route !== options.route)
221
+ if (options && fourOhFourRoute?.route !== options.route)
160
222
  return handleRoute({
161
223
  ...options,
162
224
  matchedRoute: fourOhFourRoute,
@@ -71,7 +71,7 @@ function configHeadVitePlugin() {
71
71
  }
72
72
  function astroHeadBuildPlugin(internals) {
73
73
  return {
74
- build: "ssr",
74
+ targets: ["server"],
75
75
  hooks: {
76
76
  "build:before"() {
77
77
  return {