[ci] format
This commit is contained in:
parent
4916b733c2
commit
f6cdf1202e
11 changed files with 60 additions and 76 deletions
|
@ -10,7 +10,7 @@ declare global {
|
|||
media: DirectiveLoader;
|
||||
only: DirectiveLoader;
|
||||
visible: DirectiveLoader;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,4 +9,4 @@
|
|||
} else {
|
||||
setTimeout(cb, 200);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,5 +4,3 @@
|
|||
await hydrate();
|
||||
})();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,3 @@
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,3 @@
|
|||
await hydrate();
|
||||
})();
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ declare const Astro: {
|
|||
opts: Record<string, any>,
|
||||
root: HTMLElement
|
||||
) => void;
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
interface PropTypeSelector {
|
||||
|
@ -45,7 +45,8 @@ declare const Astro: {
|
|||
window.addEventListener('astro:hydrate', this.hydrate);
|
||||
await import(this.getAttribute('before-hydration-url')!);
|
||||
const opts = JSON.parse(this.getAttribute('opts')!) as Record<string, any>;
|
||||
Astro[this.getAttribute('client') as directiveAstroKeys](async () => {
|
||||
Astro[this.getAttribute('client') as directiveAstroKeys](
|
||||
async () => {
|
||||
const rendererUrl = this.getAttribute('renderer-url');
|
||||
const [componentModule, { default: hydrator }] = await Promise.all([
|
||||
import(this.getAttribute('component-url')!),
|
||||
|
@ -54,7 +55,10 @@ declare const Astro: {
|
|||
this.Component = componentModule[this.getAttribute('component-export') || 'default'];
|
||||
this.hydrator = hydrator;
|
||||
return this.hydrate;
|
||||
}, opts, this);
|
||||
},
|
||||
opts,
|
||||
this
|
||||
);
|
||||
}
|
||||
hydrate = () => {
|
||||
if (!this.hydrator || this.parentElement?.closest('astro-island[ssr]')) {
|
||||
|
|
|
@ -11,14 +11,14 @@ import type {
|
|||
|
||||
import { escapeHTML, HTMLString, markHTMLString } from './escape.js';
|
||||
import { extractDirectives, generateHydrateScript } from './hydration.js';
|
||||
import { serializeProps } from './serialize.js';
|
||||
import { shorthash } from './shorthash.js';
|
||||
import {
|
||||
determineIfNeedsHydrationScript,
|
||||
determinesIfNeedsDirectiveScript,
|
||||
getPrescripts,
|
||||
PrescriptType,
|
||||
getPrescripts
|
||||
} from './scripts.js';
|
||||
import { serializeProps } from './serialize.js';
|
||||
import { shorthash } from './shorthash.js';
|
||||
import { serializeListValue } from './util.js';
|
||||
|
||||
export { markHTMLString, markHTMLString as unescapeHTML } from './escape.js';
|
||||
|
@ -33,7 +33,6 @@ const htmlEnumAttributes = /^(contenteditable|draggable|spellcheck|value)$/i;
|
|||
// Note: SVG is case-sensitive!
|
||||
const svgEnumAttributes = /^(autoReverse|externalResourcesRequired|focusable|preserveAlpha)$/i;
|
||||
|
||||
|
||||
// INVESTIGATE:
|
||||
// 2. Less anys when possible and make it well known when they are needed.
|
||||
|
||||
|
@ -152,7 +151,6 @@ function formatList(values: string[]): string {
|
|||
return `${values.slice(0, -1).join(', ')} or ${values[values.length - 1]}`;
|
||||
}
|
||||
|
||||
|
||||
export async function renderComponent(
|
||||
result: SSRResult,
|
||||
displayName: string,
|
||||
|
@ -186,7 +184,8 @@ export async function renderComponent(
|
|||
const { hydration, props } = extractDirectives(_props);
|
||||
let html = '';
|
||||
let needsHydrationScript = hydration && determineIfNeedsHydrationScript(result);
|
||||
let needsDirectiveScript = hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
|
||||
let needsDirectiveScript =
|
||||
hydration && determinesIfNeedsDirectiveScript(result, hydration.directive);
|
||||
|
||||
if (hydration) {
|
||||
metadata.hydrate = hydration.directive as AstroComponentMetadata['hydrate'];
|
||||
|
@ -344,8 +343,11 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
|
|||
|
||||
island.children = `${html ?? ''}${template}`;
|
||||
|
||||
let prescriptType: PrescriptType = needsHydrationScript ? 'both' : needsDirectiveScript ?
|
||||
'directive' : null;
|
||||
let prescriptType: PrescriptType = needsHydrationScript
|
||||
? 'both'
|
||||
: needsDirectiveScript
|
||||
? 'directive'
|
||||
: null;
|
||||
let prescripts = getPrescripts(prescriptType, hydration.directive);
|
||||
|
||||
return markHTMLString(prescripts + renderElement('astro-island', island, false));
|
||||
|
|
|
@ -1,21 +1,11 @@
|
|||
import type {
|
||||
APIContext,
|
||||
AstroComponentMetadata,
|
||||
AstroGlobalPartial,
|
||||
EndpointHandler,
|
||||
Params,
|
||||
SSRElement,
|
||||
SSRLoadedRenderer,
|
||||
SSRResult,
|
||||
} from '../../@types/astro';
|
||||
import type { SSRResult } from '../../@types/astro';
|
||||
|
||||
import islandScript from './astro-island.prebuilt.js';
|
||||
import idlePrebuilt from '../client/idle.prebuilt.js';
|
||||
import loadPrebuilt from '../client/load.prebuilt.js';
|
||||
import mediaPrebuilt from '../client/media.prebuilt.js';
|
||||
import onlyPrebuilt from '../client/only.prebuilt.js';
|
||||
import visiblePrebuilt from '../client/visible.prebuilt.js';
|
||||
import mediaPrebuilt from '../client/media.prebuilt.js';
|
||||
|
||||
import islandScript from './astro-island.prebuilt.js';
|
||||
|
||||
// This is used to keep track of which requests (pages) have had the hydration script
|
||||
// appended. We only add the hydration script once per page, and since the SSRResult
|
||||
|
@ -35,7 +25,7 @@ export const hydrationScripts: Record<string, string> = {
|
|||
load: loadPrebuilt,
|
||||
only: onlyPrebuilt,
|
||||
media: mediaPrebuilt,
|
||||
visible: visiblePrebuilt
|
||||
visible: visiblePrebuilt,
|
||||
};
|
||||
|
||||
const resultsWithDirectiveScript = new Map<string, WeakSet<SSRResult>>();
|
||||
|
@ -52,8 +42,6 @@ export function determinesIfNeedsDirectiveScript(result: SSRResult, directive: s
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export type PrescriptType = null | 'both' | 'directive';
|
||||
|
||||
function getDirectiveScriptText(directive: string): string {
|
||||
|
@ -71,7 +59,6 @@ export function getPrescripts(type: PrescriptType, directive: string): string {
|
|||
// deps to be loaded immediately.
|
||||
switch (type) {
|
||||
case 'both':
|
||||
|
||||
return `<script>${getDirectiveScriptText(directive) + islandScript}</script>`;
|
||||
case 'directive':
|
||||
return `<script>${getDirectiveScriptText(directive)}</script>`;
|
||||
|
|
Loading…
Reference in a new issue