Skip to content

Commit badf06f

Browse files
committed
feat(build): conditionally include client side prerender hydration
1 parent 7d2e2df commit badf06f

5 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/client/platform-main-legacy.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ export function createPlatformMainLegacy(namespace: string, Context: d.CoreConte
123123
}
124124
};
125125

126-
// if the HTML was generated from SSR
127-
// then let's walk the tree and generate vnodes out of the data
128-
createVNodesFromSsr(plt, domApi, rootElm);
126+
if (__BUILD_CONDITIONALS__.prerenderClientSide) {
127+
// if the HTML was generated from prerendering
128+
// then let's walk the tree and generate vnodes out of the data
129+
createVNodesFromSsr(plt, domApi, rootElm);
130+
}
129131

130132

131133
function defineComponent(cmpMeta: d.ComponentMeta, HostElementConstructor: any) {

src/client/platform-main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ export function createPlatformMain(namespace: string, Context: d.CoreContext, wi
116116
}
117117
};
118118

119-
if (__BUILD_CONDITIONALS__.browserModuleLoader) {
120-
// if the HTML was generated from SSR
119+
if (__BUILD_CONDITIONALS__.prerenderClientSide) {
120+
// if the HTML was generated from prerendering
121121
// then let's walk the tree and generate vnodes out of the data
122122
createVNodesFromSsr(plt, domApi, rootElm);
123123
}

src/compiler/prerender/prerender-app.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ export async function prerenderOutputTargets(config: d.Config, compilerCtx: d.Co
2929
}
3030

3131

32+
export function shouldPrerender(config: d.Config) {
33+
if (!config.srcIndexHtml) {
34+
return false;
35+
}
36+
const outputTargets = (config.outputTargets as d.OutputTargetWww[]).filter(o => {
37+
return o.type === 'www' && o.indexHtml && o.hydrateComponents && o.prerenderLocations && o.prerenderLocations.length > 0;
38+
});
39+
return (outputTargets.length > 0);
40+
}
41+
42+
3243
async function prerenderOutputTarget(config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, outputTarget: d.OutputTargetWww, entryModules: d.EntryModule[]) {
3344
// if there was src index.html file, then the process before this one
3445
// would have already loaded and updated the src index to its www path

src/declarations/build-conditionals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface BuildConditionals {
2222

2323
// ssr
2424
ssrServerSide: boolean;
25+
prerenderClientSide: boolean;
2526

2627
// encapsulation
2728
styles: boolean;

src/util/build-conditionals.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as d from '../declarations';
22
import { ENCAPSULATION, MEMBER_TYPE, PROP_TYPE } from './constants';
33
import { isTsFile } from '../compiler/util';
4+
import { shouldPrerender } from '../compiler/prerender/prerender-app';
45

56

67
export function getDefaultBuildConditionals(): d.BuildConditionals {
@@ -11,6 +12,7 @@ export function getDefaultBuildConditionals(): d.BuildConditionals {
1112
shadowDom: true,
1213
slotPolyfill: true,
1314
ssrServerSide: true,
15+
prerenderClientSide: true,
1416
devInspector: true,
1517
hotModuleReplacement: true,
1618
verboseError: true,
@@ -79,6 +81,7 @@ export async function setBuildConditionals(
7981
es5: false,
8082
cssVarShim: false,
8183
ssrServerSide: false,
84+
prerenderClientSide: false,
8285
shadowDom: false,
8386
slotPolyfill: false,
8487
event: false,
@@ -118,6 +121,7 @@ export async function setBuildConditionals(
118121
if (coreBuild.slotPolyfill) {
119122
coreBuild.slotPolyfill = !!(buildCtx.hasSlot);
120123
}
124+
coreBuild.prerenderClientSide = shouldPrerender(config);
121125
compilerCtx.lastBuildConditionalsBrowserEsm = coreBuild;
122126

123127
} else if (coreId === 'core.pf') {
@@ -126,6 +130,7 @@ export async function setBuildConditionals(
126130
coreBuild.polyfills = true;
127131
coreBuild.cssVarShim = true;
128132
coreBuild.slotPolyfill = !!(buildCtx.hasSlot);
133+
coreBuild.prerenderClientSide = shouldPrerender(config);
129134
compilerCtx.lastBuildConditionalsBrowserEs5 = coreBuild;
130135

131136
} else if (coreId === 'esm.es5') {

0 commit comments

Comments
 (0)