astro 2.4.4 → 2.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 (119) hide show
  1. package/astro-jsx.d.ts +5 -1
  2. package/dist/@types/astro.d.ts +130 -6
  3. package/dist/assets/generate.d.ts +22 -0
  4. package/dist/assets/generate.js +90 -0
  5. package/dist/assets/internal.d.ts +0 -21
  6. package/dist/assets/internal.js +0 -86
  7. package/dist/assets/vite-plugin-assets.js +13 -2
  8. package/dist/content/consts.d.ts +3 -1
  9. package/dist/content/consts.js +5 -1
  10. package/dist/content/runtime-assets.d.ts +1 -1
  11. package/dist/content/runtime.d.ts +61 -7
  12. package/dist/content/runtime.js +127 -4
  13. package/dist/content/template/virtual-mod.d.mts +4 -1
  14. package/dist/content/types-generator.js +155 -80
  15. package/dist/content/utils.d.ts +76 -23
  16. package/dist/content/utils.js +129 -65
  17. package/dist/content/vite-plugin-content-imports.js +110 -25
  18. package/dist/content/vite-plugin-content-virtual-mod.d.ts +4 -3
  19. package/dist/content/vite-plugin-content-virtual-mod.js +89 -45
  20. package/dist/core/app/common.js +2 -0
  21. package/dist/core/app/index.js +6 -4
  22. package/dist/core/app/types.d.ts +6 -1
  23. package/dist/core/build/generate.js +8 -9
  24. package/dist/core/build/index.d.ts +1 -1
  25. package/dist/core/build/plugins/plugin-pages.d.ts +0 -2
  26. package/dist/core/build/plugins/plugin-pages.js +3 -4
  27. package/dist/core/build/plugins/plugin-prerender.d.ts +0 -2
  28. package/dist/core/build/plugins/plugin-prerender.js +2 -2
  29. package/dist/core/build/plugins/plugin-ssr.d.ts +1 -4
  30. package/dist/core/build/plugins/plugin-ssr.js +4 -3
  31. package/dist/core/build/static-build.js +9 -7
  32. package/dist/core/client-directive/build.d.ts +4 -0
  33. package/dist/core/client-directive/build.js +28 -0
  34. package/dist/core/client-directive/default.d.ts +1 -0
  35. package/dist/core/client-directive/default.js +17 -0
  36. package/dist/core/client-directive/index.d.ts +2 -0
  37. package/dist/core/client-directive/index.js +6 -0
  38. package/dist/core/compile/compile.js +1 -0
  39. package/dist/core/config/config.js +6 -0
  40. package/dist/core/config/schema.d.ts +68 -12
  41. package/dist/core/config/schema.js +29 -3
  42. package/dist/core/config/settings.js +74 -2
  43. package/dist/core/config/vite-load.js +2 -1
  44. package/dist/core/constants.js +1 -1
  45. package/dist/core/dev/dev.js +1 -1
  46. package/dist/core/endpoint/dev/index.js +1 -1
  47. package/dist/core/endpoint/index.d.ts +1 -1
  48. package/dist/core/endpoint/index.js +16 -16
  49. package/dist/core/errors/errors-data.d.ts +55 -4
  50. package/dist/core/errors/errors-data.js +67 -7
  51. package/dist/core/errors/errors.d.ts +1 -0
  52. package/dist/core/errors/errors.js +5 -1
  53. package/dist/core/errors/index.d.ts +1 -1
  54. package/dist/core/errors/index.js +9 -1
  55. package/dist/core/errors/utils.d.ts +5 -0
  56. package/dist/core/errors/utils.js +14 -0
  57. package/dist/core/messages.js +2 -2
  58. package/dist/core/middleware/callMiddleware.d.ts +2 -1
  59. package/dist/core/middleware/callMiddleware.js +13 -3
  60. package/dist/core/render/core.js +1 -0
  61. package/dist/core/render/dev/environment.js +3 -1
  62. package/dist/core/render/dev/index.js +1 -1
  63. package/dist/core/render/environment.d.ts +1 -0
  64. package/dist/core/render/environment.js +2 -0
  65. package/dist/core/render/result.d.ts +1 -0
  66. package/dist/core/render/result.js +3 -2
  67. package/dist/core/routing/manifest/create.js +9 -2
  68. package/dist/core/sync/index.js +11 -1
  69. package/dist/core/util.js +2 -1
  70. package/dist/integrations/index.js +29 -3
  71. package/dist/jsx/babel.js +1 -2
  72. package/dist/prerender/utils.d.ts +3 -0
  73. package/dist/prerender/utils.js +10 -0
  74. package/dist/runtime/client/idle.d.ts +3 -0
  75. package/dist/runtime/client/idle.js +6 -3
  76. package/dist/runtime/client/idle.prebuilt.d.ts +1 -1
  77. package/dist/runtime/client/idle.prebuilt.js +1 -1
  78. package/dist/runtime/client/load.d.ts +3 -0
  79. package/dist/runtime/client/load.js +7 -6
  80. package/dist/runtime/client/load.prebuilt.d.ts +1 -1
  81. package/dist/runtime/client/load.prebuilt.js +1 -1
  82. package/dist/runtime/client/media.d.ts +6 -0
  83. package/dist/runtime/client/media.js +6 -3
  84. package/dist/runtime/client/media.prebuilt.d.ts +1 -1
  85. package/dist/runtime/client/media.prebuilt.js +1 -1
  86. package/dist/runtime/client/only.d.ts +6 -0
  87. package/dist/runtime/client/only.js +7 -6
  88. package/dist/runtime/client/only.prebuilt.d.ts +1 -1
  89. package/dist/runtime/client/only.prebuilt.js +1 -1
  90. package/dist/runtime/client/visible.d.ts +8 -0
  91. package/dist/runtime/client/visible.js +9 -6
  92. package/dist/runtime/client/visible.prebuilt.d.ts +1 -1
  93. package/dist/runtime/client/visible.prebuilt.js +1 -1
  94. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  95. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  96. package/dist/runtime/server/endpoint.js +1 -1
  97. package/dist/runtime/server/hydration.d.ts +1 -2
  98. package/dist/runtime/server/hydration.js +4 -9
  99. package/dist/runtime/server/render/astro/instance.js +1 -2
  100. package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
  101. package/dist/runtime/server/render/astro/render-template.js +10 -2
  102. package/dist/runtime/server/render/common.js +1 -1
  103. package/dist/runtime/server/render/component.js +20 -6
  104. package/dist/runtime/server/render/page.js +5 -0
  105. package/dist/runtime/server/render/util.d.ts +12 -0
  106. package/dist/runtime/server/render/util.js +89 -1
  107. package/dist/runtime/server/scripts.d.ts +1 -2
  108. package/dist/runtime/server/scripts.js +13 -21
  109. package/dist/vite-plugin-astro-server/request.js +2 -1
  110. package/dist/vite-plugin-astro-server/route.js +4 -3
  111. package/dist/vite-plugin-config-alias/index.js +13 -11
  112. package/dist/vite-plugin-jsx/index.js +1 -1
  113. package/dist/vite-plugin-scanner/index.js +6 -1
  114. package/dist/vite-plugin-scanner/scan.d.ts +1 -1
  115. package/dist/vite-plugin-scanner/scan.js +2 -2
  116. package/package.json +5 -3
  117. package/src/content/template/types.d.ts +108 -15
  118. package/src/content/template/virtual-mod.mjs +40 -16
  119. package/types.d.ts +6 -3
