astro 5.6.1 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +3 -0
- package/components/Font.astro +32 -0
- package/dist/actions/plugins.js +2 -2
- package/dist/assets/fonts/config.d.ts +378 -0
- package/dist/assets/fonts/config.js +157 -0
- package/dist/assets/fonts/constants.d.ts +15 -0
- package/dist/assets/fonts/constants.js +41 -0
- package/dist/assets/fonts/load.d.ts +20 -0
- package/dist/assets/fonts/load.js +133 -0
- package/dist/assets/fonts/metrics.d.ts +10 -0
- package/dist/assets/fonts/metrics.js +84 -0
- package/dist/assets/fonts/providers/entrypoints/adobe.d.ts +2 -0
- package/dist/assets/fonts/providers/entrypoints/adobe.js +5 -0
- package/dist/assets/fonts/providers/entrypoints/bunny.d.ts +1 -0
- package/dist/assets/fonts/providers/entrypoints/bunny.js +5 -0
- package/dist/assets/fonts/providers/entrypoints/fontshare.d.ts +1 -0
- package/dist/assets/fonts/providers/entrypoints/fontshare.js +5 -0
- package/dist/assets/fonts/providers/entrypoints/fontsource.d.ts +1 -0
- package/dist/assets/fonts/providers/entrypoints/fontsource.js +5 -0
- package/dist/assets/fonts/providers/entrypoints/google.d.ts +2 -0
- package/dist/assets/fonts/providers/entrypoints/google.js +5 -0
- package/dist/assets/fonts/providers/index.d.ts +48 -0
- package/dist/assets/fonts/providers/index.js +40 -0
- package/dist/assets/fonts/providers/local.d.ts +10 -0
- package/dist/assets/fonts/providers/local.js +30 -0
- package/dist/assets/fonts/providers/utils.d.ts +9 -0
- package/dist/assets/fonts/providers/utils.js +37 -0
- package/dist/assets/fonts/sync.d.ts +2 -0
- package/dist/assets/fonts/sync.js +17 -0
- package/dist/assets/fonts/types.d.ts +45 -0
- package/dist/assets/fonts/types.js +0 -0
- package/dist/assets/fonts/utils.d.ts +95 -0
- package/dist/assets/fonts/utils.js +215 -0
- package/dist/assets/fonts/vite-plugin-fonts.d.ts +10 -0
- package/dist/assets/fonts/vite-plugin-fonts.js +217 -0
- package/dist/assets/utils/index.d.ts +5 -1
- package/dist/assets/utils/index.js +5 -1
- package/dist/assets/utils/node/emitAsset.d.ts +12 -2
- package/dist/assets/utils/node/emitAsset.js +46 -4
- package/dist/assets/utils/vendor/image-size/types/index.d.ts +2 -2
- package/dist/assets/vite-plugin-assets.d.ts +9 -2
- package/dist/assets/vite-plugin-assets.js +9 -6
- package/dist/cli/add/index.js +3 -1
- package/dist/cli/install-package.js +3 -0
- package/dist/config/entrypoint.d.ts +2 -0
- package/dist/config/entrypoint.js +3 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/content/content-layer.js +5 -4
- package/dist/content/runtime-assets.js +1 -0
- package/dist/content/utils.d.ts +10 -10
- package/dist/content/vite-plugin-content-imports.js +4 -2
- package/dist/core/build/generate.js +2 -2
- package/dist/core/build/pipeline.js +2 -2
- package/dist/core/build/plugins/plugin-prerender.js +0 -3
- package/dist/core/build/static-build.js +2 -2
- package/dist/core/config/schemas/base.d.ts +446 -49
- package/dist/core/config/schemas/base.js +3 -7
- package/dist/core/config/schemas/refined.js +12 -0
- package/dist/core/config/schemas/relative.d.ts +581 -77
- package/dist/core/config/schemas/relative.js +1 -2
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +2 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +82 -26
- package/dist/core/errors/errors-data.js +45 -16
- package/dist/core/logger/core.d.ts +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/vite-plugin.js +2 -2
- package/dist/core/render-context.js +39 -5
- package/dist/core/routing/rewrite.js +14 -5
- package/dist/core/session.d.ts +2 -4
- package/dist/core/session.js +4 -29
- package/dist/core/sync/index.js +2 -0
- package/dist/env/schema.d.ts +6 -6
- package/dist/integrations/hooks.js +2 -3
- package/dist/manifest/virtual-module.d.ts +1 -5
- package/dist/manifest/virtual-module.js +1 -18
- package/dist/prerender/utils.d.ts +5 -1
- package/dist/prerender/utils.js +8 -8
- package/dist/runtime/client/dev-toolbar/apps/audit/annotations.d.ts +6 -0
- package/dist/runtime/client/dev-toolbar/apps/audit/annotations.js +27 -0
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +10 -4
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +2 -2
- package/dist/runtime/server/render/common.js +8 -0
- package/dist/runtime/server/render/instruction.d.ts +5 -5
- package/dist/runtime/server/render/server-islands.d.ts +1 -0
- package/dist/runtime/server/render/server-islands.js +29 -31
- package/dist/transitions/swap-functions.d.ts +1 -1
- package/dist/transitions/swap-functions.js +7 -6
- package/dist/types/public/config.d.ts +155 -98
- package/dist/types/public/internal.d.ts +1 -0
- package/dist/vite-plugin-astro-server/plugin.js +1 -1
- package/package.json +9 -5
- package/types/fonts.d.ts +4 -0
|
@@ -11,7 +11,7 @@ import { buildClientDirectiveEntrypoint } from "../core/client-directive/index.j
|
|
|
11
11
|
import { mergeConfig } from "../core/config/index.js";
|
|
12
12
|
import { validateConfigRefined } from "../core/config/validate.js";
|
|
13
13
|
import { validateSetAdapter } from "../core/dev/adapter-validation.js";
|
|
14
|
-
import {
|
|
14
|
+
import { getClientOutputDirectory } from "../prerender/utils.js";
|
|
15
15
|
import { validateSupportedFeatures } from "./features-validation.js";
|
|
16
16
|
async function withTakingALongTimeMsg({
|
|
17
17
|
name,
|
|
@@ -310,7 +310,6 @@ async function runHookConfigDone({
|
|
|
310
310
|
})
|
|
311
311
|
});
|
|
312
312
|
}
|
|
313
|
-
validateSessionConfig(settings);
|
|
314
313
|
}
|
|
315
314
|
async function runHookServerSetup({
|
|
316
315
|
config,
|
|
@@ -446,7 +445,7 @@ async function runHookBuildGenerated({
|
|
|
446
445
|
}
|
|
447
446
|
}
|
|
448
447
|
async function runHookBuildDone({ settings, pages, routes, logger }) {
|
|
449
|
-
const dir = settings
|
|
448
|
+
const dir = getClientOutputDirectory(settings);
|
|
450
449
|
await fsMod.promises.mkdir(dir, { recursive: true });
|
|
451
450
|
const integrationRoutes = routes.map(toIntegrationRouteData);
|
|
452
451
|
for (const integration of settings.config.integrations) {
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import type { Logger } from '../core/logger/core.js';
|
|
3
|
-
import type { AstroSettings } from '../types/astro.js';
|
|
4
2
|
import type { SSRManifest } from '../types/public/index.js';
|
|
5
|
-
export default function virtualModulePlugin({
|
|
6
|
-
settings: AstroSettings;
|
|
3
|
+
export default function virtualModulePlugin({ manifest }: {
|
|
7
4
|
manifest: SSRManifest;
|
|
8
|
-
logger: Logger;
|
|
9
5
|
}): Plugin;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { CantUseAstroConfigModuleError } from "../core/errors/errors-data.js";
|
|
2
1
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
3
2
|
import { fromRoutingStrategy } from "../i18n/utils.js";
|
|
4
3
|
const VIRTUAL_SERVER_ID = "astro:config/server";
|
|
5
4
|
const RESOLVED_VIRTUAL_SERVER_ID = "\0" + VIRTUAL_SERVER_ID;
|
|
6
5
|
const VIRTUAL_CLIENT_ID = "astro:config/client";
|
|
7
6
|
const RESOLVED_VIRTUAL_CLIENT_ID = "\0" + VIRTUAL_CLIENT_ID;
|
|
8
|
-
function virtualModulePlugin({
|
|
9
|
-
settings,
|
|
10
|
-
manifest,
|
|
11
|
-
logger: _logger
|
|
12
|
-
}) {
|
|
7
|
+
function virtualModulePlugin({ manifest }) {
|
|
13
8
|
return {
|
|
14
9
|
enforce: "pre",
|
|
15
10
|
name: "astro-manifest-plugin",
|
|
@@ -22,20 +17,8 @@ function virtualModulePlugin({
|
|
|
22
17
|
},
|
|
23
18
|
load(id, opts) {
|
|
24
19
|
if (id === RESOLVED_VIRTUAL_CLIENT_ID) {
|
|
25
|
-
if (!settings.config.experimental.serializeConfig) {
|
|
26
|
-
throw new AstroError({
|
|
27
|
-
...CantUseAstroConfigModuleError,
|
|
28
|
-
message: CantUseAstroConfigModuleError.message(VIRTUAL_CLIENT_ID)
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
20
|
return { code: serializeClientConfig(manifest) };
|
|
32
21
|
} else if (id == RESOLVED_VIRTUAL_SERVER_ID) {
|
|
33
|
-
if (!settings.config.experimental.serializeConfig) {
|
|
34
|
-
throw new AstroError({
|
|
35
|
-
...CantUseAstroConfigModuleError,
|
|
36
|
-
message: CantUseAstroConfigModuleError.message(VIRTUAL_SERVER_ID)
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
22
|
if (!opts?.ssr) {
|
|
40
23
|
throw new AstroError({
|
|
41
24
|
...AstroErrorData.ServerOnlyModule,
|
|
@@ -4,4 +4,8 @@ export declare function getPrerenderDefault(config: AstroConfig): boolean;
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns the correct output directory of the SSR build based on the configuration
|
|
6
6
|
*/
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function getServerOutputDirectory(settings: AstroSettings): URL;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the correct output directory of the client build based on the configuration
|
|
10
|
+
*/
|
|
11
|
+
export declare function getClientOutputDirectory(settings: AstroSettings): URL;
|
package/dist/prerender/utils.js
CHANGED
|
@@ -2,14 +2,14 @@ import { getOutDirWithinCwd } from "../core/build/common.js";
|
|
|
2
2
|
function getPrerenderDefault(config) {
|
|
3
3
|
return config.output !== "server";
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
5
|
+
function getServerOutputDirectory(settings) {
|
|
6
|
+
return settings.buildOutput === "server" ? settings.config.build.server : getOutDirWithinCwd(settings.config.outDir);
|
|
7
|
+
}
|
|
8
|
+
function getClientOutputDirectory(settings) {
|
|
9
|
+
return settings.buildOutput === "server" ? settings.config.build.client : settings.config.outDir;
|
|
11
10
|
}
|
|
12
11
|
export {
|
|
13
|
-
|
|
14
|
-
getPrerenderDefault
|
|
12
|
+
getClientOutputDirectory,
|
|
13
|
+
getPrerenderDefault,
|
|
14
|
+
getServerOutputDirectory
|
|
15
15
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const ELEMENT_ANNOTATIONS = /* @__PURE__ */ new WeakMap();
|
|
2
|
+
function getAnnotationsForElement(element) {
|
|
3
|
+
return ELEMENT_ANNOTATIONS.get(element);
|
|
4
|
+
}
|
|
5
|
+
const ANNOTATION_MAP = {
|
|
6
|
+
"data-astro-source-file": "file",
|
|
7
|
+
"data-astro-source-loc": "location"
|
|
8
|
+
};
|
|
9
|
+
function extractAnnotations(element) {
|
|
10
|
+
const annotations = {};
|
|
11
|
+
for (const [attr, key] of Object.entries(ANNOTATION_MAP)) {
|
|
12
|
+
annotations[key] = element.getAttribute(attr);
|
|
13
|
+
}
|
|
14
|
+
for (const attr of Object.keys(ANNOTATION_MAP)) {
|
|
15
|
+
element.removeAttribute(attr);
|
|
16
|
+
}
|
|
17
|
+
return annotations;
|
|
18
|
+
}
|
|
19
|
+
function processAnnotations() {
|
|
20
|
+
for (const element of document.querySelectorAll(`[data-astro-source-file]`)) {
|
|
21
|
+
ELEMENT_ANNOTATIONS.set(element, extractAnnotations(element));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
getAnnotationsForElement,
|
|
26
|
+
processAnnotations
|
|
27
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { settings } from "../../settings.js";
|
|
2
2
|
import { positionHighlight } from "../utils/highlight.js";
|
|
3
3
|
import { closeOnOutsideClick } from "../utils/window.js";
|
|
4
|
+
import { processAnnotations } from "./annotations.js";
|
|
4
5
|
import { rulesCategories } from "./rules/index.js";
|
|
5
6
|
import { DevToolbarAuditListItem } from "./ui/audit-list-item.js";
|
|
6
7
|
import { DevToolbarAuditListWindow } from "./ui/audit-list-window.js";
|
|
@@ -22,8 +23,9 @@ var audit_default = {
|
|
|
22
23
|
"astro-dev-toolbar-audit-window"
|
|
23
24
|
);
|
|
24
25
|
let hasCreatedUI = false;
|
|
26
|
+
auditWindow.popover = "";
|
|
25
27
|
canvas.appendChild(auditWindow);
|
|
26
|
-
await
|
|
28
|
+
await run();
|
|
27
29
|
let mutationDebounce;
|
|
28
30
|
const observer = new MutationObserver(() => {
|
|
29
31
|
if (mutationDebounce) {
|
|
@@ -34,7 +36,7 @@ var audit_default = {
|
|
|
34
36
|
if ("requestIdleCallback" in window) {
|
|
35
37
|
window.requestIdleCallback(
|
|
36
38
|
async () => {
|
|
37
|
-
|
|
39
|
+
run().then(() => {
|
|
38
40
|
if (showState) createAuditsUI();
|
|
39
41
|
});
|
|
40
42
|
},
|
|
@@ -42,7 +44,7 @@ var audit_default = {
|
|
|
42
44
|
);
|
|
43
45
|
} else {
|
|
44
46
|
setTimeout(async () => {
|
|
45
|
-
|
|
47
|
+
run().then(() => {
|
|
46
48
|
if (showState) createAuditsUI();
|
|
47
49
|
});
|
|
48
50
|
}, 150);
|
|
@@ -54,7 +56,7 @@ var audit_default = {
|
|
|
54
56
|
observer.disconnect();
|
|
55
57
|
});
|
|
56
58
|
document.addEventListener("astro:after-swap", async () => {
|
|
57
|
-
|
|
59
|
+
run();
|
|
58
60
|
});
|
|
59
61
|
document.addEventListener("astro:page-load", async () => {
|
|
60
62
|
refreshLintPositions();
|
|
@@ -93,6 +95,10 @@ var audit_default = {
|
|
|
93
95
|
canvas.appendChild(fragment);
|
|
94
96
|
hasCreatedUI = true;
|
|
95
97
|
}
|
|
98
|
+
async function run() {
|
|
99
|
+
processAnnotations();
|
|
100
|
+
await lint();
|
|
101
|
+
}
|
|
96
102
|
async function lint() {
|
|
97
103
|
if (audits.length > 0) {
|
|
98
104
|
audits.forEach((audit) => {
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
createHighlight,
|
|
5
5
|
getElementsPositionInDocument
|
|
6
6
|
} from "../../utils/highlight.js";
|
|
7
|
+
import { getAnnotationsForElement } from "../annotations.js";
|
|
7
8
|
import { resolveAuditRule } from "../rules/index.js";
|
|
8
9
|
function truncate(val, maxLength) {
|
|
9
10
|
return val.length > maxLength ? val.slice(0, maxLength - 1) + "…" : val;
|
|
@@ -50,8 +51,7 @@ function buildAuditTooltip(rule, element) {
|
|
|
50
51
|
content: escapeHTML(message)
|
|
51
52
|
}
|
|
52
53
|
];
|
|
53
|
-
const elementFile = element
|
|
54
|
-
const elementPosition = element.getAttribute("data-astro-source-loc");
|
|
54
|
+
const { file: elementFile, location: elementPosition } = getAnnotationsForElement(element) ?? {};
|
|
55
55
|
if (elementFile) {
|
|
56
56
|
const elementFileWithPosition = elementFile + (elementPosition ? ":" + elementPosition : "");
|
|
57
57
|
tooltip.sections.push({
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "../scripts.js";
|
|
7
7
|
import { renderAllHeadContent } from "./head.js";
|
|
8
8
|
import { isRenderInstruction } from "./instruction.js";
|
|
9
|
+
import { renderServerIslandRuntime } from "./server-islands.js";
|
|
9
10
|
import { isSlotString } from "./slot.js";
|
|
10
11
|
const Fragment = Symbol.for("astro:fragment");
|
|
11
12
|
const Renderer = Symbol.for("astro:renderer");
|
|
@@ -48,6 +49,13 @@ function stringifyChunk(result, chunk) {
|
|
|
48
49
|
}
|
|
49
50
|
return "";
|
|
50
51
|
}
|
|
52
|
+
case "server-island-runtime": {
|
|
53
|
+
if (result._metadata.hasRenderedServerIslandRuntime) {
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
result._metadata.hasRenderedServerIslandRuntime = true;
|
|
57
|
+
return renderServerIslandRuntime();
|
|
58
|
+
}
|
|
51
59
|
default: {
|
|
52
60
|
throw new Error(`Unknown chunk type: ${chunk.type}`);
|
|
53
61
|
}
|
|
@@ -18,9 +18,9 @@ export type RendererHydrationScriptInstruction = {
|
|
|
18
18
|
export type MaybeRenderHeadInstruction = {
|
|
19
19
|
type: 'maybe-head';
|
|
20
20
|
};
|
|
21
|
-
export type
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
export declare function createRenderInstruction(instruction:
|
|
21
|
+
export type ServerIslandRuntimeInstruction = {
|
|
22
|
+
type: 'server-island-runtime';
|
|
23
|
+
};
|
|
24
|
+
export type RenderInstruction = RenderDirectiveInstruction | RenderHeadInstruction | MaybeRenderHeadInstruction | RendererHydrationScriptInstruction | ServerIslandRuntimeInstruction;
|
|
25
|
+
export declare function createRenderInstruction<T extends RenderInstruction>(instruction: T): T;
|
|
26
26
|
export declare function isRenderInstruction(chunk: any): chunk is RenderInstruction;
|
|
@@ -3,3 +3,4 @@ import type { RenderInstance } from './common.js';
|
|
|
3
3
|
import { type ComponentSlots } from './slot.js';
|
|
4
4
|
export declare function containsServerDirective(props: Record<string | number, any>): boolean;
|
|
5
5
|
export declare function renderServerIsland(result: SSRResult, _displayName: string, props: Record<string | number, any>, slots: ComponentSlots): RenderInstance;
|
|
6
|
+
export declare const renderServerIslandRuntime: () => any;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { encryptString } from "../../../core/encryption.js";
|
|
2
|
+
import { markHTMLString } from "../escape.js";
|
|
2
3
|
import { renderChild } from "./any.js";
|
|
4
|
+
import { createRenderInstruction } from "./instruction.js";
|
|
3
5
|
import { renderSlotToString } from "./slot.js";
|
|
4
6
|
const internalProps = /* @__PURE__ */ new Set([
|
|
5
7
|
"server:component-path",
|
|
@@ -43,6 +45,7 @@ function renderServerIsland(result, _displayName, props, slots) {
|
|
|
43
45
|
delete props[key2];
|
|
44
46
|
}
|
|
45
47
|
}
|
|
48
|
+
destination.write(createRenderInstruction({ type: "server-island-runtime" }));
|
|
46
49
|
destination.write("<!--[if astro]>server-island-start<![endif]-->");
|
|
47
50
|
const renderedSlots = {};
|
|
48
51
|
for (const name in slots) {
|
|
@@ -70,13 +73,9 @@ function renderServerIsland(result, _displayName, props, slots) {
|
|
|
70
73
|
`<link rel="preload" as="fetch" href="${serverIslandUrl}" crossorigin="anonymous">`
|
|
71
74
|
);
|
|
72
75
|
}
|
|
73
|
-
destination.write(`<script
|
|
74
|
-
let script = document.querySelector('script[data-island-id="${hostId}"]');
|
|
75
|
-
|
|
76
|
-
${useGETRequest ? (
|
|
76
|
+
destination.write(`<script type="module" data-astro-rerun data-island-id="${hostId}">${useGETRequest ? (
|
|
77
77
|
// GET request
|
|
78
|
-
`let response = await fetch('${serverIslandUrl}')
|
|
79
|
-
`
|
|
78
|
+
`let response = await fetch('${serverIslandUrl}');`
|
|
80
79
|
) : (
|
|
81
80
|
// POST request
|
|
82
81
|
`let data = {
|
|
@@ -84,38 +83,37 @@ ${useGETRequest ? (
|
|
|
84
83
|
encryptedProps: ${safeJsonStringify(propsEncrypted)},
|
|
85
84
|
slots: ${safeJsonStringify(renderedSlots)},
|
|
86
85
|
};
|
|
87
|
-
|
|
88
86
|
let response = await fetch('${serverIslandUrl}', {
|
|
89
87
|
method: 'POST',
|
|
90
88
|
body: JSON.stringify(data),
|
|
91
|
-
})
|
|
92
|
-
`
|
|
89
|
+
});`
|
|
93
90
|
)}
|
|
94
|
-
|
|
95
|
-
if(
|
|
96
|
-
response.status === 200
|
|
97
|
-
&& response.headers.has('content-type')
|
|
98
|
-
&& response.headers.get('content-type').split(";")[0].trim() === 'text/html') {
|
|
99
|
-
let html = await response.text();
|
|
100
|
-
|
|
101
|
-
// Swap!
|
|
102
|
-
while(script.previousSibling &&
|
|
103
|
-
script.previousSibling.nodeType !== 8 &&
|
|
104
|
-
script.previousSibling.data !== '[if astro]>server-island-start<![endif]') {
|
|
105
|
-
script.previousSibling.remove();
|
|
106
|
-
}
|
|
107
|
-
script.previousSibling?.remove();
|
|
108
|
-
|
|
109
|
-
let frag = document.createRange().createContextualFragment(html);
|
|
110
|
-
script.before(frag);
|
|
111
|
-
}
|
|
112
|
-
script.remove(); // Prior to v5.4.2, this was the trick to force rerun of scripts. Keeping it to minimize change to the existing behavior.
|
|
113
|
-
}
|
|
114
|
-
</script>`);
|
|
91
|
+
replaceServerIsland('${hostId}', response);</script>`);
|
|
115
92
|
}
|
|
116
93
|
};
|
|
117
94
|
}
|
|
95
|
+
const renderServerIslandRuntime = () => markHTMLString(
|
|
96
|
+
`
|
|
97
|
+
<script>
|
|
98
|
+
async function replaceServerIsland(id, r) {
|
|
99
|
+
let s = document.querySelector(\`script[data-island-id="\${id}"]\`);
|
|
100
|
+
// If there's no matching script, or the request fails then return
|
|
101
|
+
if (!s || r.status !== 200 || r.headers.get('content-type')?.split(';')[0].trim() !== 'text/html') return;
|
|
102
|
+
// Load the HTML before modifying the DOM in case of errors
|
|
103
|
+
let html = await r.text();
|
|
104
|
+
// Remove any placeholder content before the island script
|
|
105
|
+
while (s.previousSibling && s.previousSibling.nodeType !== 8 && s.previousSibling.data !== '[if astro]>server-island-start<![endif]')
|
|
106
|
+
s.previousSibling.remove();
|
|
107
|
+
s.previousSibling?.remove();
|
|
108
|
+
// Insert the new HTML
|
|
109
|
+
s.before(document.createRange().createContextualFragment(html));
|
|
110
|
+
// Remove the script. Prior to v5.4.2, this was the trick to force rerun of scripts. Keeping it to minimize change to the existing behavior.
|
|
111
|
+
s.remove();
|
|
112
|
+
}
|
|
113
|
+
</script>`.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("//")).join(" ")
|
|
114
|
+
);
|
|
118
115
|
export {
|
|
119
116
|
containsServerDirective,
|
|
120
|
-
renderServerIsland
|
|
117
|
+
renderServerIsland,
|
|
118
|
+
renderServerIslandRuntime
|
|
121
119
|
};
|
|
@@ -5,7 +5,7 @@ export type SavedFocus = {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function detectScriptExecuted(script: HTMLScriptElement): boolean;
|
|
7
7
|
export declare function deselectScripts(doc: Document): void;
|
|
8
|
-
export declare function swapRootAttributes(
|
|
8
|
+
export declare function swapRootAttributes(newDoc: Document): void;
|
|
9
9
|
export declare function swapHeadElements(doc: Document): void;
|
|
10
10
|
export declare function swapBodyElement(newElement: Element, oldElement: Element): void;
|
|
11
11
|
export declare const saveFocus: () => (() => void);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const PERSIST_ATTR = "data-astro-transition-persist";
|
|
2
|
+
const NON_OVERRIDABLE_ASTRO_ATTRS = ["data-astro-transition", "data-astro-transition-fallback"];
|
|
2
3
|
const scriptsAlreadyRan = /* @__PURE__ */ new Set();
|
|
3
4
|
function detectScriptExecuted(script) {
|
|
4
5
|
const key = script.src ? new URL(script.src, location.href).href : script.textContent;
|
|
@@ -17,13 +18,13 @@ function deselectScripts(doc) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
function swapRootAttributes(
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
({ name }) => (
|
|
21
|
+
function swapRootAttributes(newDoc) {
|
|
22
|
+
const currentRoot = document.documentElement;
|
|
23
|
+
const nonOverridableAstroAttributes = [...currentRoot.attributes].filter(
|
|
24
|
+
({ name }) => (currentRoot.removeAttribute(name), NON_OVERRIDABLE_ASTRO_ATTRS.includes(name))
|
|
24
25
|
);
|
|
25
|
-
[...
|
|
26
|
-
({ name, value }) =>
|
|
26
|
+
[...newDoc.documentElement.attributes, ...nonOverridableAstroAttributes].forEach(
|
|
27
|
+
({ name, value }) => currentRoot.setAttribute(name, value)
|
|
27
28
|
);
|
|
28
29
|
}
|
|
29
30
|
function swapHeadElements(doc) {
|