mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
[ci] format
This commit is contained in:
parent
45da39a864
commit
b558bd5140
9 changed files with 35 additions and 43 deletions
|
@ -1594,8 +1594,8 @@ export interface SSRMetadata {
|
|||
export type PropagationHint = 'none' | 'self' | 'in-tree';
|
||||
|
||||
export type SSRComponentMetadata = {
|
||||
propagation: PropagationHint,
|
||||
containsHead: boolean
|
||||
propagation: PropagationHint;
|
||||
containsHead: boolean;
|
||||
};
|
||||
|
||||
export interface SSRResult {
|
||||
|
|
|
@ -178,13 +178,7 @@ async function render({
|
|||
|
||||
return createHeadAndContent(
|
||||
unescapeHTML(styles + links + scripts) as any,
|
||||
renderTemplate`${renderComponent(
|
||||
result,
|
||||
'Content',
|
||||
mod.Content,
|
||||
props,
|
||||
slots
|
||||
)}`
|
||||
renderTemplate`${renderComponent(result, 'Content', mod.Content, props, slots)}`
|
||||
);
|
||||
},
|
||||
propagation: 'self',
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark';
|
||||
import type {
|
||||
ComponentInstance,
|
||||
SSRComponentMetadata,
|
||||
RouteData,
|
||||
SerializedRouteData,
|
||||
SSRComponentMetadata,
|
||||
SSRLoadedRenderer,
|
||||
SSRResult,
|
||||
} from '../../@types/astro';
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import type { GetModuleInfo, ModuleInfo } from 'rollup';
|
||||
import type { ViteDevServer } from 'vite';
|
||||
|
||||
import { resolvedPagesVirtualModuleId } from '../app/index.js';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -24,21 +24,18 @@ export async function getComponentMetadata(
|
|||
return map;
|
||||
}
|
||||
|
||||
function addMetadata(
|
||||
map: SSRResult['componentMetadata'],
|
||||
modInfo: ModuleInfo | null
|
||||
) {
|
||||
function addMetadata(map: SSRResult['componentMetadata'], modInfo: ModuleInfo | null) {
|
||||
if (modInfo) {
|
||||
const astro = getAstroMetadata(modInfo);
|
||||
if(astro) {
|
||||
if (astro) {
|
||||
let metadata: SSRComponentMetadata = {
|
||||
containsHead: false,
|
||||
propagation: 'none'
|
||||
propagation: 'none',
|
||||
};
|
||||
if(astro.propagation) {
|
||||
if (astro.propagation) {
|
||||
metadata.propagation = astro.propagation;
|
||||
}
|
||||
if(astro.containsHead) {
|
||||
if (astro.containsHead) {
|
||||
metadata.containsHead = astro.containsHead;
|
||||
}
|
||||
map.set(modInfo.id, metadata);
|
||||
|
|
|
@ -9,11 +9,7 @@ import type {
|
|||
SSRLoadedRenderer,
|
||||
SSRResult,
|
||||
} from '../../@types/astro';
|
||||
import {
|
||||
renderSlot,
|
||||
stringifyChunk,
|
||||
type ComponentSlots,
|
||||
} from '../../runtime/server/index.js';
|
||||
import { renderSlot, stringifyChunk, type ComponentSlots } from '../../runtime/server/index.js';
|
||||
import { renderJSX } from '../../runtime/server/jsx.js';
|
||||
import { AstroCookies } from '../cookies/index.js';
|
||||
import { AstroError, AstroErrorData } from '../errors/index.js';
|
||||
|
|
|
@ -48,7 +48,7 @@ export function isAPropagatingComponent(
|
|||
factory: AstroComponentFactory
|
||||
): boolean {
|
||||
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;
|
||||
}
|
||||
return hint === 'in-tree' || hint === 'self';
|
||||
|
|
|
@ -83,7 +83,7 @@ export async function renderPage(
|
|||
try {
|
||||
if (nonAstroPageNeedsHeadInjection(componentFactory)) {
|
||||
const parts = new HTMLParts();
|
||||
for await(const chunk of maybeRenderHead(result)) {
|
||||
for await (const chunk of maybeRenderHead(result)) {
|
||||
parts.append(chunk, result);
|
||||
}
|
||||
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
|
||||
// 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 factoryIsHeadAndContent = isHeadAndContent(factoryReturnValue);
|
||||
if (isRenderTemplateResult(factoryReturnValue) || factoryIsHeadAndContent) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type * as vite from 'vite';
|
||||
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 { StaticBuildOptions } from '../core/build/types';
|
||||
import type { PluginMetadata } from '../vite-plugin-astro/types';
|
||||
|
@ -21,26 +21,31 @@ export default function configHeadVitePlugin({
|
|||
function propagateMetadata<
|
||||
P extends keyof PluginMetadata['astro'],
|
||||
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);
|
||||
const mod = server.moduleGraph.getModuleById(id);
|
||||
const info = this.getModuleInfo(id);
|
||||
if (info?.meta.astro) {
|
||||
const astroMetadata = getAstroMetadata(info)
|
||||
if(astroMetadata) {
|
||||
const astroMetadata = getAstroMetadata(info);
|
||||
if (astroMetadata) {
|
||||
Reflect.set(astroMetadata, prop, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const parent of mod?.importers || []) {
|
||||
if(parent.id) {
|
||||
if (parent.id) {
|
||||
propagateMetadata.call(this, parent.id, prop, value, seen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
name: 'astro:head-metadata',
|
||||
configureServer(_server) {
|
||||
|
@ -52,7 +57,7 @@ export default function configHeadVitePlugin({
|
|||
}
|
||||
|
||||
let info = this.getModuleInfo(id);
|
||||
if(info && getAstroMetadata(info)?.containsHead) {
|
||||
if (info && getAstroMetadata(info)?.containsHead) {
|
||||
propagateMetadata.call(this, id, 'containsHead', true);
|
||||
}
|
||||
|
||||
|
@ -77,23 +82,23 @@ export function astroHeadBuildPlugin(
|
|||
generateBundle(_opts, bundle) {
|
||||
const map: SSRResult['componentMetadata'] = internals.componentMetadata;
|
||||
function getOrCreateMetadata(id: string): SSRComponentMetadata {
|
||||
if(map.has(id)) return map.get(id)!;
|
||||
if (map.has(id)) return map.get(id)!;
|
||||
const metadata: SSRComponentMetadata = {
|
||||
propagation: 'none',
|
||||
containsHead: false
|
||||
containsHead: false,
|
||||
};
|
||||
map.set(id, metadata);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
for (const [,output] of Object.entries(bundle)) {
|
||||
for (const [, output] of Object.entries(bundle)) {
|
||||
if (output.type !== 'chunk') continue;
|
||||
for (const [id, mod] of Object.entries(output.modules)) {
|
||||
const modinfo = this.getModuleInfo(id);
|
||||
|
||||
// <head> tag in the tree
|
||||
if(modinfo && getAstroMetadata(modinfo)?.containsHead) {
|
||||
for(const [pageInfo] of getTopLevelPages(id, this)) {
|
||||
if (modinfo && getAstroMetadata(modinfo)?.containsHead) {
|
||||
for (const [pageInfo] of getTopLevelPages(id, this)) {
|
||||
let metadata = getOrCreateMetadata(pageInfo.id);
|
||||
metadata.containsHead = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue