Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
"cheerio": "1.2.0",
"eol": "^0.10.0",
"expect-type": "^1.3.0",
"fs-fixture": "^2.11.0",
"fs-fixture": "^2.13.0",
"mdast-util-mdx": "^3.0.0",
"mdast-util-mdx-jsx": "^3.2.0",
"node-mocks-http": "^1.17.2",
Expand Down
8 changes: 6 additions & 2 deletions packages/astro/src/content/loaders/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,12 @@ export function glob(globOptions: GlobOptions & { [secretLegacyFlag]?: boolean }
const entryType = configForFile(changedPath);
const baseUrl = pathToFileURL(basePath);
const oldId = fileToIdMap.get(changedPath);
await syncData(entry, baseUrl, entryType, oldId);
logger.info(`Reloaded data from ${colors.green(entry)}`);
try {
await syncData(entry, baseUrl, entryType, oldId);
logger.info(`Reloaded data from ${colors.green(entry)}`);
} catch (e: any) {
logger.error(`Failed to reload ${entry}: ${e.message}`);
}
}

watcher.on('change', onChange);
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/routing/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export async function matchRoute(
const matches = matchAllRoutes(pathname, routesList);

const preloadedMatches = getSortedPreloadedMatches({
pipeline,
matches,
manifest,
});
Expand Down
10 changes: 1 addition & 9 deletions packages/astro/src/prerender/routing.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { routeIsRedirect } from '../core/routing/helpers.js';
import { routeComparator } from '../core/routing/priority.js';
import type { RouteData, SSRManifest } from '../types/public/internal.js';
import type { RunnablePipeline } from '../vite-plugin-app/pipeline.js';

type GetSortedPreloadedMatchesParams = {
pipeline: RunnablePipeline;
matches: RouteData[];
manifest: SSRManifest;
};
export function getSortedPreloadedMatches({
pipeline,
matches,
manifest,
}: GetSortedPreloadedMatchesParams) {
export function getSortedPreloadedMatches({ matches, manifest }: GetSortedPreloadedMatchesParams) {
return preloadAndSetPrerenderStatus({
pipeline,
matches,
manifest,
})
Expand All @@ -23,7 +16,6 @@ export function getSortedPreloadedMatches({
}

type PreloadAndSetPrerenderStatusParams = {
pipeline: RunnablePipeline;
matches: RouteData[];
manifest: SSRManifest;
};
Expand Down
122 changes: 1 addition & 121 deletions packages/astro/src/vite-plugin-astro-server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@ import { AsyncLocalStorage } from 'node:async_hooks';
import { IncomingMessage } from 'node:http';
import type * as vite from 'vite';
import { isRunnableDevEnvironment, type RunnableDevEnvironment } from 'vite';
import { toFallbackType } from '../core/app/common.js';
import { toRoutingStrategy } from '../core/app/entrypoints/index.js';
import type { SSRManifest, SSRManifestCSP, SSRManifestI18n } from '../core/app/types.js';
import type { SSRManifest } from '../core/app/types.js';
import { ASTRO_VITE_ENVIRONMENT_NAMES, devPrerenderMiddlewareSymbol } from '../core/constants.js';
import {
getAlgorithm,
getDirectives,
getScriptHashes,
getScriptResources,
getStrictDynamic,
getStyleHashes,
getStyleResources,
shouldTrackCspHashes,
} from '../core/csp/common.js';
import { createKey, getEnvironmentKey, hasEnvironmentKey } from '../core/encryption.js';
import { getViteErrorPayload } from '../core/errors/dev/index.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import type { Logger } from '../core/logger/core.js';
import { NOOP_MIDDLEWARE_FN } from '../core/middleware/noop-middleware.js';
import { createViteLoader } from '../core/module-loader/index.js';
import { matchAllRoutes } from '../core/routing/match.js';
import { resolveMiddlewareMode } from '../integrations/adapter-utils.js';
import { SERIALIZED_MANIFEST_ID } from '../manifest/serialized.js';
import type { AstroSettings } from '../types/astro.js';
import { ASTRO_DEV_SERVER_APP_ID } from '../vite-plugin-app/index.js';
Expand All @@ -34,7 +19,6 @@ import { setRouteError } from './server-state.js';
import { routeGuardMiddleware } from './route-guard.js';
import { secFetchMiddleware } from './sec-fetch.js';
import { trailingSlashMiddleware } from './trailing-slash.js';
import { sessionConfigToManifest } from '../core/session/utils.js';

interface AstroPluginOptions {
settings: AstroSettings;
Expand Down Expand Up @@ -201,107 +185,3 @@ export default function createVitePluginAstroServer({
},
};
}

/**
* It creates a `SSRManifest` from the `AstroSettings`.
*
* Renderers needs to be pulled out from the page module emitted during the build.
* @param settings
*/
export async function createDevelopmentManifest(settings: AstroSettings): Promise<SSRManifest> {
let i18nManifest: SSRManifestI18n | undefined;
let csp: SSRManifestCSP | undefined;
if (settings.config.i18n) {
i18nManifest = {
fallback: settings.config.i18n.fallback,
strategy: toRoutingStrategy(settings.config.i18n.routing, settings.config.i18n.domains),
defaultLocale: settings.config.i18n.defaultLocale,
locales: settings.config.i18n.locales,
domainLookupTable: {},
fallbackType: toFallbackType(settings.config.i18n.routing),
domains: settings.config.i18n.domains,
};
}

if (shouldTrackCspHashes(settings.config.security.csp)) {
const styleHashes = [
...getStyleHashes(settings.config.security.csp),
...settings.injectedCsp.styleHashes,
];

csp = {
cspDestination: settings.adapter?.adapterFeatures?.staticHeaders ? 'adapter' : undefined,
scriptHashes: getScriptHashes(settings.config.security.csp),
scriptResources: getScriptResources(settings.config.security.csp),
styleHashes,
styleResources: getStyleResources(settings.config.security.csp),
algorithm: getAlgorithm(settings.config.security.csp),
directives: getDirectives(settings),
isStrictDynamic: getStrictDynamic(settings.config.security.csp),
};
}

return {
rootDir: settings.config.root,
srcDir: settings.config.srcDir,
cacheDir: settings.config.cacheDir,
outDir: settings.config.outDir,
buildServerDir: settings.config.build.server,
buildClientDir: settings.config.build.client,
publicDir: settings.config.publicDir,
trailingSlash: settings.config.trailingSlash,
buildFormat: settings.config.build.format,
compressHTML: settings.config.compressHTML,
assetsDir: settings.config.build.assets,
serverLike: settings.buildOutput === 'server',
middlewareMode: resolveMiddlewareMode(settings.adapter?.adapterFeatures),
assets: new Set(),
entryModules: {},
routes: [],
adapterName: settings?.adapter?.name ?? '',
clientDirectives: settings.clientDirectives,
renderers: [],
base: settings.config.base,
userAssetsBase: settings.config?.vite?.base,
assetsPrefix: settings.config.build.assetsPrefix,
site: settings.config.site,
componentMetadata: new Map(),
inlinedScripts: new Map(),
i18n: i18nManifest,
checkOrigin: settings.config.security?.checkOrigin ?? false,
allowedDomains: settings.config.security?.allowedDomains,
actionBodySizeLimit: settings.config.security?.actionBodySizeLimit
? settings.config.security.actionBodySizeLimit
: 1024 * 1024, // 1mb default
serverIslandBodySizeLimit: settings.config.security?.serverIslandBodySizeLimit
? settings.config.security.serverIslandBodySizeLimit
: 1024 * 1024, // 1mb default
key: hasEnvironmentKey() ? getEnvironmentKey() : createKey(),
middleware() {
return {
onRequest: NOOP_MIDDLEWARE_FN,
};
},
sessionConfig: sessionConfigToManifest(settings.config.session),
csp,
image: {
objectFit: settings.config.image.objectFit,
objectPosition: settings.config.image.objectPosition,
layout: settings.config.image.layout,
},
devToolbar: {
enabled:
settings.config.devToolbar.enabled &&
(await settings.preferences.get('devToolbar.enabled')),
latestAstroVersion: settings.latestAstroVersion,
debugInfoOutput: '',
placement: settings.config.devToolbar.placement,
},
logLevel: settings.logLevel,
shouldInjectCspMetaTags: false,
experimentalQueuedRendering: {
enabled: !!settings.config.experimental?.queuedRendering,
poolSize: settings.config.experimental?.queuedRendering?.poolSize ?? 1000,
},
};
}
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/content-frontmatter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/content-frontmatter",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import { glob } from 'astro/loaders';

const posts = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/posts' }),
schema: z.object({
title: z.string(),
}),
});

export const collections = {
posts
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: One
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
---
<html>
<head><title>Test</title></head>
<body class="one">
<h1>Test</h1>
</body>
</html>
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/dev-container/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/dev-container",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
1 change: 1 addition & 0 deletions packages/astro/test/fixtures/dev-container/public/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Custom 404</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>{Astro.params.slug}</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
const name = 'Testing';
---
<html>
<head><title>{name}</title></head>
<body>
<h1>{name}</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Regular page</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>{Astro.params.slug}</h1>
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/dev-error-pages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/dev-error-pages",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Custom 404</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Server Error</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Home</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
throw new Error('boom');
---
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/dev-render/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/dev-render",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre id="both-flipped" set:html={JSON.stringify(Astro.props)} />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre id="both-literal" set:html={JSON.stringify(Astro.props)} />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre id="both-spread" set:html={JSON.stringify(Astro.props)} />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre id="class" set:html={JSON.stringify(Astro.props)} />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre id="class-list" set:html={JSON.stringify(Astro.props)} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
return null;
---
4 changes: 4 additions & 0 deletions packages/astro/test/fixtures/dev-render/src/pages/chunk.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
const value = { type: 'foobar' }
---
<div id="chunk">{value}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
import Class from '../components/Class.astro';
import ClassList from '../components/ClassList.astro';
import BothLiteral from '../components/BothLiteral.astro';
import BothFlipped from '../components/BothFlipped.astro';
import BothSpread from '../components/BothSpread.astro';
---
<Class class="red blue" />
<ClassList class:list={{ red: true, blue: true }} />
<BothLiteral class="red" class:list={{ blue: true }} />
<BothFlipped class:list={{ blue: true }} class="red" />
<BothSpread class:list={{ blue: true }} { ...{ class: "red" }} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
const selectedColor = "blue";
const autoplay = 2000;
---
<html>
<head><title>Custom Element Attributes Test</title></head>
<body>
<color-picker selected={selectedColor}></color-picker>
<test-a autoplay={autoplay}>Test with autoplay prop working</test-a>
</body>
</html>
12 changes: 12 additions & 0 deletions packages/astro/test/fixtures/dev-render/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
const name = 'Testing';
const TagA = 'p style=color:red;'
const TagB = 'p><script id="pwnd">console.log("pwnd")</script>'
---
<html>
<head><title>{name}</title></head>
<body>
<TagA id="target" />
<TagB />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
import NullComponent from '../components/NullComponent.astro';
---
<NullComponent />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>testing</h1>
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/dev-request-url/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/dev-request-url",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
export const prerender = true;
---
{Astro.request.url}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{Astro.request.url}
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/endpoint-routing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/endpoint-routing",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const GET = () => { return new Response('content', { status: 201, headers: { Test: 'value' } }) }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const GET = _ => {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const GET = ({ url }) => new Response('something went wrong', { headers: { "Content-Type": "text/plain" }, status: 500 })
Loading
Loading