[ci] format

This commit is contained in:
matthewp 2023-03-24 15:20:00 +00:00 committed by fredkbot
parent 45da39a864
commit b558bd5140
9 changed files with 35 additions and 43 deletions

View file

@ -1594,8 +1594,8 @@ export interface SSRMetadata {
export type PropagationHint = 'none' | 'self' | 'in-tree'; export type PropagationHint = 'none' | 'self' | 'in-tree';
export type SSRComponentMetadata = { export type SSRComponentMetadata = {
propagation: PropagationHint, propagation: PropagationHint;
containsHead: boolean containsHead: boolean;
}; };
export interface SSRResult { export interface SSRResult {

View file

@ -178,13 +178,7 @@ async function render({
return createHeadAndContent( return createHeadAndContent(
unescapeHTML(styles + links + scripts) as any, unescapeHTML(styles + links + scripts) as any,
renderTemplate`${renderComponent( renderTemplate`${renderComponent(result, 'Content', mod.Content, props, slots)}`
result,
'Content',
mod.Content,
props,
slots
)}`
); );
}, },
propagation: 'self', propagation: 'self',

View file

@ -1,9 +1,9 @@
import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark'; import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark';
import type { import type {
ComponentInstance, ComponentInstance,
SSRComponentMetadata,
RouteData, RouteData,
SerializedRouteData, SerializedRouteData,
SSRComponentMetadata,
SSRLoadedRenderer, SSRLoadedRenderer,
SSRResult, SSRResult,
} from '../../@types/astro'; } from '../../@types/astro';

View file

@ -1,5 +1,4 @@
import type { GetModuleInfo, ModuleInfo } from 'rollup'; import type { GetModuleInfo, ModuleInfo } from 'rollup';
import type { ViteDevServer } from 'vite';
import { resolvedPagesVirtualModuleId } from '../app/index.js'; import { resolvedPagesVirtualModuleId } from '../app/index.js';

View file

@ -1,4 +1,4 @@
import type { SSRResult, SSRComponentMetadata } from '../../../@types/astro'; import type { SSRComponentMetadata, SSRResult } from '../../../@types/astro';
import type { ModuleInfo, ModuleLoader } from '../../module-loader/index'; import type { ModuleInfo, ModuleLoader } from '../../module-loader/index';
@ -24,21 +24,18 @@ export async function getComponentMetadata(
return map; return map;
} }
function addMetadata( function addMetadata(map: SSRResult['componentMetadata'], modInfo: ModuleInfo | null) {
map: SSRResult['componentMetadata'],
modInfo: ModuleInfo | null
) {
if (modInfo) { if (modInfo) {
const astro = getAstroMetadata(modInfo); const astro = getAstroMetadata(modInfo);
if(astro) { if (astro) {
let metadata: SSRComponentMetadata = { let metadata: SSRComponentMetadata = {
containsHead: false, containsHead: false,
propagation: 'none' propagation: 'none',
}; };
if(astro.propagation) { if (astro.propagation) {
metadata.propagation = astro.propagation; metadata.propagation = astro.propagation;
} }
if(astro.containsHead) { if (astro.containsHead) {
metadata.containsHead = astro.containsHead; metadata.containsHead = astro.containsHead;
} }
map.set(modInfo.id, metadata); map.set(modInfo.id, metadata);

View file

@ -9,11 +9,7 @@ import type {
SSRLoadedRenderer, SSRLoadedRenderer,
SSRResult, SSRResult,
} from '../../@types/astro'; } from '../../@types/astro';
import { import { renderSlot, stringifyChunk, type ComponentSlots } from '../../runtime/server/index.js';
renderSlot,
stringifyChunk,
type ComponentSlots,
} from '../../runtime/server/index.js';
import { renderJSX } from '../../runtime/server/jsx.js'; import { renderJSX } from '../../runtime/server/jsx.js';
import { AstroCookies } from '../cookies/index.js'; import { AstroCookies } from '../cookies/index.js';
import { AstroError, AstroErrorData } from '../errors/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js';

View file

@ -48,7 +48,7 @@ export function isAPropagatingComponent(
factory: AstroComponentFactory factory: AstroComponentFactory
): boolean { ): boolean {
let hint: PropagationHint = factory.propagation || 'none'; let hint: PropagationHint = factory.propagation || 'none';
if(factory.moduleId && result.componentMetadata.has(factory.moduleId) && hint === 'none') { if (factory.moduleId && result.componentMetadata.has(factory.moduleId) && hint === 'none') {
hint = result.componentMetadata.get(factory.moduleId)!.propagation; hint = result.componentMetadata.get(factory.moduleId)!.propagation;
} }
return hint === 'in-tree' || hint === 'self'; return hint === 'in-tree' || hint === 'self';

View file

@ -83,7 +83,7 @@ export async function renderPage(
try { try {
if (nonAstroPageNeedsHeadInjection(componentFactory)) { if (nonAstroPageNeedsHeadInjection(componentFactory)) {
const parts = new HTMLParts(); const parts = new HTMLParts();
for await(const chunk of maybeRenderHead(result)) { for await (const chunk of maybeRenderHead(result)) {
parts.append(chunk, result); parts.append(chunk, result);
} }
head = parts.toString(); head = parts.toString();
@ -125,7 +125,8 @@ export async function renderPage(
} }
// Mark if this page component contains a <head> within its tree. If it does // Mark if this page component contains a <head> within its tree. If it does
// We avoid implicit head injection entirely. // We avoid implicit head injection entirely.
result._metadata.headInTree = result.componentMetadata.get(componentFactory.moduleId!)?.containsHead ?? false; result._metadata.headInTree =
result.componentMetadata.get(componentFactory.moduleId!)?.containsHead ?? false;
const factoryReturnValue = await componentFactory(result, props, children); const factoryReturnValue = await componentFactory(result, props, children);
const factoryIsHeadAndContent = isHeadAndContent(factoryReturnValue); const factoryIsHeadAndContent = isHeadAndContent(factoryReturnValue);
if (isRenderTemplateResult(factoryReturnValue) || factoryIsHeadAndContent) { if (isRenderTemplateResult(factoryReturnValue) || factoryIsHeadAndContent) {

View file

@ -1,6 +1,6 @@
import type * as vite from 'vite';
import type { ModuleInfo } from 'rollup'; import type { ModuleInfo } from 'rollup';
import type { AstroSettings, SSRResult, SSRComponentMetadata } from '../@types/astro'; import type * as vite from 'vite';
import type { AstroSettings, SSRComponentMetadata, SSRResult } from '../@types/astro';
import type { AstroBuildPlugin } from '../core/build/plugin.js'; import type { AstroBuildPlugin } from '../core/build/plugin.js';
import type { StaticBuildOptions } from '../core/build/types'; import type { StaticBuildOptions } from '../core/build/types';
import type { PluginMetadata } from '../vite-plugin-astro/types'; import type { PluginMetadata } from '../vite-plugin-astro/types';
@ -21,26 +21,31 @@ export default function configHeadVitePlugin({
function propagateMetadata< function propagateMetadata<
P extends keyof PluginMetadata['astro'], P extends keyof PluginMetadata['astro'],
V extends PluginMetadata['astro'][P] V extends PluginMetadata['astro'][P]
>(this: { getModuleInfo(id: string): ModuleInfo | null }, id: string, prop: P, value: V, seen = new Set<string>()) { >(
if(seen.has(id)) return; this: { getModuleInfo(id: string): ModuleInfo | null },
id: string,
prop: P,
value: V,
seen = new Set<string>()
) {
if (seen.has(id)) return;
seen.add(id); seen.add(id);
const mod = server.moduleGraph.getModuleById(id); const mod = server.moduleGraph.getModuleById(id);
const info = this.getModuleInfo(id); const info = this.getModuleInfo(id);
if (info?.meta.astro) { if (info?.meta.astro) {
const astroMetadata = getAstroMetadata(info) const astroMetadata = getAstroMetadata(info);
if(astroMetadata) { if (astroMetadata) {
Reflect.set(astroMetadata, prop, value); Reflect.set(astroMetadata, prop, value);
} }
} }
for (const parent of mod?.importers || []) { for (const parent of mod?.importers || []) {
if(parent.id) { if (parent.id) {
propagateMetadata.call(this, parent.id, prop, value, seen); propagateMetadata.call(this, parent.id, prop, value, seen);
} }
} }
} }
return { return {
name: 'astro:head-metadata', name: 'astro:head-metadata',
configureServer(_server) { configureServer(_server) {
@ -52,7 +57,7 @@ export default function configHeadVitePlugin({
} }
let info = this.getModuleInfo(id); let info = this.getModuleInfo(id);
if(info && getAstroMetadata(info)?.containsHead) { if (info && getAstroMetadata(info)?.containsHead) {
propagateMetadata.call(this, id, 'containsHead', true); propagateMetadata.call(this, id, 'containsHead', true);
} }
@ -77,23 +82,23 @@ export function astroHeadBuildPlugin(
generateBundle(_opts, bundle) { generateBundle(_opts, bundle) {
const map: SSRResult['componentMetadata'] = internals.componentMetadata; const map: SSRResult['componentMetadata'] = internals.componentMetadata;
function getOrCreateMetadata(id: string): SSRComponentMetadata { function getOrCreateMetadata(id: string): SSRComponentMetadata {
if(map.has(id)) return map.get(id)!; if (map.has(id)) return map.get(id)!;
const metadata: SSRComponentMetadata = { const metadata: SSRComponentMetadata = {
propagation: 'none', propagation: 'none',
containsHead: false containsHead: false,
}; };
map.set(id, metadata); map.set(id, metadata);
return metadata; return metadata;
} }
for (const [,output] of Object.entries(bundle)) { for (const [, output] of Object.entries(bundle)) {
if (output.type !== 'chunk') continue; if (output.type !== 'chunk') continue;
for (const [id, mod] of Object.entries(output.modules)) { for (const [id, mod] of Object.entries(output.modules)) {
const modinfo = this.getModuleInfo(id); const modinfo = this.getModuleInfo(id);
// <head> tag in the tree // <head> tag in the tree
if(modinfo && getAstroMetadata(modinfo)?.containsHead) { if (modinfo && getAstroMetadata(modinfo)?.containsHead) {
for(const [pageInfo] of getTopLevelPages(id, this)) { for (const [pageInfo] of getTopLevelPages(id, this)) {
let metadata = getOrCreateMetadata(pageInfo.id); let metadata = getOrCreateMetadata(pageInfo.id);
metadata.containsHead = true; metadata.containsHead = true;
} }