@@ -1,7 +1,8 @@
1
- (self.Astro = self.Astro || {}).load = (getHydrateCallback) => {
2
- (async () => {
3
- let hydrate = await getHydrateCallback();
4
- await hydrate();
5
- })();
1
+ const loadDirective = async (load) => {
2
+ const hydrate = await load();
3
+ await hydrate();
4
+ };
5
+ var load_default = loadDirective;
6
+ export {
7
+ load_default as default
6
8
  };
7
- window.dispatchEvent(new Event("astro:load"));
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro=self.Astro||{}).load=a=>{(async()=>await(await a())())()},window.dispatchEvent(new Event(\"astro:load\"));";
6
+ declare const _default: "(()=>{var e=async t=>{await(await t())()};(self.Astro||(self.Astro={})).load=e;window.dispatchEvent(new Event(\"astro:load\"));})();";
7
7
  export default _default;
@@ -1,4 +1,4 @@
1
- var load_prebuilt_default = `(self.Astro=self.Astro||{}).load=a=>{(async()=>await(await a())())()},window.dispatchEvent(new Event("astro:load"));`;
1
+ var load_prebuilt_default = `(()=>{var e=async t=>{await(await t())()};(self.Astro||(self.Astro={})).load=e;window.dispatchEvent(new Event("astro:load"));})();`;
2
2
  export {
3
3
  load_prebuilt_default as default
4
4
  };
@@ -0,0 +1,6 @@
1
+ import type { ClientDirective } from '../../@types/astro';
2
+ /**
3
+ * Hydrate this component when a matching media query is found
4
+ */
5
+ declare const mediaDirective: ClientDirective;
6
+ export default mediaDirective;
@@ -1,6 +1,6 @@
1
- (self.Astro = self.Astro || {}).media = (getHydrateCallback, options) => {
1
+ const mediaDirective = (load, options) => {
2
2
  const cb = async () => {
3
- let hydrate = await getHydrateCallback();
3
+ const hydrate = await load();
4
4
  await hydrate();
5
5
  };
6
6
  if (options.value) {
@@ -12,4 +12,7 @@
12
12
  }
13
13
  }
14
14
  };
15
- window.dispatchEvent(new Event("astro:media"));
15
+ var media_default = mediaDirective;
16
+ export {
17
+ media_default as default
18
+ };
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro=self.Astro||{}).media=(s,a)=>{const t=async()=>{await(await s())()};if(a.value){const e=matchMedia(a.value);e.matches?t():e.addEventListener(\"change\",t,{once:!0})}},window.dispatchEvent(new Event(\"astro:media\"));";
6
+ declare const _default: "(()=>{var s=(i,t)=>{let a=async()=>{await(await i())()};if(t.value){let e=matchMedia(t.value);e.matches?a():e.addEventListener(\"change\",a,{once:!0})}};(self.Astro||(self.Astro={})).media=s;window.dispatchEvent(new Event(\"astro:media\"));})();";
7
7
  export default _default;
@@ -1,4 +1,4 @@
1
- var media_prebuilt_default = `(self.Astro=self.Astro||{}).media=(s,a)=>{const t=async()=>{await(await s())()};if(a.value){const e=matchMedia(a.value);e.matches?t():e.addEventListener("change",t,{once:!0})}},window.dispatchEvent(new Event("astro:media"));`;
1
+ var media_prebuilt_default = `(()=>{var s=(i,t)=>{let a=async()=>{await(await i())()};if(t.value){let e=matchMedia(t.value);e.matches?a():e.addEventListener("change",a,{once:!0})}};(self.Astro||(self.Astro={})).media=s;window.dispatchEvent(new Event("astro:media"));})();`;
2
2
  export {
3
3
  media_prebuilt_default as default
4
4
  };
@@ -0,0 +1,6 @@
1
+ import type { ClientDirective } from '../../@types/astro';
2
+ /**
3
+ * Hydrate this component only on the client
4
+ */
5
+ declare const onlyDirective: ClientDirective;
6
+ export default onlyDirective;
@@ -1,7 +1,8 @@
1
- (self.Astro = self.Astro || {}).only = (getHydrateCallback) => {
2
- (async () => {
3
- let hydrate = await getHydrateCallback();
4
- await hydrate();
5
- })();
1
+ const onlyDirective = async (load) => {
2
+ const hydrate = await load();
3
+ await hydrate();
4
+ };
5
+ var only_default = onlyDirective;
6
+ export {
7
+ only_default as default
6
8
  };
7
- window.dispatchEvent(new Event("astro:only"));
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro=self.Astro||{}).only=t=>{(async()=>await(await t())())()},window.dispatchEvent(new Event(\"astro:only\"));";
6
+ declare const _default: "(()=>{var e=async t=>{await(await t())()};(self.Astro||(self.Astro={})).only=e;window.dispatchEvent(new Event(\"astro:only\"));})();";
7
7
  export default _default;
@@ -1,4 +1,4 @@
1
- var only_prebuilt_default = `(self.Astro=self.Astro||{}).only=t=>{(async()=>await(await t())())()},window.dispatchEvent(new Event("astro:only"));`;
1
+ var only_prebuilt_default = `(()=>{var e=async t=>{await(await t())()};(self.Astro||(self.Astro={})).only=e;window.dispatchEvent(new Event("astro:only"));})();`;
2
2
  export {
3
3
  only_prebuilt_default as default
4
4
  };
@@ -0,0 +1,8 @@
1
+ import type { ClientDirective } from '../../@types/astro';
2
+ /**
3
+ * Hydrate this component when one of it's children becomes visible
4
+ * We target the children because `astro-island` is set to `display: contents`
5
+ * which doesn't work with IntersectionObserver
6
+ */
7
+ declare const visibleDirective: ClientDirective;
8
+ export default visibleDirective;
@@ -1,9 +1,9 @@
1
- (self.Astro = self.Astro || {}).visible = (getHydrateCallback, _opts, root) => {
1
+ const visibleDirective = (load, _options, el) => {
2
2
  const cb = async () => {
3
- let hydrate = await getHydrateCallback();
3
+ const hydrate = await load();
4
4
  await hydrate();
5
5
  };
6
- let io = new IntersectionObserver((entries) => {
6
+ const io = new IntersectionObserver((entries) => {
7
7
  for (const entry of entries) {
8
8
  if (!entry.isIntersecting)
9
9
  continue;
@@ -12,9 +12,12 @@
12
12
  break;
13
13
  }
14
14
  });
15
- for (let i = 0; i < root.children.length; i++) {
16
- const child = root.children[i];
15
+ for (let i = 0; i < el.children.length; i++) {
16
+ const child = el.children[i];
17
17
  io.observe(child);
18
18
  }
19
19
  };
20
- window.dispatchEvent(new Event("astro:visible"));
20
+ var visible_default = visibleDirective;
21
+ export {
22
+ visible_default as default
23
+ };
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "(self.Astro=self.Astro||{}).visible=(s,c,n)=>{const r=async()=>{await(await s())()};let i=new IntersectionObserver(e=>{for(const t of e)if(t.isIntersecting){i.disconnect(),r();break}});for(let e=0;e<n.children.length;e++){const t=n.children[e];i.observe(t)}},window.dispatchEvent(new Event(\"astro:visible\"));";
6
+ declare const _default: "(()=>{var r=(s,c,i)=>{let o=async()=>{await(await s())()},n=new IntersectionObserver(e=>{for(let t of e)if(t.isIntersecting){n.disconnect(),o();break}});for(let e=0;e<i.children.length;e++){let t=i.children[e];n.observe(t)}};(self.Astro||(self.Astro={})).visible=r;window.dispatchEvent(new Event(\"astro:visible\"));})();";
7
7
  export default _default;
@@ -1,4 +1,4 @@
1
- var visible_prebuilt_default = `(self.Astro=self.Astro||{}).visible=(s,c,n)=>{const r=async()=>{await(await s())()};let i=new IntersectionObserver(e=>{for(const t of e)if(t.isIntersecting){i.disconnect(),r();break}});for(let e=0;e<n.children.length;e++){const t=n.children[e];i.observe(t)}},window.dispatchEvent(new Event("astro:visible"));`;
1
+ var visible_prebuilt_default = `(()=>{var r=(s,c,i)=>{let o=async()=>{await(await s())()},n=new IntersectionObserver(e=>{for(let t of e)if(t.isIntersecting){n.disconnect(),o();break}});for(let e=0;e<i.children.length;e++){let t=i.children[e];n.observe(t)}};(self.Astro||(self.Astro={})).visible=r;window.dispatchEvent(new Event("astro:visible"));})();`;
2
2
  export {
3
3
  visible_prebuilt_default as default
4
4
  };
@@ -3,5 +3,5 @@
3
3
  * Do not edit this directly, but instead edit that file and rerun the prebuild
4
4
  * to generate this file.
5
5
  */
6
- declare const _default: "var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(JSON.parse(t)),9:t=>new Uint16Array(JSON.parse(t)),10:t=>new Uint32Array(JSON.parse(t))},o=(t,s)=>{if(t===\"\"||!Array.isArray(s))return s;const[e,n]=s;return e in c?c[e](n):void 0};customElements.get(\"astro-island\")||customElements.define(\"astro-island\",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest(\"astro-island[ssr]\"))return;const s=this.querySelectorAll(\"astro-slot\"),e={},n=this.querySelectorAll(\"template[data-astro-template]\");for(const r of n){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute(\"data-astro-template\")||\"default\"]=r.innerHTML,r.remove())}for(const r of s){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute(\"name\")||\"default\"]=r.innerHTML)}const a=this.hasAttribute(\"props\")?JSON.parse(this.getAttribute(\"props\"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute(\"client\")}),this.removeAttribute(\"ssr\"),window.removeEventListener(\"astro:hydrate\",this.hydrate),window.dispatchEvent(new CustomEvent(\"astro:hydrate\"))}}connectedCallback(){!this.hasAttribute(\"await-children\")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((s,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener(\"astro:hydrate\",this.hydrate);let s=this.getAttribute(\"before-hydration-url\");s&&await import(s),this.start()}start(){const s=JSON.parse(this.getAttribute(\"opts\")),e=this.getAttribute(\"client\");if(Astro[e]===void 0){window.addEventListener(`astro:${e}`,()=>this.start(),{once:!0});return}Astro[e](async()=>{const n=this.getAttribute(\"renderer-url\"),[a,{default:r}]=await Promise.all([import(this.getAttribute(\"component-url\")),n?import(n):()=>()=>{}]),i=this.getAttribute(\"component-export\")||\"default\";if(!i.includes(\".\"))this.Component=a[i];else{this.Component=a;for(const d of i.split(\".\"))this.Component=this.Component[d]}return this.hydrator=r,this.hydrate},s,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=[\"props\"],l))}";
6
+ declare const _default: "(()=>{var l;{let c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(JSON.parse(t)),9:t=>new Uint16Array(JSON.parse(t)),10:t=>new Uint32Array(JSON.parse(t))},o=(t,s)=>{if(t===\"\"||!Array.isArray(s))return s;let[e,n]=s;return e in c?c[e](n):void 0};customElements.get(\"astro-island\")||customElements.define(\"astro-island\",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest(\"astro-island[ssr]\"))return;let s=this.querySelectorAll(\"astro-slot\"),e={},n=this.querySelectorAll(\"template[data-astro-template]\");for(let r of n){let i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute(\"data-astro-template\")||\"default\"]=r.innerHTML,r.remove())}for(let r of s){let i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute(\"name\")||\"default\"]=r.innerHTML)}let a=this.hasAttribute(\"props\")?JSON.parse(this.getAttribute(\"props\"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute(\"client\")}),this.removeAttribute(\"ssr\"),window.removeEventListener(\"astro:hydrate\",this.hydrate),window.dispatchEvent(new CustomEvent(\"astro:hydrate\"))}}connectedCallback(){!this.hasAttribute(\"await-children\")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((s,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener(\"astro:hydrate\",this.hydrate);let s=this.getAttribute(\"before-hydration-url\");s&&await import(s),this.start()}start(){let s=JSON.parse(this.getAttribute(\"opts\")),e=this.getAttribute(\"client\");if(Astro[e]===void 0){window.addEventListener(`astro:${e}`,()=>this.start(),{once:!0});return}Astro[e](async()=>{let n=this.getAttribute(\"renderer-url\"),[a,{default:r}]=await Promise.all([import(this.getAttribute(\"component-url\")),n?import(n):()=>()=>{}]),i=this.getAttribute(\"component-export\")||\"default\";if(!i.includes(\".\"))this.Component=a[i];else{this.Component=a;for(let d of i.split(\".\"))this.Component=this.Component[d]}return this.hydrator=r,this.hydrate},s,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=[\"props\"],l))}})();";
7
7
  export default _default;
@@ -1,4 +1,4 @@
1
- var astro_island_prebuilt_default = `var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(JSON.parse(t)),9:t=>new Uint16Array(JSON.parse(t)),10:t=>new Uint32Array(JSON.parse(t))},o=(t,s)=>{if(t===""||!Array.isArray(s))return s;const[e,n]=s;return e in c?c[e](n):void 0};customElements.get("astro-island")||customElements.define("astro-island",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest("astro-island[ssr]"))return;const s=this.querySelectorAll("astro-slot"),e={},n=this.querySelectorAll("template[data-astro-template]");for(const r of n){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute("data-astro-template")||"default"]=r.innerHTML,r.remove())}for(const r of s){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute("name")||"default"]=r.innerHTML)}const a=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),window.removeEventListener("astro:hydrate",this.hydrate),window.dispatchEvent(new CustomEvent("astro:hydrate"))}}connectedCallback(){!this.hasAttribute("await-children")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((s,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener("astro:hydrate",this.hydrate);let s=this.getAttribute("before-hydration-url");s&&await import(s),this.start()}start(){const s=JSON.parse(this.getAttribute("opts")),e=this.getAttribute("client");if(Astro[e]===void 0){window.addEventListener(\`astro:\${e}\`,()=>this.start(),{once:!0});return}Astro[e](async()=>{const n=this.getAttribute("renderer-url"),[a,{default:r}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),i=this.getAttribute("component-export")||"default";if(!i.includes("."))this.Component=a[i];else{this.Component=a;for(const d of i.split("."))this.Component=this.Component[d]}return this.hydrator=r,this.hydrate},s,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=["props"],l))}`;
1
+ var astro_island_prebuilt_default = `(()=>{var l;{let c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(JSON.parse(t)),9:t=>new Uint16Array(JSON.parse(t)),10:t=>new Uint32Array(JSON.parse(t))},o=(t,s)=>{if(t===""||!Array.isArray(s))return s;let[e,n]=s;return e in c?c[e](n):void 0};customElements.get("astro-island")||customElements.define("astro-island",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest("astro-island[ssr]"))return;let s=this.querySelectorAll("astro-slot"),e={},n=this.querySelectorAll("template[data-astro-template]");for(let r of n){let i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute("data-astro-template")||"default"]=r.innerHTML,r.remove())}for(let r of s){let i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute("name")||"default"]=r.innerHTML)}let a=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),window.removeEventListener("astro:hydrate",this.hydrate),window.dispatchEvent(new CustomEvent("astro:hydrate"))}}connectedCallback(){!this.hasAttribute("await-children")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((s,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener("astro:hydrate",this.hydrate);let s=this.getAttribute("before-hydration-url");s&&await import(s),this.start()}start(){let s=JSON.parse(this.getAttribute("opts")),e=this.getAttribute("client");if(Astro[e]===void 0){window.addEventListener(\`astro:\${e}\`,()=>this.start(),{once:!0});return}Astro[e](async()=>{let n=this.getAttribute("renderer-url"),[a,{default:r}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),i=this.getAttribute("component-export")||"default";if(!i.includes("."))this.Component=a[i];else{this.Component=a;for(let d of i.split("."))this.Component=this.Component[d]}return this.hydrator=r,this.hydrate},s,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=["props"],l))}})();`;
2
2
  export {
3
3
  astro_island_prebuilt_default as default
4
4
  };
@@ -17,7 +17,7 @@ async function renderEndpoint(mod, context, ssr) {
17
17
  const handler = getHandlerFromModule(mod, chosenMethod);
18
18
  if (!ssr && ssr === false && chosenMethod && chosenMethod !== "get") {
19
19
  console.warn(`
20
- ${chosenMethod} requests are not available when building a static site. Update your config to output: 'server' to handle ${chosenMethod} requests.`);
20
+ ${chosenMethod} requests are not available when building a static site. Update your config to \`output: 'server'\` or \`output: 'hybrid'\` with an \`export const prerender = false\` to handle ${chosenMethod} requests.`);
21
21
  }
22
22
  if (!handler || typeof handler !== "function") {
23
23
  let response = new Response(null, {
@@ -1,5 +1,4 @@
1
1
  import type { AstroComponentMetadata, SSRElement, SSRLoadedRenderer, SSRResult } from '../../@types/astro';
2
- export declare const HydrationDirectiveProps: Set<string>;
3
2
  export interface HydrationMetadata {
4
3
  directive: string;
5
4
  value: string;
@@ -13,7 +12,7 @@ interface ExtractedProps {
13
12
  hydration: HydrationMetadata | null;
14
13
  props: Record<string | number | symbol, any>;
15
14
  }
16
- export declare function extractDirectives(displayName: string, inputProps: Record<string | number | symbol, any>): ExtractedProps;
15
+ export declare function extractDirectives(inputProps: Record<string | number | symbol, any>, clientDirectives: SSRResult['_metadata']['clientDirectives']): ExtractedProps;
17
16
  interface HydrateScriptOptions {
18
17
  renderer: SSRLoadedRenderer;
19
18
  result: SSRResult;
@@ -2,10 +2,7 @@ import { AstroError, AstroErrorData } from "../../core/errors/index.js";
2
2
  import { escapeHTML } from "./escape.js";
3
3
  import { serializeProps } from "./serialize.js";
4
4
  import { serializeListValue } from "./util.js";
5
- const HydrationDirectivesRaw = ["load", "idle", "media", "visible", "only"];
6
- const HydrationDirectives = new Set(HydrationDirectivesRaw);
7
- const HydrationDirectiveProps = new Set(HydrationDirectivesRaw.map((n) => `client:${n}`));
8
- function extractDirectives(displayName, inputProps) {
5
+ function extractDirectives(inputProps, clientDirectives) {
9
6
  let extracted = {
10
7
  isPage: false,
11
8
  hydration: null,
@@ -44,11 +41,10 @@ function extractDirectives(displayName, inputProps) {
44
41
  default: {
45
42
  extracted.hydration.directive = key.split(":")[1];
46
43
  extracted.hydration.value = value;
47
- if (!HydrationDirectives.has(extracted.hydration.directive)) {
44
+ if (!clientDirectives.has(extracted.hydration.directive)) {
45
+ const hydrationMethods = Array.from(clientDirectives.keys()).map((d) => `client:${d}`).join(", ");
48
46
  throw new Error(
49
- `Error: invalid hydration directive "${key}". Supported hydration methods: ${Array.from(
50
- HydrationDirectiveProps
51
- ).join(", ")}`
47
+ `Error: invalid hydration directive "${key}". Supported hydration methods: ${hydrationMethods}`
52
48
  );
53
49
  }
54
50
  if (extracted.hydration.directive === "media" && typeof extracted.hydration.value !== "string") {
@@ -111,7 +107,6 @@ async function generateHydrateScript(scriptOptions, metadata) {
111
107
  return island;
112
108
  }
113
109
  export {
114
- HydrationDirectiveProps,
115
110
  extractDirectives,
116
111
  generateHydrateScript
117
112
  };
@@ -1,5 +1,4 @@
1
1
  var _a;
2
- import { HydrationDirectiveProps } from "../../hydration.js";
3
2
  import { isPromise } from "../../util.js";
4
3
  import { renderChild } from "../any.js";
5
4
  import { isAPropagatingComponent } from "./factory.js";
@@ -40,7 +39,7 @@ _a = astroComponentInstanceSym;
40
39
  function validateComponentProps(props, displayName) {
41
40
  if (props != null) {
42
41
  for (const prop of Object.keys(props)) {
43
- if (HydrationDirectiveProps.has(prop)) {
42
+ if (prop.startsWith("client:")) {
44
43
  console.warn(
45
44
  `You are attempting to render <${displayName} ${prop} />, but ${displayName} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`
46
45
  );
@@ -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, undefined>;
10
+ [Symbol.asyncIterator](): AsyncGenerator<any, void, unknown>;
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,6 +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
6
  const renderTemplateResultSym = Symbol.for("astro.renderTemplateResult");
6
7
  class RenderTemplateResult {
7
8
  constructor(htmlParts, expressions) {
@@ -22,11 +23,18 @@ class RenderTemplateResult {
22
23
  }
23
24
  async *[(_a = renderTemplateResultSym, Symbol.asyncIterator)]() {
24
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);
25
33
  for (let i = 0; i < htmlParts.length; i++) {
26
34
  const html = htmlParts[i];
27
- const expression = expressions[i];
35
+ const iterable = iterables[i];
28
36
  yield markHTMLString(html);
29
- yield* renderChild(expression);
37
+ yield* iterable;
30
38
  }
31
39
  }
32
40
  }
@@ -20,7 +20,7 @@ function stringifyChunk(result, chunk) {
20
20
  let needsDirectiveScript = hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
21
21
  let prescriptType = needsHydrationScript ? "both" : needsDirectiveScript ? "directive" : null;
22
22
  if (prescriptType) {
23
- let prescripts = getPrescripts(prescriptType, hydration.directive);
23
+ let prescripts = getPrescripts(result, prescriptType, hydration.directive);
24
24
  return markHTMLString(prescripts);
25
25
  } else {
26
26
  return "";
@@ -43,17 +43,26 @@ function isFragmentComponent(Component) {
43
43
  function isHTMLComponent(Component) {
44
44
  return Component && typeof Component === "object" && Component["astro:html"];
45
45
  }
46
+ const ASTRO_SLOT_EXP = /\<\/?astro-slot\b[^>]*>/g;
47
+ const ASTRO_STATIC_SLOT_EXP = /\<\/?astro-static-slot\b[^>]*>/g;
48
+ function removeStaticAstroSlot(html, supportsAstroStaticSlot) {
49
+ const exp = supportsAstroStaticSlot ? ASTRO_STATIC_SLOT_EXP : ASTRO_SLOT_EXP;
50
+ return html.replace(exp, "");
51
+ }
46
52
  async function renderFrameworkComponent(result, displayName, Component, _props, slots = {}) {
47
- var _a, _b;
53
+ var _a, _b, _c;
48
54
  if (!Component && !_props["client:only"]) {
49
55
  throw new Error(
50
56
  `Unable to render ${displayName} because it is ${Component}!
51
57
  Did you forget to import the component or is it possible there is a typo?`
52
58
  );
53
59
  }
54
- const { renderers } = result._metadata;
55
- const metadata = { displayName };
56
- const { hydration, isPage, props } = extractDirectives(displayName, _props);
60
+ const { renderers, clientDirectives } = result._metadata;
61
+ const metadata = {
62
+ astroStaticSlot: true,
63
+ displayName
64
+ };
65
+ const { hydration, isPage, props } = extractDirectives(_props, clientDirectives);
57
66
  let html = "";
58
67
  let attrs = void 0;
59
68
  if (hydration) {
@@ -202,13 +211,16 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
202
211
  }
203
212
  if (!hydration) {
204
213
  return async function* () {
214
+ var _a2;
205
215
  if (slotInstructions) {
206
216
  yield* slotInstructions;
207
217
  }
208
218
  if (isPage || (renderer == null ? void 0 : renderer.name) === "astro:jsx") {
209
219
  yield html;
210
220
  } else if (html && html.length > 0) {
211
- yield markHTMLString(html.replace(/\<\/?astro-slot\b[^>]*>/g, ""));
221
+ yield markHTMLString(
222
+ removeStaticAstroSlot(html, ((_a2 = renderer == null ? void 0 : renderer.ssr) == null ? void 0 : _a2.supportsAstroStaticSlot) ?? false)
223
+ );
212
224
  } else {
213
225
  yield "";
214
226
  }
@@ -230,7 +242,9 @@ ${serializeProps(
230
242
  if (html) {
231
243
  if (Object.keys(children).length > 0) {
232
244
  for (const key of Object.keys(children)) {
233
- if (!html.includes(key === "default" ? `<astro-slot>` : `<astro-slot name="${key}">`)) {
245
+ let tagName = ((_c = renderer == null ? void 0 : renderer.ssr) == null ? void 0 : _c.supportsAstroStaticSlot) ? !!metadata.hydrate ? "astro-slot" : "astro-static-slot" : "astro-slot";
246
+ let expectedHTML = key === "default" ? `<${tagName}>` : `<${tagName} name="${key}">`;
247
+ if (!html.includes(expectedHTML)) {
234
248
  unrenderedSlots.push(key);
235
249
  }
236
250
  }
@@ -116,6 +116,11 @@ async function renderPage(result, componentFactory, props, children, streaming,
116
116
  }
117
117
  }
118
118
  }
119
+ if (chunk instanceof Response) {
120
+ throw new AstroError({
121
+ ...AstroErrorData.ResponseSentError
122
+ });
123
+ }
119
124
  const bytes = chunkToByteArray(result, chunk);
120
125
  controller.enqueue(bytes);
121
126
  i++;
@@ -6,3 +6,15 @@ 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
+ export declare class EagerAsyncIterableIterator {
10
+ #private;
11
+ constructor(iterable: AsyncIterable<any>);
12
+ /**
13
+ * Starts to eagerly fetch the inner iterator and cache the results.
14
+ * Note: This might not be called after next() has been called once, e.g. the iterator is started
15
+ */
16
+ buffer(): Promise<void>;
17
+ next(): Promise<IteratorResult<any, any>>;
18
+ isStarted(): boolean;
19
+ [Symbol.asyncIterator](): this;
20
+ }
@@ -22,7 +22,10 @@ const toStyleString = (obj) => Object.entries(obj).map(([k, v]) => {
22
22
  function defineScriptVars(vars) {
23
23
  let output = "";
24
24
  for (const [key, value] of Object.entries(vars)) {
25
- output += `const ${toIdent(key)} = ${JSON.stringify(value)};
25
+ output += `const ${toIdent(key)} = ${JSON.stringify(value).replace(
26
+ /<\/script>/g,
27
+ "\\x3C/script>"
28
+ )};
26
29
  `;
27
30
  }
28
31
  return markHTMLString(output);
@@ -92,7 +95,92 @@ function renderElement(name, { props: _props, children = "" }, shouldEscape = tr
92
95
  }
93
96
  return `<${name}${internalSpreadAttributes(props, shouldEscape)}>${children}</${name}>`;
94
97
  }
98
+ class EagerAsyncIterableIterator {
99
+ #iterable;
100
+ #queue = new Queue();
101
+ #error = void 0;
102
+ #next;
103
+ /**
104
+ * Whether the proxy is running in buffering or pass-through mode
105
+ */
106
+ #isBuffering = false;
107
+ #gen = void 0;
108
+ #isStarted = false;
109
+ constructor(iterable) {
110
+ this.#iterable = iterable;
111
+ }
112
+ /**
113
+ * Starts to eagerly fetch the inner iterator and cache the results.
114
+ * Note: This might not be called after next() has been called once, e.g. the iterator is started
115
+ */
116
+ async buffer() {
117
+ if (this.#gen) {
118
+ throw new Error("Cannot not switch from non-buffer to buffer mode");
119
+ }
120
+ this.#isBuffering = true;
121
+ this.#isStarted = true;
122
+ this.#gen = this.#iterable[Symbol.asyncIterator]();
123
+ let value = void 0;
124
+ do {
125
+ this.#next = this.#gen.next();
126
+ try {
127
+ value = await this.#next;
128
+ this.#queue.push(value);
129
+ } catch (e) {
130
+ this.#error = e;
131
+ }
132
+ } while (value && !value.done);
133
+ }
134
+ async next() {
135
+ if (this.#error) {
136
+ throw this.#error;
137
+ }
138
+ if (!this.#isBuffering) {
139
+ if (!this.#gen) {
140
+ this.#isStarted = true;
141
+ this.#gen = this.#iterable[Symbol.asyncIterator]();
142
+ }
143
+ return await this.#gen.next();
144
+ }
145
+ if (!this.#queue.isEmpty()) {
146
+ return this.#queue.shift();
147
+ }
148
+ await this.#next;
149
+ return this.#queue.shift();
150
+ }
151
+ isStarted() {
152
+ return this.#isStarted;
153
+ }
154
+ [Symbol.asyncIterator]() {
155
+ return this;
156
+ }
157
+ }
158
+ class Queue {
159
+ constructor() {
160
+ this.head = void 0;
161
+ this.tail = void 0;
162
+ }
163
+ push(item) {
164
+ if (this.head === void 0) {
165
+ this.head = { item };
166
+ this.tail = this.head;
167
+ } else {
168
+ this.tail.next = { item };
169
+ this.tail = this.tail.next;
170
+ }
171
+ }
172
+ isEmpty() {
173
+ return this.head === void 0;
174
+ }
175
+ shift() {
176
+ var _a, _b;
177
+ const val = (_a = this.head) == null ? void 0 : _a.item;
178
+ this.head = (_b = this.head) == null ? void 0 : _b.next;
179
+ return val;
180
+ }
181
+ }
95
182
  export {
183
+ EagerAsyncIterableIterator,
96
184
  addAttribute,
97
185
  defineScriptVars,
98
186
  formatList,
@@ -1,6 +1,5 @@
1
1
  import type { SSRResult } from '../../@types/astro';
2
2
  export declare function determineIfNeedsHydrationScript(result: SSRResult): boolean;
3
- export declare const hydrationScripts: Record<string, string>;
4
3
  export declare function determinesIfNeedsDirectiveScript(result: SSRResult, directive: string): boolean;
5
4
  export type PrescriptType = null | 'both' | 'directive';
6
- export declare function getPrescripts(type: PrescriptType, directive: string): string;
5
+ export declare function getPrescripts(result: SSRResult, type: PrescriptType, directive: string): string;
@@ -1,22 +1,11 @@
1
- import idlePrebuilt from "../client/idle.prebuilt.js";
2
- import loadPrebuilt from "../client/load.prebuilt.js";
3
- import mediaPrebuilt from "../client/media.prebuilt.js";
4
- import onlyPrebuilt from "../client/only.prebuilt.js";
5
- import visiblePrebuilt from "../client/visible.prebuilt.js";
6
1
  import islandScript from "./astro-island.prebuilt.js";
2
+ const ISLAND_STYLES = `<style>astro-island,astro-slot{display:contents}</style>`;
7
3
  function determineIfNeedsHydrationScript(result) {
8
4
  if (result._metadata.hasHydrationScript) {
9
5
  return false;
10
6
  }
11
7
  return result._metadata.hasHydrationScript = true;
12
8
  }
13
- const hydrationScripts = {
14
- idle: idlePrebuilt,
15
- load: loadPrebuilt,
16
- only: onlyPrebuilt,
17
- media: mediaPrebuilt,
18
- visible: visiblePrebuilt
19
- };
20
9
  function determinesIfNeedsDirectiveScript(result, directive) {
21
10
  if (result._metadata.hasDirectives.has(directive)) {
22
11
  return false;
@@ -24,25 +13,28 @@ function determinesIfNeedsDirectiveScript(result, directive) {
24
13
  result._metadata.hasDirectives.add(directive);
25
14
  return true;
26
15
  }
27
- function getDirectiveScriptText(directive) {
28
- if (!(directive in hydrationScripts)) {
16
+ function getDirectiveScriptText(result, directive) {
17
+ const clientDirectives = result._metadata.clientDirectives;
18
+ const clientDirective = clientDirectives.get(directive);
19
+ if (!clientDirective) {
29
20
  throw new Error(`Unknown directive: ${directive}`);
30
21
  }
31
- const directiveScriptText = hydrationScripts[directive];
32
- return directiveScriptText;
22
+ return clientDirective;
33
23
  }
34
- function getPrescripts(type, directive) {
24
+ function getPrescripts(result, type, directive) {
35
25
  switch (type) {
36
26
  case "both":
37
- return `<style>astro-island,astro-slot{display:contents}</style><script>${getDirectiveScriptText(directive) + islandScript}</script>`;
27
+ return `${ISLAND_STYLES}<script>${getDirectiveScriptText(
28
+ result,
29
+ directive
30
+ )};${islandScript}</script>`;
38
31
  case "directive":
39
- return `<script>${getDirectiveScriptText(directive)}</script>`;
32
+ return `<script>${getDirectiveScriptText(result, directive)}</script>`;
40
33
  }
41
34
  return "";
42
35
  }
43
36
  export {
44
37
  determineIfNeedsHydrationScript,
45
38
  determinesIfNeedsDirectiveScript,
46
- getPrescripts,
47
- hydrationScripts
39
+ getPrescripts
48
40
  };
@@ -4,6 +4,7 @@ import { error } from "../core/logger/core.js";
4
4
  import * as msg from "../core/messages.js";
5
5
  import { removeTrailingForwardSlash } from "../core/path.js";
6
6
  import { eventError, telemetry } from "../events/index.js";
7
+ import { isHybridOutput } from "../prerender/utils.js";
7
8
  import { runWithErrorHandling } from "./controller.js";
8
9
  import { handle500Response } from "./response.js";
9
10
  import { handleRoute, matchRoute } from "./route.js";
@@ -11,7 +12,7 @@ async function handleRequest(env, manifest, controller, req, res) {
11
12
  const { settings, loader: moduleLoader } = env;
12
13
  const { config } = settings;
13
14
  const origin = `${moduleLoader.isHttps() ? "https" : "http"}://${req.headers.host}`;
14
- const buildingToSSR = config.output === "server";
15
+ const buildingToSSR = config.output === "server" || isHybridOutput(config);
15
16
  const url = new URL(origin + req.url);
16
17
  let pathname;
17
18
  if (config.trailingSlash === "never" && !req.url) {