Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
96
node_modules/astro/dist/runtime/server/render/common.js
generated
vendored
Normal file
96
node_modules/astro/dist/runtime/server/render/common.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
import { markHTMLString } from "../escape.js";
|
||||
import {
|
||||
determineIfNeedsHydrationScript,
|
||||
determinesIfNeedsDirectiveScript,
|
||||
getPrescripts
|
||||
} from "../scripts.js";
|
||||
import { renderAllHeadContent } from "./head.js";
|
||||
import { isRenderInstruction } from "./instruction.js";
|
||||
import { isSlotString } from "./slot.js";
|
||||
const Fragment = Symbol.for("astro:fragment");
|
||||
const Renderer = Symbol.for("astro:renderer");
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
function stringifyChunk(result, chunk) {
|
||||
if (isRenderInstruction(chunk)) {
|
||||
const instruction = chunk;
|
||||
switch (instruction.type) {
|
||||
case "directive": {
|
||||
const { hydration } = instruction;
|
||||
let needsHydrationScript = hydration && determineIfNeedsHydrationScript(result);
|
||||
let needsDirectiveScript = hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
|
||||
let prescriptType = needsHydrationScript ? "both" : needsDirectiveScript ? "directive" : null;
|
||||
if (prescriptType) {
|
||||
let prescripts = getPrescripts(result, prescriptType, hydration.directive);
|
||||
return markHTMLString(prescripts);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
case "head": {
|
||||
if (result._metadata.hasRenderedHead || result.partial) {
|
||||
return "";
|
||||
}
|
||||
return renderAllHeadContent(result);
|
||||
}
|
||||
case "maybe-head": {
|
||||
if (result._metadata.hasRenderedHead || result._metadata.headInTree || result.partial) {
|
||||
return "";
|
||||
}
|
||||
return renderAllHeadContent(result);
|
||||
}
|
||||
case "renderer-hydration-script": {
|
||||
const { rendererSpecificHydrationScripts } = result._metadata;
|
||||
const { rendererName } = instruction;
|
||||
if (!rendererSpecificHydrationScripts.has(rendererName)) {
|
||||
rendererSpecificHydrationScripts.add(rendererName);
|
||||
return instruction.render();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown chunk type: ${chunk.type}`);
|
||||
}
|
||||
}
|
||||
} else if (chunk instanceof Response) {
|
||||
return "";
|
||||
} else if (isSlotString(chunk)) {
|
||||
let out = "";
|
||||
const c = chunk;
|
||||
if (c.instructions) {
|
||||
for (const instr of c.instructions) {
|
||||
out += stringifyChunk(result, instr);
|
||||
}
|
||||
}
|
||||
out += chunk.toString();
|
||||
return out;
|
||||
}
|
||||
return chunk.toString();
|
||||
}
|
||||
function chunkToString(result, chunk) {
|
||||
if (ArrayBuffer.isView(chunk)) {
|
||||
return decoder.decode(chunk);
|
||||
} else {
|
||||
return stringifyChunk(result, chunk);
|
||||
}
|
||||
}
|
||||
function chunkToByteArray(result, chunk) {
|
||||
if (ArrayBuffer.isView(chunk)) {
|
||||
return chunk;
|
||||
} else {
|
||||
const stringified = stringifyChunk(result, chunk);
|
||||
return encoder.encode(stringified.toString());
|
||||
}
|
||||
}
|
||||
function isRenderInstance(obj) {
|
||||
return !!obj && typeof obj === "object" && "render" in obj && typeof obj.render === "function";
|
||||
}
|
||||
export {
|
||||
Fragment,
|
||||
Renderer,
|
||||
chunkToByteArray,
|
||||
chunkToString,
|
||||
decoder,
|
||||
encoder,
|
||||
isRenderInstance
|
||||
};
|
Reference in New Issue
Block a user