astro 1.0.0-beta.60 → 1.0.0-beta.63

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.
@@ -20,7 +20,7 @@ var __privateMethod = (obj, member, method) => {
20
20
  __accessCheck(obj, member, "access private method");
21
21
  return method;
22
22
  };
23
- var _manifest, _manifestData, _routeDataToRouteInfo, _routeCache, _encoder, _logging, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
23
+ var _manifest, _manifestData, _routeDataToRouteInfo, _routeCache, _encoder, _logging, _streaming, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
24
24
  import mime from "mime";
25
25
  import { call as callEndpoint } from "../endpoint/index.js";
26
26
  import { consoleLogDestination } from "../logger/console.js";
@@ -36,7 +36,7 @@ import { deserializeManifest } from "./common.js";
36
36
  const pagesVirtualModuleId = "@astrojs-pages-virtual-entry";
37
37
  const resolvedPagesVirtualModuleId = "\0" + pagesVirtualModuleId;
38
38
  class App {
39
- constructor(manifest) {
39
+ constructor(manifest, streaming = true) {
40
40
  __privateAdd(this, _renderPage);
41
41
  __privateAdd(this, _callEndpoint);
42
42
  __privateAdd(this, _manifest, void 0);
@@ -48,12 +48,14 @@ class App {
48
48
  dest: consoleLogDestination,
49
49
  level: "info"
50
50
  });
51
+ __privateAdd(this, _streaming, void 0);
51
52
  __privateSet(this, _manifest, manifest);
52
53
  __privateSet(this, _manifestData, {
53
54
  routes: manifest.routes.map((route) => route.routeData)
54
55
  });
55
56
  __privateSet(this, _routeDataToRouteInfo, new Map(manifest.routes.map((route) => [route.routeData, route])));
56
57
  __privateSet(this, _routeCache, new RouteCache(__privateGet(this, _logging)));
58
+ __privateSet(this, _streaming, streaming);
57
59
  }
58
60
  match(request) {
59
61
  const url = new URL(request.url);
@@ -85,6 +87,7 @@ _routeDataToRouteInfo = new WeakMap();
85
87
  _routeCache = new WeakMap();
86
88
  _encoder = new WeakMap();
87
89
  _logging = new WeakMap();
90
+ _streaming = new WeakMap();
88
91
  _renderPage = new WeakSet();
89
92
  renderPage_fn = async function(request, routeData, mod) {
90
93
  const url = new URL(request.url);
@@ -125,7 +128,8 @@ renderPage_fn = async function(request, routeData, mod) {
125
128
  routeCache: __privateGet(this, _routeCache),
126
129
  site: __privateGet(this, _manifest).site,
127
130
  ssr: true,
128
- request
131
+ request,
132
+ streaming: __privateGet(this, _streaming)
129
133
  });
130
134
  return response;
131
135
  };
@@ -145,7 +145,8 @@ async function generatePath(pathname, opts, gopts) {
145
145
  route: pageData.route,
146
146
  routeCache,
147
147
  site: astroConfig.site ? new URL(astroConfig.base, astroConfig.site).toString() : astroConfig.site,
148
- ssr
148
+ ssr,
149
+ streaming: true
149
150
  };
150
151
  let body;
151
152
  if (pageData.route.type === "endpoint") {
@@ -20,7 +20,8 @@ const ASTRO_CONFIG_DEFAULTS = {
20
20
  build: { format: "directory" },
21
21
  server: {
22
22
  host: false,
23
- port: 3e3
23
+ port: 3e3,
24
+ streaming: true
24
25
  },
25
26
  style: { postcss: { options: {}, plugins: [] } },
26
27
  integrations: [],
@@ -176,7 +177,8 @@ See https://astro.build/config for more information.`);
176
177
  outDir: z.string().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
177
178
  server: z.preprocess((val) => typeof val === "function" ? val({ command: cmd === "dev" ? "dev" : "preview" }) : val, z.object({
178
179
  host: z.union([z.string(), z.boolean()]).optional().default(ASTRO_CONFIG_DEFAULTS.server.host),
179
- port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port)
180
+ port: z.number().optional().default(ASTRO_CONFIG_DEFAULTS.server.port),
181
+ streaming: z.boolean().optional().default(true)
180
182
  }).optional().default({})),
181
183
  style: z.object({
182
184
  postcss: z.preprocess((val) => resolvePostcssConfig(val, fileProtocolRoot), z.object({
@@ -47,7 +47,7 @@ async function dev(config, options) {
47
47
  site,
48
48
  https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
49
49
  }));
50
- const currentVersion = "1.0.0-beta.60";
50
+ const currentVersion = "1.0.0-beta.63";
51
51
  if (currentVersion.includes("-")) {
52
52
  warn(options.logging, null, msg.prerelease({ currentVersion }));
53
53
  }
@@ -47,7 +47,7 @@ function devStart({
47
47
  https,
48
48
  site
49
49
  }) {
50
- const version = "1.0.0-beta.60";
50
+ const version = "1.0.0-beta.63";
51
51
  const rootPath = site ? site.pathname : "/";
52
52
  const localPrefix = `${dim("\u2503")} Local `;
53
53
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -206,7 +206,7 @@ function printHelp({
206
206
  };
207
207
  let message = [];
208
208
  if (headline) {
209
- message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.60"}`)} ${headline}`);
209
+ message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.63"}`)} ${headline}`);
210
210
  }
211
211
  if (usage) {
212
212
  message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`);
@@ -48,7 +48,8 @@ async function render(opts) {
48
48
  route,
49
49
  routeCache,
50
50
  site,
51
- ssr
51
+ ssr,
52
+ streaming
52
53
  } = opts;
53
54
  const paramsAndPropsRes = await getParamsAndProps({
54
55
  logging,
@@ -79,12 +80,13 @@ async function render(opts) {
79
80
  request,
80
81
  site,
81
82
  scripts,
82
- ssr
83
+ ssr,
84
+ streaming
83
85
  });
84
86
  if (typeof mod.components === "object") {
85
87
  Object.assign(pageProps, { components: mod.components });
86
88
  }
87
- return await renderPage(result, Component, pageProps, null);
89
+ return await renderPage(result, Component, pageProps, null, streaming);
88
90
  }
89
91
  export {
90
92
  GetParamsAndPropsError,
@@ -108,7 +108,8 @@ async function render(renderers, mod, ssrOpts) {
108
108
  route,
109
109
  routeCache,
110
110
  site: astroConfig.site ? new URL(astroConfig.base, astroConfig.site).toString() : void 0,
111
- ssr: isBuildingToSSR(astroConfig)
111
+ ssr: isBuildingToSSR(astroConfig),
112
+ streaming: true
112
113
  });
113
114
  return response;
114
115
  }
@@ -99,7 +99,11 @@ function createResult(args) {
99
99
  const url = new URL(request.url);
100
100
  const canonicalURL = createCanonicalURL("." + pathname, site ?? url.origin, paginated);
101
101
  const headers = new Headers();
102
- headers.set("Transfer-Encoding", "chunked");
102
+ if (args.streaming) {
103
+ headers.set("Transfer-Encoding", "chunked");
104
+ } else {
105
+ headers.set("Content-Type", "text/html");
106
+ }
103
107
  const response = {
104
108
  status: 200,
105
109
  statusText: "OK",
package/dist/core/util.js CHANGED
@@ -5,7 +5,7 @@ import resolve from "resolve";
5
5
  import slash from "slash";
6
6
  import { fileURLToPath, pathToFileURL } from "url";
7
7
  import { removeTrailingForwardSlash } from "./path.js";
8
- const ASTRO_VERSION = "1.0.0-beta.60";
8
+ const ASTRO_VERSION = "1.0.0-beta.63";
9
9
  function isObject(value) {
10
10
  return typeof value === "object" && value != null;
11
11
  }
@@ -1,5 +1,5 @@
1
1
  import { Fragment, markHTMLString } from "../runtime/server/index.js";
2
- const AstroJSX = Symbol("@astrojs/jsx");
2
+ const AstroJSX = "astro:jsx";
3
3
  const Empty = Symbol("empty");
4
4
  const toSlotName = (str) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
5
5
  function isVNode(vnode) {
@@ -447,7 +447,7 @@ async function renderToIterable(result, componentFactory, props, children) {
447
447
  return renderAstroComponent(Component);
448
448
  }
449
449
  const encoder = new TextEncoder();
450
- async function renderPage(result, componentFactory, props, children) {
450
+ async function renderPage(result, componentFactory, props, children, streaming) {
451
451
  let iterable;
452
452
  if (!componentFactory.isAstroComponentFactory) {
453
453
  const pageProps = { ...props ?? {}, "server:root": true };
@@ -466,28 +466,47 @@ ${await maybeRenderHead(result)}${html}`;
466
466
  }
467
467
  const factoryReturnValue = await componentFactory(result, props, children);
468
468
  if (isAstroComponent(factoryReturnValue)) {
469
- iterable = renderAstroComponent(factoryReturnValue);
470
- let stream = new ReadableStream({
471
- start(controller) {
472
- async function read() {
473
- let i = 0;
474
- for await (const chunk of iterable) {
475
- let html = chunk.toString();
476
- if (i === 0) {
477
- if (!/<!doctype html/i.test(html)) {
478
- controller.enqueue(encoder.encode("<!DOCTYPE html>\n"));
469
+ let iterable2 = renderAstroComponent(factoryReturnValue);
470
+ let init = result.response;
471
+ let headers = new Headers(init.headers);
472
+ let body;
473
+ if (streaming) {
474
+ body = new ReadableStream({
475
+ start(controller) {
476
+ async function read() {
477
+ let i = 0;
478
+ for await (const chunk of iterable2) {
479
+ let html = chunk.toString();
480
+ if (i === 0) {
481
+ if (!/<!doctype html/i.test(html)) {
482
+ controller.enqueue(encoder.encode("<!DOCTYPE html>\n"));
483
+ }
479
484
  }
485
+ controller.enqueue(encoder.encode(html));
486
+ i++;
480
487
  }
481
- controller.enqueue(encoder.encode(html));
482
- i++;
488
+ controller.close();
489
+ }
490
+ read();
491
+ }
492
+ });
493
+ } else {
494
+ body = "";
495
+ let i = 0;
496
+ for await (const chunk of iterable2) {
497
+ let html = chunk.toString();
498
+ if (i === 0) {
499
+ if (!/<!doctype html/i.test(html)) {
500
+ body += "<!DOCTYPE html>\n";
483
501
  }
484
- controller.close();
485
502
  }
486
- read();
503
+ body += chunk;
504
+ i++;
487
505
  }
488
- });
489
- let init = result.response;
490
- let response = createResponse(stream, init);
506
+ const bytes = encoder.encode(body);
507
+ headers.set("Content-Length", `${bytes.byteLength}`);
508
+ }
509
+ let response = createResponse(body, { ...init, headers });
491
510
  return response;
492
511
  } else {
493
512
  return factoryReturnValue;
@@ -59,6 +59,9 @@ function createResponseClass() {
59
59
  return StreamingCompatibleResponse;
60
60
  }
61
61
  const createResponse = isNodeJS ? (body, init) => {
62
+ if (typeof body === "string") {
63
+ return new Response(body, init);
64
+ }
62
65
  if (typeof StreamingCompatibleResponse === "undefined") {
63
66
  return new (createResponseClass())(body, init);
64
67
  }
@@ -5,7 +5,7 @@ export declare const pagesVirtualModuleId = "@astrojs-pages-virtual-entry";
5
5
  export declare const resolvedPagesVirtualModuleId: string;
6
6
  export declare class App {
7
7
  #private;
8
- constructor(manifest: Manifest);
8
+ constructor(manifest: Manifest, streaming?: boolean);
9
9
  match(request: Request): RouteData | undefined;
10
10
  render(request: Request, routeData?: RouteData): Promise<Response>;
11
11
  }
@@ -29,6 +29,7 @@ export interface RenderOptions {
29
29
  routeCache: RouteCache;
30
30
  site?: string;
31
31
  ssr: boolean;
32
+ streaming: boolean;
32
33
  request: Request;
33
34
  }
34
35
  export declare function render(opts: RenderOptions): Promise<Response>;
@@ -3,6 +3,7 @@ import type { Params, Props, SSRElement, SSRLoadedRenderer, SSRResult } from '..
3
3
  import { LogOptions } from '../logger/core.js';
4
4
  export interface CreateResultArgs {
5
5
  ssr: boolean;
6
+ streaming: boolean;
6
7
  logging: LogOptions;
7
8
  origin: string;
8
9
  markdown: MarkdownRenderingOptions;
@@ -1,5 +1,5 @@
1
1
  import { Fragment } from '../runtime/server/index.js';
2
- declare const AstroJSX: unique symbol;
2
+ declare const AstroJSX = "astro:jsx";
3
3
  interface AstroVNode {
4
4
  [AstroJSX]: boolean;
5
5
  type: string | ((...args: any) => any) | typeof Fragment;
@@ -30,7 +30,7 @@ export declare function defineScriptVars(vars: Record<any, any>): any;
30
30
  export declare function renderEndpoint(mod: EndpointHandler, request: Request, params: Params): Promise<Response | import("../../@types/astro").EndpointOutput>;
31
31
  export declare function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<string>;
32
32
  export declare function renderToIterable(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<AsyncIterable<string>>;
33
- export declare function renderPage(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<Response>;
33
+ export declare function renderPage(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any, streaming: boolean): Promise<Response>;
34
34
  export declare function renderHead(result: SSRResult): Promise<string>;
35
35
  export declare function maybeRenderHead(result: SSRResult): string | Promise<string>;
36
36
  export declare function renderAstroComponent(component: InstanceType<typeof AstroComponent>): AsyncIterable<string>;
@@ -60,6 +60,8 @@ async function writeWebResponse(res, webResponse) {
60
60
  } else if (body instanceof Readable) {
61
61
  body.pipe(res);
62
62
  return;
63
+ } else if (typeof body === "string") {
64
+ res.write(body);
63
65
  } else {
64
66
  const reader = body.getReader();
65
67
  while (true) {
@@ -136,7 +138,7 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
136
138
  const url = new URL(origin + ((_a = req.url) == null ? void 0 : _a.replace(/(index)?\.html$/, "")));
137
139
  const pathname = decodeURI(url.pathname);
138
140
  const rootRelativeUrl = pathname.substring(devRoot.length - 1);
139
- if (!buildingToSSR) {
141
+ if (!buildingToSSR && rootRelativeUrl !== "/_image") {
140
142
  const allSearchParams = Array.from(url.searchParams);
141
143
  for (const [key] of allSearchParams) {
142
144
  url.searchParams.delete(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.0.0-beta.60",
3
+ "version": "1.0.0-beta.63",
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",