Skip to content

Commit 29d87c2

Browse files
committed
perf(): generate modulepreload for mode
1 parent 2f664f0 commit 29d87c2

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

src/compiler/prerender/prerender-modulepreload.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { flatOne, unique } from '@utils';
33
import { getScopeId } from '../style/scope-css';
44
import {injectModulePreloads} from '../html/inject-module-preloads';
55

6-
export function generateModulePreloads(doc: Document, hydrateResults: d.HydrateResults, componnentGraph: Map<string, string[]>) {
7-
if (!componnentGraph) {
6+
export function generateModulePreloads(doc: Document, hydrateResults: d.HydrateResults, componentGraph: Map<string, string[]>) {
7+
if (!componentGraph) {
88
return false;
99
}
1010
const hasImportScript = !!doc.querySelector('script[type=module][data-resources-url]');
@@ -14,8 +14,8 @@ export function generateModulePreloads(doc: Document, hydrateResults: d.HydrateR
1414
const modulePreloads = unique(
1515
flatOne(
1616
hydrateResults.components
17-
.map(cmp => getScopeId(cmp.tag))
18-
.map(scopeId => componnentGraph.get(scopeId) || [])
17+
.map(cmp => getScopeId(cmp.tag, cmp.mode))
18+
.map(scopeId => componentGraph.get(scopeId) || [])
1919
)
2020
);
2121

src/declarations/hydrate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface HydrateResults {
5555

5656
export interface HydrateComponent {
5757
tag: string;
58+
mode: string;
5859
count: number;
5960
depth: number;
6061
}

src/hydrate/platform/bootstrap-hydrate.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { insertVdomAnnotations, postUpdateComponent } from '@runtime';
77
export function bootstrapHydrate(win: Window, opts: d.HydrateDocumentOptions, done: (results: BootstrapHydrateResults) => void) {
88
const results: BootstrapHydrateResults = {
99
hydratedCount: 0,
10-
hydratedTags: []
10+
hydratedComponents: []
1111
};
1212
plt.$resourcesUrl$ = new URL(opts.resourcesUrl || '/', win.location.href).href;
1313

@@ -168,5 +168,8 @@ const NO_HYDRATE_TAGS = new Set([
168168

169169
export interface BootstrapHydrateResults {
170170
hydratedCount: number;
171-
hydratedTags: string[];
171+
hydratedComponents: {
172+
tag: string,
173+
mode: string | undefined
174+
}[];
172175
}

src/hydrate/platform/hydrate-component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as d from '../../declarations';
2-
import { connectedCallback, getComponent, registerHost } from '@platform';
2+
import { connectedCallback, getComponent, getHostRef, registerHost } from '@platform';
33
import { proxyHostElement } from './proxy-host-element';
44
import { BootstrapHydrateResults } from './bootstrap-hydrate';
55

@@ -21,10 +21,14 @@ export function hydrateComponent(win: Window, results: BootstrapHydrateResults,
2121

2222
results.hydratedCount++;
2323

24-
if (!results.hydratedTags.includes(tagName)) {
25-
results.hydratedTags.push(tagName);
24+
const ref = getHostRef(elm);
25+
const modeName = ref.$modeName$;
26+
if (!results.hydratedComponents.some(c => c.tag === tagName && c.mode === modeName)) {
27+
results.hydratedComponents.push({
28+
tag: tagName,
29+
mode: modeName
30+
});
2631
}
27-
2832
} catch (e) {
2933
win.console.error(e);
3034
}

src/hydrate/runner/render.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ async function render(win: Window, doc: Document, opts: d.HydrateDocumentOptions
124124

125125
try {
126126
results.hydratedCount = bootstrapResults.hydratedCount;
127-
bootstrapResults.hydratedTags.forEach(hydratedTag => {
127+
bootstrapResults.hydratedComponents.forEach(component => {
128128
results.components.push({
129-
tag: hydratedTag,
129+
tag: component.tag,
130+
mode: component.mode,
130131
count: 0,
131132
depth: -1
132133
});

0 commit comments

Comments
 (0)