diff --git a/.changeset/warm-donuts-learn.md b/.changeset/warm-donuts-learn.md new file mode 100644 index 000000000000..c676a50fc53e --- /dev/null +++ b/.changeset/warm-donuts-learn.md @@ -0,0 +1,19 @@ +--- +'astro': minor +--- + +Adds `streaming` option to the `createApp()` function in the Adapter API, mirroring the same functionality available when creating a new `App` instance + +An adapter's `createApp()` function now accepts `streaming` (defaults to `true`) as an option. HTML streaming breaks a document into chunks to send over the network and render on the page in order. This normally results in visitors seeing your HTML as fast as possible but factors such as network conditions and waiting for data fetches can block page rendering. + +HTML streaming helps with performance and generally provides a better visitor experience. In most cases, disabling streaming is not recommended. + +However, when you need to disable HTML streaming (e.g. your host only supports non-streamed HTML caching at the CDN level), you can opt out of the default behavior by passing `streaming: false` to `createApp()`: + +```ts +import { createApp } from 'astro/app/entrypoint' + +const app = createApp({ streaming: false }) +``` + +See more about [the `createApp()` function](https://v6.docs.astro.build/en/reference/adapter-reference/#createapp) in the Adapter API reference. diff --git a/packages/astro/dev-only.d.ts b/packages/astro/dev-only.d.ts index f428b7699af9..96f3a94d7924 100644 --- a/packages/astro/dev-only.d.ts +++ b/packages/astro/dev-only.d.ts @@ -79,5 +79,5 @@ declare module 'virtual:astro:dev-css-all' { } declare module 'virtual:astro:app' { - export function createApp(): import('./src/core/app/base.js').BaseApp; + export const createApp: import('./src/core/app/types.js').CreateApp; } diff --git a/packages/astro/src/core/app/entrypoints/virtual/dev.ts b/packages/astro/src/core/app/entrypoints/virtual/dev.ts index 53bf243624c4..31eafcc72822 100644 --- a/packages/astro/src/core/app/entrypoints/virtual/dev.ts +++ b/packages/astro/src/core/app/entrypoints/virtual/dev.ts @@ -1,15 +1,14 @@ import { manifest } from 'virtual:astro:manifest'; -import type { BaseApp } from '../../base.js'; import { DevApp } from '../../dev/app.js'; import { createConsoleLogger } from '../../logging.js'; -import type { RouteInfo } from '../../types.js'; +import type { CreateApp, RouteInfo } from '../../types.js'; import type { RoutesList } from '../../../../types/astro.js'; let currentDevApp: DevApp | null = null; -export function createApp(): BaseApp { +export const createApp: CreateApp = ({ streaming } = {}) => { const logger = createConsoleLogger(manifest.logLevel); - currentDevApp = new DevApp(manifest, true, logger); + currentDevApp = new DevApp(manifest, streaming, logger); // Listen for route updates via HMR if (import.meta.hot) { @@ -30,4 +29,4 @@ export function createApp(): BaseApp { } return currentDevApp; -} +}; diff --git a/packages/astro/src/core/app/entrypoints/virtual/index.ts b/packages/astro/src/core/app/entrypoints/virtual/index.ts index 88bbdd19485b..13c88755cc32 100644 --- a/packages/astro/src/core/app/entrypoints/virtual/index.ts +++ b/packages/astro/src/core/app/entrypoints/virtual/index.ts @@ -1,4 +1,4 @@ import { createApp as _createApp } from 'virtual:astro:app'; -import type { BaseApp } from '../../base.js'; +import type { CreateApp } from '../../types.js'; -export const createApp: () => BaseApp = _createApp; +export const createApp: CreateApp = _createApp; diff --git a/packages/astro/src/core/app/entrypoints/virtual/prod.ts b/packages/astro/src/core/app/entrypoints/virtual/prod.ts index 75135148e60a..0ec893eb0a83 100644 --- a/packages/astro/src/core/app/entrypoints/virtual/prod.ts +++ b/packages/astro/src/core/app/entrypoints/virtual/prod.ts @@ -1,7 +1,7 @@ import { manifest } from 'virtual:astro:manifest'; -import type { BaseApp } from '../../base.js'; +import type { CreateApp } from '../../types.js'; import { App } from '../../app.js'; -export function createApp(): BaseApp { - return new App(manifest); -} +export const createApp: CreateApp = ({ streaming } = {}) => { + return new App(manifest, streaming); +}; diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index e56a6445a586..99646ca2a12f 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -19,6 +19,7 @@ import type { LoggerLevel } from '../logger/core.js'; import type { RoutingStrategies } from './common.js'; import type { BaseSessionConfig, SessionDriverFactory } from '../session/types.js'; import type { DevToolbarPlacement } from '../../types/public/toolbar.js'; +import type { BaseApp } from './base.js'; type ComponentPath = string; @@ -205,3 +206,5 @@ export type NodeAppHeadersJson = { value: string; }[]; }[]; + +export type CreateApp = (options?: { streaming?: boolean }) => BaseApp;