[ci] format
This commit is contained in:
parent
999250d651
commit
c01194b9d8
4 changed files with 25 additions and 12 deletions
|
@ -302,7 +302,10 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
|
||||||
|
|
||||||
// Include componentExport name, componentUrl, and props in hash to dedupe identical islands
|
// Include componentExport name, componentUrl, and props in hash to dedupe identical islands
|
||||||
const astroId = shorthash(
|
const astroId = shorthash(
|
||||||
`<!--${metadata.componentExport!.value}:${metadata.componentUrl}-->\n${html}\n${serializeProps(props, metadata)}`
|
`<!--${metadata.componentExport!.value}:${metadata.componentUrl}-->\n${html}\n${serializeProps(
|
||||||
|
props,
|
||||||
|
metadata
|
||||||
|
)}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const island = await generateHydrateScript(
|
const island = await generateHydrateScript(
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import type {
|
import type { AstroComponentMetadata } from '../../@types/astro';
|
||||||
AstroComponentMetadata,
|
|
||||||
} from '../../@types/astro';
|
|
||||||
|
|
||||||
type ValueOf<T> = T[keyof T];
|
type ValueOf<T> = T[keyof T];
|
||||||
|
|
||||||
|
@ -19,11 +17,14 @@ function serializeArray(value: any[], metadata: AstroComponentMetadata): any[] {
|
||||||
return value.map((v) => convertToSerializedForm(v, metadata));
|
return value.map((v) => convertToSerializedForm(v, metadata));
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeObject(value: Record<any, any>, metadata: AstroComponentMetadata): Record<any, any> {
|
function serializeObject(
|
||||||
|
value: Record<any, any>,
|
||||||
|
metadata: AstroComponentMetadata
|
||||||
|
): Record<any, any> {
|
||||||
if (cyclicRefs.has(value)) {
|
if (cyclicRefs.has(value)) {
|
||||||
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
|
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
|
||||||
|
|
||||||
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`)
|
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
|
||||||
}
|
}
|
||||||
cyclicRefs.add(value);
|
cyclicRefs.add(value);
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
|
@ -33,7 +34,10 @@ Cyclic references cannot be safely serialized for client-side usage. Please remo
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToSerializedForm(value: any, metadata: AstroComponentMetadata): [ValueOf<typeof PROP_TYPE>, any] {
|
function convertToSerializedForm(
|
||||||
|
value: any,
|
||||||
|
metadata: AstroComponentMetadata
|
||||||
|
): [ValueOf<typeof PROP_TYPE>, any] {
|
||||||
const tag = Object.prototype.toString.call(value);
|
const tag = Object.prototype.toString.call(value);
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case '[object Date]': {
|
case '[object Date]': {
|
||||||
|
@ -43,10 +47,16 @@ function convertToSerializedForm(value: any, metadata: AstroComponentMetadata):
|
||||||
return [PROP_TYPE.RegExp, (value as RegExp).source];
|
return [PROP_TYPE.RegExp, (value as RegExp).source];
|
||||||
}
|
}
|
||||||
case '[object Map]': {
|
case '[object Map]': {
|
||||||
return [PROP_TYPE.Map, JSON.stringify(serializeArray(Array.from(value as Map<any, any>), metadata))];
|
return [
|
||||||
|
PROP_TYPE.Map,
|
||||||
|
JSON.stringify(serializeArray(Array.from(value as Map<any, any>), metadata)),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
case '[object Set]': {
|
case '[object Set]': {
|
||||||
return [PROP_TYPE.Set, JSON.stringify(serializeArray(Array.from(value as Set<any>), metadata))];
|
return [
|
||||||
|
PROP_TYPE.Set,
|
||||||
|
JSON.stringify(serializeArray(Array.from(value as Set<any>), metadata)),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
case '[object BigInt]': {
|
case '[object BigInt]': {
|
||||||
return [PROP_TYPE.BigInt, (value as bigint).toString()];
|
return [PROP_TYPE.BigInt, (value as bigint).toString()];
|
||||||
|
|
|
@ -120,7 +120,7 @@ async function handle500Response(
|
||||||
) {
|
) {
|
||||||
res.on('close', () => setTimeout(() => viteServer.ws.send(getViteErrorPayload(err)), 200));
|
res.on('close', () => setTimeout(() => viteServer.ws.send(getViteErrorPayload(err)), 200));
|
||||||
if (res.headersSent) {
|
if (res.headersSent) {
|
||||||
res.write(`<script type="module" src="/@vite/client"></script>`)
|
res.write(`<script type="module" src="/@vite/client"></script>`);
|
||||||
res.end();
|
res.end();
|
||||||
} else {
|
} else {
|
||||||
writeHtmlResponse(
|
writeHtmlResponse(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import "preact/debug"
|
import 'preact/debug';
|
||||||
import clientFn from "./client.js";
|
import clientFn from './client.js';
|
||||||
|
|
||||||
export default clientFn;
|
export default clientFn;
|
||||||
|
|
Loading…
Reference in a new issue