From 1f5a773ecb00b465c0b8fffe3a4339ed70495fb2 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Tue, 29 Mar 2022 20:11:04 -0300 Subject: [PATCH 01/11] Replaced `--experimental-ssr` with `isBuildingToSSR` --- examples/ssr/package.json | 4 ++-- packages/astro/src/@types/astro.ts | 1 + packages/astro/src/cli/index.ts | 1 - packages/astro/src/core/build/generate.ts | 4 ++-- packages/astro/src/core/build/index.ts | 6 +++--- packages/astro/src/core/build/page-data.ts | 3 ++- packages/astro/src/core/config.ts | 11 ++++------- packages/astro/src/core/endpoint/dev/index.ts | 3 ++- packages/astro/src/core/render/dev/index.ts | 4 +++- packages/astro/src/vite-plugin-astro-server/index.ts | 4 ++-- packages/astro/test/ssr-api-route.test.js | 3 --- packages/astro/test/ssr-dynamic.test.js | 3 --- 12 files changed, 21 insertions(+), 26 deletions(-) diff --git a/examples/ssr/package.json b/examples/ssr/package.json index 401f7e06a6dd..370e79972db1 100644 --- a/examples/ssr/package.json +++ b/examples/ssr/package.json @@ -3,9 +3,9 @@ "version": "0.0.1", "private": true, "scripts": { - "dev": "astro dev --experimental-ssr", + "dev": "astro dev", "start": "astro dev", - "build": "astro build --experimental-ssr", + "build": "astro build", "server": "node server/server.mjs" }, "devDependencies": { diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 7dd66e41a1ce..bf96e2b8e17a 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -32,6 +32,7 @@ export interface CLIFlags { config?: string; /** @deprecated */ experimentalStaticBuild?: boolean; + /** @deprecated */ experimentalSsr?: boolean; experimentalIntegrations?: boolean; legacyBuild?: boolean; diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 5b4f2abbc4f4..c708d7076ff7 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -39,7 +39,6 @@ function printAstroHelp() { ['--project-root ', 'Specify the path to the project root folder.'], ['--no-sitemap', 'Disable sitemap generation (build only).'], ['--legacy-build', 'Use the build strategy prior to 0.24.0'], - ['--experimental-ssr', 'Enable SSR compilation.'], ['--drafts', 'Include markdown draft pages in the build.'], ['--verbose', 'Enable verbose logging'], ['--silent', 'Disable logging'], diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index f18f7b2bb59f..459003d0212d 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -12,7 +12,7 @@ import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import { call as callEndpoint } from '../endpoint/index.js'; import { render } from '../render/core.js'; import { createLinkStylesheetElementSet, createModuleScriptElementWithSrcSet } from '../render/ssr-element.js'; -import { getOutputFilename } from '../util.js'; +import { getOutputFilename, isBuildingToSSR } from '../util.js'; import { getOutFile, getOutFolder } from './common.js'; import { eachPageData, getPageDataByComponent } from './internal.js'; import type { PageBuildData, SingleFileBuiltModule, StaticBuildOptions } from './types'; @@ -197,7 +197,7 @@ async function generatePath(pathname: string, opts: StaticBuildOptions, gopts: G route: pageData.route, routeCache, site: astroConfig.buildOptions.site, - ssr: opts.astroConfig.buildOptions.experimentalSsr, + ssr: isBuildingToSSR(opts.astroConfig), }; let body: string; diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 4962ce1c7f16..b2ddabc5b339 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -16,7 +16,7 @@ import { staticBuild } from './static-build.js'; import { RouteCache } from '../render/route-cache.js'; import { runHookBuildDone, runHookBuildStart, runHookConfigDone, runHookConfigSetup } from '../../integrations/index.js'; import { getTimeStat } from './util.js'; -import { createSafeError } from '../util.js'; +import { createSafeError, isBuildingToSSR } from '../util.js'; import { fixViteErrorMessage } from '../errors.js'; export interface BuildOptions { @@ -100,7 +100,7 @@ class AstroBuilder { origin, routeCache: this.routeCache, viteServer, - ssr: this.config.buildOptions.experimentalSsr, + ssr: isBuildingToSSR(this.config), }); // Filter pages by using conditions based on their frontmatter. @@ -181,7 +181,7 @@ class AstroBuilder { await runHookBuildDone({ config: this.config, pages: pageNames, routes: Object.values(allPages).map((pd) => pd.route) }); if (this.logging.level && levels[this.logging.level] <= levels['info']) { - const buildMode = this.config.buildOptions.experimentalSsr ? 'ssr' : 'static'; + const buildMode = isBuildingToSSR(this.config) ? 'ssr' : 'static'; await this.printStats({ logging: this.logging, timeStart: this.timer.init, pageCount: pageNames.length, buildMode }); } } diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index 7681c066489d..2a8227b70b27 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -10,6 +10,7 @@ import { debug } from '../logger.js'; import { preload as ssrPreload } from '../render/dev/index.js'; import { generateRssFunction } from '../render/rss.js'; import { callGetStaticPaths, RouteCache, RouteCacheEntry } from '../render/route-cache.js'; +import { isBuildingToSSR } from '../util.js'; export interface CollectPagesDataOptions { astroConfig: AstroConfig; @@ -33,7 +34,7 @@ export async function collectPagesData(opts: CollectPagesDataOptions): Promise = {}; const allPages: AllPagesData = {}; - const buildMode = astroConfig.buildOptions.experimentalSsr ? 'ssr' : 'static'; + const buildMode = isBuildingToSSR(astroConfig) ? 'ssr' : 'static'; const dataCollectionLogTimeout = setInterval(() => { info(opts.logging, 'build', 'The data collection step may take longer for larger projects...'); diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 394c1c42dbe8..8c485382d7df 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -236,6 +236,10 @@ function resolveFlags(flags: Partial): CLIFlags { // eslint-disable-next-line no-console console.warn(`Passing --experimental-static-build is no longer necessary and is now the default. The flag will be removed in a future version of Astro.`); } + if (flags.experimentalSsr) { + // eslint-disable-next-line no-console + console.warn(`Passing --experimental-ssr is no longer necessary. The flag will be removed in a future version of Astro.`); + } return { projectRoot: typeof flags.projectRoot === 'string' ? flags.projectRoot : undefined, site: typeof flags.site === 'string' ? flags.site : undefined, @@ -245,7 +249,6 @@ function resolveFlags(flags: Partial): CLIFlags { hostname: typeof flags.hostname === 'string' ? flags.hostname : undefined, host: typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined, legacyBuild: typeof flags.legacyBuild === 'boolean' ? flags.legacyBuild : false, - experimentalSsr: typeof flags.experimentalSsr === 'boolean' ? flags.experimentalSsr : false, experimentalIntegrations: typeof flags.experimentalIntegrations === 'boolean' ? flags.experimentalIntegrations : false, drafts: typeof flags.drafts === 'boolean' ? flags.drafts : false, }; @@ -261,12 +264,6 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags) { if (typeof flags.host === 'string' || typeof flags.host === 'boolean') astroConfig.devOptions.host = flags.host; if (typeof flags.hostname === 'string') astroConfig.devOptions.hostname = flags.hostname; if (typeof flags.legacyBuild === 'boolean') astroConfig.buildOptions.legacyBuild = flags.legacyBuild; - if (typeof flags.experimentalSsr === 'boolean') { - astroConfig.buildOptions.experimentalSsr = flags.experimentalSsr; - if (flags.experimentalSsr) { - astroConfig.buildOptions.legacyBuild = false; - } - } if (typeof flags.experimentalIntegrations === 'boolean') astroConfig.experimentalIntegrations = flags.experimentalIntegrations; if (typeof flags.drafts === 'boolean') astroConfig.buildOptions.drafts = flags.drafts; return astroConfig; diff --git a/packages/astro/src/core/endpoint/dev/index.ts b/packages/astro/src/core/endpoint/dev/index.ts index da3671bc04b2..1e7abe8df722 100644 --- a/packages/astro/src/core/endpoint/dev/index.ts +++ b/packages/astro/src/core/endpoint/dev/index.ts @@ -1,12 +1,13 @@ import type { EndpointHandler } from '../../../@types/astro'; import type { SSROptions } from '../../render/dev'; import { preload } from '../../render/dev/index.js'; +import { isBuildingToSSR } from '../../util.js'; import { call as callEndpoint } from '../index.js'; export async function call(ssrOpts: SSROptions) { const [, mod] = await preload(ssrOpts); return await callEndpoint(mod as unknown as EndpointHandler, { ...ssrOpts, - ssr: ssrOpts.astroConfig.buildOptions.experimentalSsr, + ssr: isBuildingToSSR(ssrOpts.astroConfig), }); } diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index b96a431aed26..4636f5f13e8b 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -9,6 +9,8 @@ import { createModuleScriptElementWithSrcSet } from '../ssr-element.js'; import { getStylesForURL } from './css.js'; import { getHmrScript } from './hmr.js'; import { injectTags } from './html.js'; +import { isBuildingToSSR } from '../../util.js'; + export interface SSROptions { /** an instance of the AstroConfig */ astroConfig: AstroConfig; @@ -146,7 +148,7 @@ export async function render(renderers: SSRLoadedRenderer[], mod: ComponentInsta route, routeCache, site: astroConfig.buildOptions.site, - ssr: astroConfig.buildOptions.experimentalSsr, + ssr: isBuildingToSSR(astroConfig), }); if (route?.type === 'endpoint' || content.type === 'response') { diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index 87346af691ea..da5e49ac5881 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -6,7 +6,7 @@ import { debug, info, warn, error, LogOptions } from '../core/logger.js'; import { getParamsAndProps, GetParamsAndPropsError } from '../core/render/core.js'; import { createRouteManifest, matchRoute } from '../core/routing/index.js'; import stripAnsi from 'strip-ansi'; -import { createSafeError } from '../core/util.js'; +import { createSafeError, isBuildingToSSR } from '../core/util.js'; import { ssr, preload } from '../core/render/dev/index.js'; import { call as callEndpoint } from '../core/endpoint/dev/index.js'; import * as msg from '../core/messages.js'; @@ -185,7 +185,7 @@ async function handleRequest( routeCache, pathname: rootRelativeUrl, logging, - ssr: config.buildOptions.experimentalSsr, + ssr: isBuildingToSSR(config), }); if (paramsAndPropsRes === GetParamsAndPropsError.NoMatchingStaticPath) { warn(logging, 'getStaticPaths', `Route pattern matched, but no matching static path found. (${pathname})`); diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index 54991e80a5b8..d6954de1139d 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -10,9 +10,6 @@ describe('API routes in SSR', () => { before(async () => { fixture = await loadFixture({ projectRoot: './fixtures/ssr-api-route/', - buildOptions: { - experimentalSsr: true, - }, adapter: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index d938e5c95aef..75fdb85c7c83 100644 --- a/packages/astro/test/ssr-dynamic.test.js +++ b/packages/astro/test/ssr-dynamic.test.js @@ -11,9 +11,6 @@ describe('Dynamic pages in SSR', () => { before(async () => { fixture = await loadFixture({ projectRoot: './fixtures/ssr-dynamic/', - buildOptions: { - experimentalSsr: true, - }, adapter: testAdapter(), }); await fixture.build(); From 0d0fdf7f20eb14c4e43156335956f8b3abb2111a Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Tue, 29 Mar 2022 20:12:43 -0300 Subject: [PATCH 02/11] changest --- .changeset/flat-radios-cheer.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/flat-radios-cheer.md diff --git a/.changeset/flat-radios-cheer.md b/.changeset/flat-radios-cheer.md new file mode 100644 index 000000000000..ea969c62c735 --- /dev/null +++ b/.changeset/flat-radios-cheer.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Removed `--experimental-ssr` flag From af8d853ffa217da2ed09358ebd7d302dc8f954da Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Tue, 29 Mar 2022 20:28:47 -0300 Subject: [PATCH 03/11] Improved `isBuildingToSSR` a bit --- packages/astro/src/core/util.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index ca98419daded..7bc924417689 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -157,7 +157,8 @@ export function emptyDir(_dir: URL, skip?: Set): void { } export function isBuildingToSSR(config: AstroConfig): boolean { - return !!config._ctx.adapter?.serverEntrypoint; + const serverEntrypoint = config._ctx?.adapter?.serverEntrypoint; + return typeof serverEntrypoint === 'string'; } export function emoji(char: string, fallback: string) { From 2ce56927978a1ce6cc6fde3663a6211b80987cb2 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Tue, 29 Mar 2022 20:29:03 -0300 Subject: [PATCH 04/11] Added `isBuildingToSSR` to more places!!1! --- packages/astro/src/core/build/generate.ts | 2 +- packages/astro/src/vite-plugin-astro-server/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 459003d0212d..5525f559b799 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -71,7 +71,7 @@ export async function generatePages(result: RollupOutput, opts: StaticBuildOptio const timer = performance.now(); info(opts.logging, null, `\n${bgGreen(black(' generating static routes '))}`); - const ssr = !!opts.astroConfig._ctx.adapter?.serverEntrypoint; + const ssr = isBuildingToSSR(opts.astroConfig); const serverEntry = opts.buildConfig.serverEntry; const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.dist; const ssrEntryURL = new URL('./' + serverEntry + `?time=${Date.now()}`, outFolder); diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index da5e49ac5881..e195d7015145 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -123,7 +123,7 @@ async function handleRequest( const site = config.buildOptions.site ? new URL(config.buildOptions.site) : undefined; const devRoot = site ? site.pathname : '/'; const origin = `${viteServer.config.server.https ? 'https' : 'http'}://${req.headers.host}`; - const buildingToSSR = !!config._ctx.adapter?.serverEntrypoint; + const buildingToSSR = isBuildingToSSR(config); const url = new URL(origin + req.url); const pathname = decodeURI(url.pathname); const rootRelativeUrl = pathname.substring(devRoot.length - 1); From 6394462631a29b0f1b93b404e3ddbcdadf4d2384 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Tue, 29 Mar 2022 20:42:49 -0300 Subject: [PATCH 05/11] Added `@deprecated` tag --- packages/astro/src/@types/astro.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index bf96e2b8e17a..f6185c6b91d4 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -345,6 +345,7 @@ export interface AstroUserConfig { */ experimentalStaticBuild?: boolean; /** + * @deprecated * Enable a build for SSR support. * Default: false */ From c7e4ef62f706ca6eed44e5a07aaf44b23eda273a Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Tue, 29 Mar 2022 20:44:02 -0300 Subject: [PATCH 06/11] Replaced missing experimentalSsr --- packages/astro/src/core/build/static-build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index b166948f1fa5..f1a1ff3d2122 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -110,7 +110,7 @@ export async function staticBuild(opts: StaticBuildOptions) { async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, input: Set) { const { astroConfig, viteConfig } = opts; - const ssr = astroConfig.buildOptions.experimentalSsr; + const ssr = isBuildingToSSR(astroConfig); const out = ssr ? opts.buildConfig.server : astroConfig.dist; // TODO: use vite.mergeConfig() here? return await vite.build({ From 1b61a3734fe3d65d4e080e36d759b88f9e59247d Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Tue, 29 Mar 2022 20:49:11 -0300 Subject: [PATCH 07/11] Added failing test --- .../astro/test/fixtures/ssr-api-route/public/static.txt | 1 + packages/astro/test/ssr-api-route.test.js | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 packages/astro/test/fixtures/ssr-api-route/public/static.txt diff --git a/packages/astro/test/fixtures/ssr-api-route/public/static.txt b/packages/astro/test/fixtures/ssr-api-route/public/static.txt new file mode 100644 index 000000000000..af5626b4a114 --- /dev/null +++ b/packages/astro/test/fixtures/ssr-api-route/public/static.txt @@ -0,0 +1 @@ +Hello, world! diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index d6954de1139d..2522f5eba148 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -23,6 +23,14 @@ describe('API routes in SSR', () => { expect(html).to.not.be.empty; }); + it('Static files work too', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/static.txt'); + const response = await app.render(request); + const txt = await response.text(); + expect(txt).to.include('Hello, world!'); + }); + it('Can load the API route too', async () => { const app = await fixture.loadTestAdapterApp(); const request = new Request('http://example.com/food.json'); From e08abb35d5e859c7144d9f9d6425f0ece72f46ba Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Wed, 30 Mar 2022 12:44:57 -0300 Subject: [PATCH 08/11] Removed test --- .../astro/test/fixtures/ssr-api-route/public/static.txt | 1 - packages/astro/test/ssr-api-route.test.js | 8 -------- 2 files changed, 9 deletions(-) delete mode 100644 packages/astro/test/fixtures/ssr-api-route/public/static.txt diff --git a/packages/astro/test/fixtures/ssr-api-route/public/static.txt b/packages/astro/test/fixtures/ssr-api-route/public/static.txt deleted file mode 100644 index af5626b4a114..000000000000 --- a/packages/astro/test/fixtures/ssr-api-route/public/static.txt +++ /dev/null @@ -1 +0,0 @@ -Hello, world! diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index 2522f5eba148..d6954de1139d 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -23,14 +23,6 @@ describe('API routes in SSR', () => { expect(html).to.not.be.empty; }); - it('Static files work too', async () => { - const app = await fixture.loadTestAdapterApp(); - const request = new Request('http://example.com/static.txt'); - const response = await app.render(request); - const txt = await response.text(); - expect(txt).to.include('Hello, world!'); - }); - it('Can load the API route too', async () => { const app = await fixture.loadTestAdapterApp(); const request = new Request('http://example.com/food.json'); From ecc14466517b19946a1ac55f9090d98587d6e6f8 Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Thu, 31 Mar 2022 11:03:25 -0300 Subject: [PATCH 09/11] Re-added experimental ssr flag --- .changeset/flat-radios-cheer.md | 2 +- packages/astro/src/@types/astro.ts | 5 ++--- packages/astro/src/cli/index.ts | 1 + packages/astro/src/core/config.ts | 6 ++---- packages/astro/src/core/util.ts | 23 +++++++++++++++++++++-- packages/astro/test/ssr-api-route.test.js | 1 + packages/astro/test/ssr-dynamic.test.js | 1 + 7 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.changeset/flat-radios-cheer.md b/.changeset/flat-radios-cheer.md index ea969c62c735..ab01d34ddfd2 100644 --- a/.changeset/flat-radios-cheer.md +++ b/.changeset/flat-radios-cheer.md @@ -2,4 +2,4 @@ 'astro': patch --- -Removed `--experimental-ssr` flag +`--experimental-ssr` now is only required when using a 3rd-party adapter diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 4d3200b28705..8c398112a21b 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -33,7 +33,6 @@ export interface CLIFlags { config?: string; /** @deprecated */ experimentalStaticBuild?: boolean; - /** @deprecated */ experimentalSsr?: boolean; experimentalIntegrations?: boolean; legacyBuild?: boolean; @@ -346,8 +345,8 @@ export interface AstroUserConfig { */ experimentalStaticBuild?: boolean; /** - * @deprecated - * Enable a build for SSR support. + * Enable SSR support for 3rd-party adapters. + * Not requuired when using a built-in adapter. * Default: false */ experimentalSsr?: boolean; diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 0e63d5d29c21..c68a97a748b3 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -39,6 +39,7 @@ function printAstroHelp() { ['--project-root ', 'Specify the path to the project root folder.'], ['--no-sitemap', 'Disable sitemap generation (build only).'], ['--legacy-build', 'Use the build strategy prior to 0.24.0'], + ['--experimental-ssr', 'Enable SSR compilation fot 3rd-party adapters.'], ['--drafts', 'Include markdown draft pages in the build.'], ['--verbose', 'Enable verbose logging'], ['--silent', 'Disable logging'], diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 8c485382d7df..97b467e9da6a 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -236,10 +236,6 @@ function resolveFlags(flags: Partial): CLIFlags { // eslint-disable-next-line no-console console.warn(`Passing --experimental-static-build is no longer necessary and is now the default. The flag will be removed in a future version of Astro.`); } - if (flags.experimentalSsr) { - // eslint-disable-next-line no-console - console.warn(`Passing --experimental-ssr is no longer necessary. The flag will be removed in a future version of Astro.`); - } return { projectRoot: typeof flags.projectRoot === 'string' ? flags.projectRoot : undefined, site: typeof flags.site === 'string' ? flags.site : undefined, @@ -249,6 +245,7 @@ function resolveFlags(flags: Partial): CLIFlags { hostname: typeof flags.hostname === 'string' ? flags.hostname : undefined, host: typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined, legacyBuild: typeof flags.legacyBuild === 'boolean' ? flags.legacyBuild : false, + experimentalSsr: typeof flags.experimentalSsr === 'boolean' ? flags.experimentalSsr : false, experimentalIntegrations: typeof flags.experimentalIntegrations === 'boolean' ? flags.experimentalIntegrations : false, drafts: typeof flags.drafts === 'boolean' ? flags.drafts : false, }; @@ -264,6 +261,7 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags) { if (typeof flags.host === 'string' || typeof flags.host === 'boolean') astroConfig.devOptions.host = flags.host; if (typeof flags.hostname === 'string') astroConfig.devOptions.hostname = flags.hostname; if (typeof flags.legacyBuild === 'boolean') astroConfig.buildOptions.legacyBuild = flags.legacyBuild; + if (typeof flags.experimentalSsr === 'boolean') astroConfig.buildOptions.experimentalSsr = flags.experimentalSsr; if (typeof flags.experimentalIntegrations === 'boolean') astroConfig.experimentalIntegrations = flags.experimentalIntegrations; if (typeof flags.drafts === 'boolean') astroConfig.buildOptions.drafts = flags.drafts; return astroConfig; diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 12968bafb656..2ec2a1744030 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -139,8 +139,27 @@ export function emptyDir(_dir: URL, skip?: Set): void { } export function isBuildingToSSR(config: AstroConfig): boolean { - const serverEntrypoint = config._ctx?.adapter?.serverEntrypoint; - return typeof serverEntrypoint === 'string'; + const adapter = config._ctx.adapter; + if (!adapter) return false; + + if (typeof adapter.serverEntrypoint === 'string') { + if (!adapter.name.startsWith('@astrojs/') && !config.buildOptions.experimentalSsr) { + throw new Error( + [ + `Server-side rendering (SSR) is still experimental.`, + ``, + `Only official "@astrojs/*" adapters are currently supported.`, + `To enable SSR for 3rd-party adapters, use the "--experimental-ssr" flag.`, + `Breaking changes may occur in this API before Astro v1.0 is released.`, + ``, + ].join('\n') + ); + } else { + return true; + } + } else { + return false; + } } export function emoji(char: string, fallback: string) { diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index d6954de1139d..6bf8fcd20f74 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -10,6 +10,7 @@ describe('API routes in SSR', () => { before(async () => { fixture = await loadFixture({ projectRoot: './fixtures/ssr-api-route/', + buildOptions: { experimentalSsr: true }, adapter: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index 75fdb85c7c83..98d73b98ef6a 100644 --- a/packages/astro/test/ssr-dynamic.test.js +++ b/packages/astro/test/ssr-dynamic.test.js @@ -11,6 +11,7 @@ describe('Dynamic pages in SSR', () => { before(async () => { fixture = await loadFixture({ projectRoot: './fixtures/ssr-dynamic/', + buildOptions: { experimentalSsr: true }, adapter: testAdapter(), }); await fixture.build(); From 604e8b479ef647461c500383b644c6b640290086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Thu, 31 Mar 2022 14:09:37 -0300 Subject: [PATCH 10/11] Fixed typo Co-authored-by: Matthew Phillips --- packages/astro/src/@types/astro.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 8c398112a21b..800ab9b23b27 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -346,7 +346,7 @@ export interface AstroUserConfig { experimentalStaticBuild?: boolean; /** * Enable SSR support for 3rd-party adapters. - * Not requuired when using a built-in adapter. + * Not required when using a built-in adapter. * Default: false */ experimentalSsr?: boolean; From cb45642008b0cca6a38c0282f569aceeb3c32bfe Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Thu, 31 Mar 2022 14:49:02 -0300 Subject: [PATCH 11/11] Fixed deno tests --- .../integrations/deno/test/fixtures/basics/astro.config.mjs | 3 ++- packages/integrations/deno/test/helpers.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/integrations/deno/test/fixtures/basics/astro.config.mjs b/packages/integrations/deno/test/fixtures/basics/astro.config.mjs index dfdf9e182f7c..38490926b07e 100644 --- a/packages/integrations/deno/test/fixtures/basics/astro.config.mjs +++ b/packages/integrations/deno/test/fixtures/basics/astro.config.mjs @@ -2,5 +2,6 @@ import { defineConfig } from 'astro/config'; import deno from '@astrojs/deno'; export default defineConfig({ - adapter: deno() + adapter: deno(), + buildOptions: { experimentalSsr: true } }) diff --git a/packages/integrations/deno/test/helpers.js b/packages/integrations/deno/test/helpers.js index 659d24d5ecb8..bc2bc062285d 100644 --- a/packages/integrations/deno/test/helpers.js +++ b/packages/integrations/deno/test/helpers.js @@ -13,7 +13,7 @@ export async function runBuild(fixturePath) { export async function runBuildAndStartApp(fixturePath, cb) { const url = new URL(fixturePath, dir); const close = await runBuild(fixturePath); - const mod = await import(new URL('./dist/entry.mjs', url)); + const mod = await import(new URL('./dist/server/entry.mjs', url)); await cb(); await mod.stop(); await close();