Skip to content

Commit 524c855

Browse files
ematipicosarah11918ascorbic
authored
fix(core): add error log for server islands (#12768)
Co-authored-by: Sarah Rainsberger <[email protected]> Co-authored-by: Matt Kane <[email protected]>
1 parent 892dd9f commit 524c855

File tree

9 files changed

+34
-8
lines changed

9 files changed

+34
-8
lines changed

.changeset/khaki-tools-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes an issue where Astro didn't print error logs when Astro Islands were used in incorrect cases.

.changeset/silver-cars-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes an issue where Astro was printing the incorrect output format when running the `astro build` command

.changeset/spotty-timers-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/underscore-redirects': minor
3+
---
4+
5+
Adds a new `buildOutput` property to the API `createRedirectsFromAstroRoutes`

packages/astro/src/core/build/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
runHookConfigSetup,
1313
} from '../../integrations/hooks.js';
1414
import type { AstroSettings, ManifestData } from '../../types/astro.js';
15-
import type { AstroConfig, AstroInlineConfig, RuntimeMode } from '../../types/public/config.js';
15+
import type { AstroInlineConfig, RuntimeMode } from '../../types/public/config.js';
1616
import { resolveConfig } from '../config/config.js';
1717
import { createNodeLogger } from '../config/logging.js';
1818
import { createSettings } from '../config/settings.js';
@@ -163,7 +163,7 @@ class AstroBuilder {
163163
await runHookBuildStart({ config: this.settings.config, logging: this.logger });
164164
this.validateConfig();
165165

166-
this.logger.info('build', `output: ${blue('"' + this.settings.config.output + '"')}`);
166+
this.logger.info('build', `output: ${blue('"' + this.settings.buildOutput + '"')}`);
167167
this.logger.info('build', `directory: ${blue(fileURLToPath(this.settings.config.outDir))}`);
168168
if (this.settings.adapter) {
169169
this.logger.info('build', `adapter: ${green(this.settings.adapter.name)}`);
@@ -283,7 +283,7 @@ class AstroBuilder {
283283
logger: Logger;
284284
timeStart: number;
285285
pageCount: number;
286-
buildMode: AstroConfig['output'];
286+
buildMode: AstroSettings['buildOutput'];
287287
}) {
288288
const total = getTimeStat(timeStart, performance.now());
289289

packages/astro/src/core/build/static-build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function viteBuild(opts: StaticBuildOptions) {
6363
registerAllPlugins(container);
6464
// Build your project (SSR application code, assets, client JS, etc.)
6565
const ssrTime = performance.now();
66-
opts.logger.info('build', `Building ${settings.config.output} entrypoints...`);
66+
opts.logger.info('build', `Building ${settings.buildOutput} entrypoints...`);
6767
const ssrOutput = await ssrBuild(opts, internals, pageInput, container);
6868
opts.logger.info('build', green(`✓ Completed in ${getTimeStat(ssrTime, performance.now())}.`));
6969

packages/astro/src/core/create-vite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export async function createVite(
170170
astroInternationalization({ settings }),
171171
vitePluginActions({ fs, settings }),
172172
vitePluginUserActions({ settings }),
173-
vitePluginServerIslands({ settings }),
173+
vitePluginServerIslands({ settings, logger }),
174174
astroContainer(),
175175
astroHmrReloadPlugin(),
176176
],

packages/astro/src/core/logger/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type LoggerLabel =
3333
| 'env'
3434
| 'update'
3535
| 'adapter'
36+
| 'islands'
3637
// SKIP_FORMAT: A special label that tells the logger not to apply any formatting.
3738
// Useful for messages that are already formatted, like the server start message.
3839
| 'SKIP_FORMAT';

packages/astro/src/core/server-islands/vite-plugin-server-islands.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { ConfigEnv, ViteDevServer, Plugin as VitePlugin } from 'vite';
2-
import type { AstroSettings } from '../../types/astro.js';
2+
import type { AstroPluginOptions } from '../../types/astro.js';
33
import type { AstroPluginMetadata } from '../../vite-plugin-astro/index.js';
44

55
export const VIRTUAL_ISLAND_MAP_ID = '@astro-server-islands';
66
export const RESOLVED_VIRTUAL_ISLAND_MAP_ID = '\0' + VIRTUAL_ISLAND_MAP_ID;
77
const serverIslandPlaceholder = "'$$server-islands$$'";
88

9-
export function vitePluginServerIslands({ settings }: { settings: AstroSettings }): VitePlugin {
9+
export function vitePluginServerIslands({ settings, logger }: AstroPluginOptions): VitePlugin {
1010
let command: ConfigEnv['command'] = 'serve';
1111
let viteServer: ViteDevServer | null = null;
1212
const referenceIdMap = new Map<string, string>();
@@ -37,6 +37,13 @@ export function vitePluginServerIslands({ settings }: { settings: AstroSettings
3737
if (astro?.serverComponents.length) {
3838
for (const comp of astro.serverComponents) {
3939
if (!settings.serverIslandNameMap.has(comp.resolvedPath)) {
40+
if (!settings.adapter) {
41+
logger.error(
42+
'islands',
43+
"You tried to render a server island without an adapter added to your project. An adapter is required to use the `server:defer` attribute on any component. Your project will fail to build unless you add an adapter or remove the attribute.",
44+
);
45+
}
46+
4047
let name = comp.localName;
4148
let idx = 1;
4249

packages/underscore-redirects/src/astro.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface CreateRedirectsFromAstroRoutesParams {
1818
*/
1919
routeToDynamicTargetMap: Map<IntegrationRouteData, string>;
2020
dir: URL;
21+
buildOutput: 'static' | 'server';
2122
}
2223

2324
/**
@@ -27,14 +28,16 @@ export function createRedirectsFromAstroRoutes({
2728
config,
2829
routeToDynamicTargetMap,
2930
dir,
31+
buildOutput,
3032
}: CreateRedirectsFromAstroRoutesParams) {
3133
const base =
3234
config.base && config.base !== '/'
3335
? config.base.endsWith('/')
3436
? config.base.slice(0, -1)
3537
: config.base
3638
: '';
37-
const output = config.output;
39+
// TODO: the use of `config.output` is deprecated. We need to update the adapters that use this package to pass the new buildOutput
40+
const output = buildOutput ?? config.output;
3841
const _redirects = new Redirects();
3942

4043
for (const [route, dynamicTarget = ''] of routeToDynamicTargetMap) {

0 commit comments

Comments
 (0)