-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Base Environment * SSRRoutePipeline -> AppEnvironment * BuildPipeline -> BuildEnvironment * DevPipeline -> DevEnvironment * per-request pipeline * internal middleware: i18n * delete callEndpoint * pipeline access for internal middleware * Address review comments `environment.ts` is now lives directly in `src/core`, rather than `src/core/render`. `environment.createPipeline` is removed. `Pipeline.create` is used instead. Constructors with positional arguments are replaced by `Environment.create` with named arguments. Clarifies the use of `HiddenPipeline`. * migrate some of `RenderContext`'s responsibilities to `Pipeline` * delete renderPage * RenderContext.params -> Pipeline.params * delete `RenderContext` * `Pipeline` -> `RenderContext` * `Environment` -> `Pipeline` * `AppEnvironment` -> `AppPipeline` * `BuildEnvironment` -> `BuildPipeline` * `DevEnvironment` -> `DevPipeline` * provide locals directly to renderContext * add changeset
- Loading branch information
Showing
46 changed files
with
828 additions
and
1,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"astro": patch | ||
--- | ||
|
||
Refactors internals relating to middleware, endpoints, and page rendering. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { RouteData, SSRElement, SSRResult } from "../../@types/astro.js"; | ||
import { Pipeline } from "../base-pipeline.js"; | ||
import { createModuleScriptElement, createStylesheetElementSet } from "../render/ssr-element.js"; | ||
|
||
export class AppPipeline extends Pipeline { | ||
static create({ logger, manifest, mode, renderers, resolve, serverLike, streaming }: Pick<AppPipeline, 'logger' | 'manifest' | 'mode' | 'renderers' | 'resolve' | 'serverLike' | 'streaming'>) { | ||
return new AppPipeline(logger, manifest, mode, renderers, resolve, serverLike, streaming); | ||
} | ||
|
||
headElements(routeData: RouteData): Pick<SSRResult, 'scripts' | 'styles' | 'links'> { | ||
const routeInfo = this.manifest.routes.find(route => route.routeData === routeData); | ||
// may be used in the future for handling rel=modulepreload, rel=icon, rel=manifest etc. | ||
const links = new Set<never>(); | ||
const scripts = new Set<SSRElement>(); | ||
const styles = createStylesheetElementSet(routeInfo?.styles ?? []); | ||
|
||
for (const script of routeInfo?.scripts ?? []) { | ||
if ('stage' in script) { | ||
if (script.stage === 'head-inline') { | ||
scripts.add({ | ||
props: {}, | ||
children: script.children, | ||
}); | ||
} | ||
} else { | ||
scripts.add(createModuleScriptElement(script)); | ||
} | ||
} | ||
return { links, styles, scripts } | ||
} | ||
|
||
componentMetadata() {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { MiddlewareHandler, RouteData, RuntimeMode, SSRLoadedRenderer, SSRManifest, SSRResult } from '../@types/astro.js'; | ||
import type { Logger } from './logger/core.js'; | ||
import { RouteCache } from './render/route-cache.js'; | ||
import { createI18nMiddleware } from '../i18n/middleware.js'; | ||
|
||
/** | ||
* The `Pipeline` represents the static parts of rendering that do not change between requests. | ||
* These are mostly known when the server first starts up and do not change. | ||
* | ||
* Thus, a `Pipeline` is created once at process start and then used by every `RenderContext`. | ||
*/ | ||
export abstract class Pipeline { | ||
readonly internalMiddleware: MiddlewareHandler[]; | ||
|
||
constructor( | ||
readonly logger: Logger, | ||
readonly manifest: SSRManifest, | ||
/** | ||
* "development" or "production" | ||
*/ | ||
readonly mode: RuntimeMode, | ||
readonly renderers: SSRLoadedRenderer[], | ||
readonly resolve: (s: string) => Promise<string>, | ||
/** | ||
* Based on Astro config's `output` option, `true` if "server" or "hybrid". | ||
*/ | ||
readonly serverLike: boolean, | ||
readonly streaming: boolean, | ||
/** | ||
* Used to provide better error messages for `Astro.clientAddress` | ||
*/ | ||
readonly adapterName = manifest.adapterName, | ||
readonly clientDirectives = manifest.clientDirectives, | ||
readonly compressHTML = manifest.compressHTML, | ||
readonly i18n = manifest.i18n, | ||
readonly middleware = manifest.middleware, | ||
readonly routeCache = new RouteCache(logger, mode), | ||
/** | ||
* Used for `Astro.site`. | ||
*/ | ||
readonly site = manifest.site, | ||
) { | ||
this.internalMiddleware = [ createI18nMiddleware(i18n, manifest.base, manifest.trailingSlash, manifest.buildFormat) ]; | ||
} | ||
|
||
abstract headElements(routeData: RouteData): Promise<HeadElements> | HeadElements | ||
abstract componentMetadata(routeData: RouteData): Promise<SSRResult['componentMetadata']> | void | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface HeadElements extends Pick<SSRResult, 'scripts' | 'styles' | 'links'> {} |
Oops, something went wrong.