Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/warm-donuts-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'astro': minor
---

Adds `streaming` option to the `createApp()` function in the Adapter API, mirroring the same functionality available when creating a new `App` instance


Comment thread
florian-lefebvre marked this conversation as resolved.
Outdated
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 })
```
Comment thread
florian-lefebvre marked this conversation as resolved.

See more about [the `createApp()` function](https://v6.docs.astro.build/en/reference/adapter-reference/#createapp) in the Adapter API reference.
2 changes: 1 addition & 1 deletion packages/astro/dev-only.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 4 additions & 5 deletions packages/astro/src/core/app/entrypoints/virtual/dev.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -30,4 +29,4 @@ export function createApp(): BaseApp {
}

return currentDevApp;
}
};
4 changes: 2 additions & 2 deletions packages/astro/src/core/app/entrypoints/virtual/index.ts
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 4 additions & 4 deletions packages/astro/src/core/app/entrypoints/virtual/prod.ts
Original file line number Diff line number Diff line change
@@ -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);
};
3 changes: 3 additions & 0 deletions packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -205,3 +206,5 @@ export type NodeAppHeadersJson = {
value: string;
}[];
}[];

export type CreateApp = (options?: { streaming?: boolean }) => BaseApp;
Loading