@lwrjs/view-registry 0.10.0-alpha.13 → 0.10.0-alpha.14

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.
@@ -0,0 +1,70 @@
1
+ import { explodeSpecifier, getGroupName, getVersionedModuleId, normalizeVersionToUri, logger, VERSION_NOT_PROVIDED, getSpecifier, isGroupie, } from '@lwrjs/shared-utils';
2
+ /**
3
+ * keeps track of preloadModules metadata
4
+ */
5
+ export function setPreloadModulesMeta(specifier, uri, groups, preloads) {
6
+ const preloadModulesSpecifiers = preloads.specifiers;
7
+ const preloadBundleGroupsMap = preloads.groups;
8
+ const preloadModulesURIs = preloads.uris;
9
+ preloadModulesSpecifiers.push(specifier);
10
+ const { specifier: unversionedSpecifier } = explodeSpecifier(specifier);
11
+ const groupName = getGroupName(unversionedSpecifier, groups);
12
+ if (groupName && preloadBundleGroupsMap.has(groupName)) {
13
+ return;
14
+ }
15
+ // With bundling groups, we only want to include one URI
16
+ preloadModulesURIs.push(uri);
17
+ groupName && preloadBundleGroupsMap.set(groupName, true);
18
+ }
19
+ /**
20
+ * Recursively gets preloadModules metadata starting with a specifer
21
+ * Note: don't call me unless you got bundles
22
+ */
23
+ export async function getPreloadModulesMeta(specifier, // unversioned specifier
24
+ viewPreloads, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending) {
25
+ const { exclude = [], external = {}, groups = {} } = bundleConfig;
26
+ const isExternal = function (rawSpecifier) {
27
+ const { specifier } = explodeSpecifier(rawSpecifier);
28
+ return Object.keys(external).includes(specifier);
29
+ };
30
+ const isExclude = function (specifier) {
31
+ return exclude.includes(specifier);
32
+ };
33
+ if (isExternal(specifier)) {
34
+ logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
35
+ }
36
+ else {
37
+ // eslint-disable-next-line no-await-in-loop
38
+ const versionedModuleId = await getVersionedModuleId(specifier, moduleRegistry); // TODO replace moduleRegistry with defRegistry
39
+ const versionedModuleSpecifier = getSpecifier({
40
+ specifier,
41
+ version: normalizeVersionToUri(versionedModuleId.version),
42
+ });
43
+ const uri =
44
+ // eslint-disable-next-line no-await-in-loop
45
+ await defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
46
+ // fallback to unversioned specifier if needed
47
+ const normalizedSpecifier = versionedModuleId.version === VERSION_NOT_PROVIDED ? specifier : versionedModuleSpecifier;
48
+ setPreloadModulesMeta(normalizedSpecifier, uri, groups, viewPreloads);
49
+ if (exclude.length || Object.keys(groups).length) {
50
+ // check if we need to also preload any excluded dependencies of this preload module
51
+ const preloadModuleRecord = await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams);
52
+ const { imports } = preloadModuleRecord.bundleRecord;
53
+ if (imports) {
54
+ if (!pending) {
55
+ pending = new Map();
56
+ }
57
+ for (let i = 0; i < imports.length; i++) {
58
+ const imp = imports[i];
59
+ if (!pending.has(imp.specifier) &&
60
+ (isExclude(imp.specifier) || isGroupie(imp.specifier, groups))) {
61
+ pending.set(imp.specifier, true); // prevent dupe calls
62
+ // eslint-disable-next-line no-await-in-loop
63
+ await getPreloadModulesMeta(imp.specifier, viewPreloads, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending);
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+ }
70
+ //# sourceMappingURL=preload-utils.js.map
@@ -1,12 +1,6 @@
1
- import { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefinition, RenderedViewMetadata, CustomElementReference, BundleConfig, ModuleBundler, ModuleRegistry } from '@lwrjs/types';
1
+ import { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefinition, RenderedViewMetadata, CustomElementReference } from '@lwrjs/types';
2
2
  import { View, ViewInfo } from '@lwrjs/types';
3
3
  export declare function getViewBootstrapConfigurationResource(viewInfo: ViewInfo, config: ClientBootstrapConfig, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): ResourceDefinition;
4
4
  export declare function getViewHmrConfigurationResource(view: View, viewMetadata: RenderedViewMetadata): ResourceDefinition;
5
5
  export declare function flattenCustomElements(arr: CustomElementReference[], isSSR?: boolean): CustomElementReference[];
6
- /**
7
- * Recursively gets preloadModules metadata starting with a specifer
8
- * Note: don't call me unless you got bundles
9
- */
10
- export declare function getPreloadModulesMeta(specifier: string, // unversioned specifier
11
- preloadModulesMeta: Map<string, string>, bundleConfig: BundleConfig, moduleRegistry: ModuleRegistry, defRegistry: ModuleBundler, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, pending?: Map<string, boolean>): Promise<void>;
12
6
  //# sourceMappingURL=utils.d.ts.map
@@ -1,4 +1,4 @@
1
- import { getMappingUriPrefix, getModuleUriPrefix, getClientBootstrapConfigurationUri, hashContent, getVersionedModuleId, normalizeVersionToUri, logger, VERSION_NOT_PROVIDED, explodeSpecifier, getSpecifier, } from '@lwrjs/shared-utils';
1
+ import { getMappingUriPrefix, getModuleUriPrefix, getClientBootstrapConfigurationUri, hashContent, } from '@lwrjs/shared-utils';
2
2
  const CONTENT_TYPE = 'application/javascript';
3
3
  export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams) {
4
4
  const { compat, debug, hmrEnabled, apiVersion, format } = runtimeEnvironment;
@@ -101,54 +101,4 @@ export function flattenCustomElements(arr, isSSR = false) {
101
101
  flatten(arr);
102
102
  return ret;
103
103
  }
104
- /**
105
- * Recursively gets preloadModules metadata starting with a specifer
106
- * Note: don't call me unless you got bundles
107
- */
108
- export async function getPreloadModulesMeta(specifier, // unversioned specifier
109
- preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending) {
110
- const { exclude = [], external = {} } = bundleConfig;
111
- const isExternal = function (rawSpecifier) {
112
- const { specifier } = explodeSpecifier(rawSpecifier);
113
- return Object.keys(external).includes(specifier);
114
- };
115
- const isExclude = function (specifier) {
116
- return exclude.includes(specifier);
117
- };
118
- if (isExternal(specifier)) {
119
- logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
120
- }
121
- else {
122
- // eslint-disable-next-line no-await-in-loop
123
- const versionedModuleId = await getVersionedModuleId(specifier, moduleRegistry); // TODO replace moduleRegistry with defRegistry
124
- const versionedModuleSpecifier = getSpecifier({
125
- specifier,
126
- version: normalizeVersionToUri(versionedModuleId.version),
127
- });
128
- const uri =
129
- // eslint-disable-next-line no-await-in-loop
130
- await defRegistry.resolveModuleUri(versionedModuleId, runtimeEnvironment, runtimeParams);
131
- // fallback to unversioned specifier if needed
132
- const normalizedSpecifier = versionedModuleId.version === VERSION_NOT_PROVIDED ? specifier : versionedModuleSpecifier;
133
- preloadModulesMeta.set(normalizedSpecifier, uri);
134
- if (exclude.length) {
135
- // check if we need to also preload any excluded dependencies of this preload module
136
- const preloadModuleRecord = await defRegistry.getModuleBundle(versionedModuleId, runtimeEnvironment, runtimeParams);
137
- const { imports } = preloadModuleRecord.bundleRecord;
138
- if (imports) {
139
- if (!pending) {
140
- pending = new Map();
141
- }
142
- for (let i = 0; i < imports.length; i++) {
143
- const imp = imports[i];
144
- if (!pending.has(imp.specifier) && isExclude(imp.specifier)) {
145
- pending.set(imp.specifier, true); // prevent dupe calls
146
- // eslint-disable-next-line no-await-in-loop
147
- await getPreloadModulesMeta(imp.specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, pending);
148
- }
149
- }
150
- }
151
- }
152
- }
153
- }
154
104
  //# sourceMappingURL=utils.js.map
@@ -1,11 +1,22 @@
1
- import { kebabCaseToModuleSpecifier, toImportMetadata, getModuleGraphs, getMappingUriPrefix, GraphDepth, logger, explodeSpecifier, isBundler, } from '@lwrjs/shared-utils';
1
+ import { kebabCaseToModuleSpecifier, toImportMetadata, getModuleGraphs, getMappingUriPrefix, GraphDepth, logger, explodeSpecifier, isBundler, hasHydrateDirective, } from '@lwrjs/shared-utils';
2
2
  import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
3
3
  import { generateHtmlTag, getModuleResourceByUri } from '../utils.js';
4
- import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, getPreloadModulesMeta, } from './utils.js';
4
+ import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
5
+ import { setPreloadModulesMeta, getPreloadModulesMeta } from './preload-utils.js';
5
6
  export async function getHtmlResources(view, viewParams, resourceContext) {
6
7
  const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata, } = resourceContext;
8
+ const { lwrVersion, format, hmrEnabled, bundle, debug, minify } = runtimeEnvironment;
9
+ const { customElements } = viewMetadata;
10
+ const defRegistry = bundle ? moduleBundler : moduleRegistry;
11
+ const version = lwrVersion;
12
+ const isAMD = format === 'amd';
13
+ const depth = isAMD
14
+ ? { static: GraphDepth.ALL, dynamic: 1 }
15
+ : { static: GraphDepth.NONE, dynamic: 1 };
7
16
  const { bundleConfig } = resourceContext;
8
17
  const { external = {} } = bundleConfig;
18
+ // Bundling groups is only supported in AMD for now
19
+ const groups = isAMD ? bundleConfig.groups || {} : {};
9
20
  const isExternal = function (rawSpecifier) {
10
21
  const { specifier } = explodeSpecifier(rawSpecifier);
11
22
  return Object.keys(external).some((e) => specifier === e);
@@ -14,11 +25,6 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
14
25
  services: [],
15
26
  preloadModules: [],
16
27
  }, } = view;
17
- const { lwrVersion, format, hmrEnabled, bundle, debug, minify } = runtimeEnvironment;
18
- const { customElements } = viewMetadata;
19
- const defRegistry = bundle ? moduleBundler : moduleRegistry;
20
- const version = lwrVersion;
21
- const isAMD = format === 'amd';
22
28
  // The Application Bootstrap (ABS) module resource is EITHER
23
29
  // - configured as routes[x].bootstrap.module OR
24
30
  // - defaulted as "@lwrjs/app-service/{appName}/module/{format}"
@@ -49,139 +55,156 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
49
55
  const rootComponents = [];
50
56
  // Collection of modules specifiers that MUST be loaded in the view
51
57
  const requiredAmdModules = [];
52
- // Collection of modules that will be preloaded. For AMD, it will be part of
53
- // the preloadModules client bootstrap config
54
- const preloadModulesMeta = new Map();
58
+ // Collect preload modules metadata
59
+ const viewPreloads = {
60
+ uris: [],
61
+ specifiers: [],
62
+ groups: new Map(),
63
+ };
55
64
  // Determine if server side rendering view modules
56
65
  const isSSR = view.bootstrap?.ssr;
57
- // ------ AMD Required module resources
58
- if (isAMD) {
59
- // Keep shim format in sync with legacy_view_bootstrap.ts
60
- const shimBundle = debug || minify === false ? 'lwr-loader-shim.bundle.js' : 'lwr-loader-shim.bundle.min.js';
61
- const def = (await resourceRegistry.getResource({ specifier: shimBundle, version }, runtimeEnvironment, runtimeParams));
62
- if (!def) {
63
- throw Error('Failed to find definition of resource: ' + shimBundle);
64
- }
65
- requiredResources.push(def);
66
- // Always inline the error shim script after the shim
67
- const errorShimDef = (await resourceRegistry.getResource({ specifier: 'lwr-error-shim.js', version }, runtimeEnvironment, runtimeParams));
68
- if (!errorShimDef) {
69
- throw Error('Failed to find definition of resource: lwr-error-shim.js');
70
- }
71
- requiredResources.push(errorShimDef);
72
- }
73
- // ------- Application Bootstrap module
74
- // Traversal of the Bootstrap Module Graph is done to get all the URLS for discoverable static dependencies.
75
- // Reasoning: This is to avoid unnecessary HTTP 302's during initial application module fetching.
76
- const depth = isAMD
77
- ? { static: GraphDepth.ALL, dynamic: 1 }
78
- : { static: GraphDepth.NONE, dynamic: 1 };
79
- const bootstrapModuleGraph = await getModuleGraphs(bootstrapSpecifier, { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visitedCache);
80
- // ADD bootstrap module uri as a script resource
81
- const versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
82
- const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
83
- moduleResources.push(getModuleResourceByUri(uri, runtimeEnvironment, { isPreload: false, isSSR }));
84
- // PRELOAD the bootstrap module static dependencies as preloaded script resources
85
- for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
86
- if (!isExternal(depSpecifier)) {
87
- const uri = bootstrapModuleGraph.uriMap[depSpecifier];
88
- preloadModulesMeta.set(depSpecifier, uri);
66
+ // ABS module and custom element references
67
+ let bootstrapModuleRef, versionedSpecifier = bootstrapSpecifier;
68
+ let importMetadata = { imports: {} };
69
+ const customElementsRecords = [];
70
+ const flattenedElements = flattenCustomElements(customElements, isSSR);
71
+ const viewContainsHydratedElements = !isSSR || flattenedElements.some(({ props }) => hasHydrateDirective(props));
72
+ if (viewContainsHydratedElements) {
73
+ // ------ AMD Required module resources
74
+ if (isAMD) {
75
+ // Keep shim format in sync with legacy_view_bootstrap.ts
76
+ const shimBundle = debug || minify === false ? 'lwr-loader-shim.bundle.js' : 'lwr-loader-shim.bundle.min.js';
77
+ const def = (await resourceRegistry.getResource({ specifier: shimBundle, version }, runtimeEnvironment, runtimeParams));
78
+ if (!def) {
79
+ throw Error('Failed to find definition of resource: ' + shimBundle);
80
+ }
81
+ requiredResources.push(def);
82
+ // Always inline the error shim script after the shim
83
+ const errorShimDef = (await resourceRegistry.getResource({ specifier: 'lwr-error-shim.js', version }, runtimeEnvironment, runtimeParams));
84
+ if (!errorShimDef) {
85
+ throw Error('Failed to find definition of resource: lwr-error-shim.js');
86
+ }
87
+ requiredResources.push(errorShimDef);
89
88
  }
90
- }
91
- // PRELOAD configured preloadModules as preloaded script resources
92
- if (isBundler(defRegistry)) {
93
- for (const specifier of preloadModules) {
94
- // eslint-disable-next-line no-await-in-loop
95
- await getPreloadModulesMeta(specifier, preloadModulesMeta, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams);
89
+ // ------- Application Bootstrap module
90
+ // Traversal of the Bootstrap Module Graph is done to get all the URLS for discoverable static dependencies.
91
+ // Reasoning: This is to avoid unnecessary HTTP 302's during initial application module fetching.
92
+ const bootstrapModuleGraph = await getModuleGraphs(bootstrapSpecifier, { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visitedCache);
93
+ bootstrapModuleRef = {
94
+ specifier: bootstrapModuleGraph.graphs[0].specifier,
95
+ flatGraph: bootstrapModuleGraph,
96
+ resources: configResources,
97
+ };
98
+ // ADD bootstrap module uri as a script resource
99
+ versionedSpecifier = bootstrapModuleGraph.graphs[0].specifier;
100
+ const uri = bootstrapModuleGraph.uriMap[versionedSpecifier];
101
+ moduleResources.push(getModuleResourceByUri(uri, runtimeEnvironment, { isPreload: false, isSSR }));
102
+ // PRELOAD the bootstrap module static dependencies as preloaded script resources
103
+ for (const depSpecifier of bootstrapModuleGraph.graphs[0].static) {
104
+ if (!isExternal(depSpecifier)) {
105
+ const uri = bootstrapModuleGraph.uriMap[depSpecifier];
106
+ setPreloadModulesMeta(depSpecifier, uri, groups, viewPreloads);
107
+ }
96
108
  }
97
- }
98
- if (isAMD) {
99
- // ADD bootstrap module as required
100
- requiredAmdModules.push(versionedSpecifier);
101
- // ADD bootstrap module uri addressability
102
- imports[versionedSpecifier] = uri;
103
- // PRELOAD bootstrap module static deps as link resource
104
- for (const staticDep of bootstrapModuleGraph.graphs[0].static) {
105
- const uri = bootstrapModuleGraph.uriMap[staticDep];
106
- // ADD static module dep uri addressability
107
- imports[staticDep] = uri;
108
- // ADD bootstrap module static deps to requiredAmdModules if services, otherwise preloadModules
109
- if (services && services.length) {
110
- requiredAmdModules.push(staticDep);
109
+ // PRELOAD configured preloadModules as preloaded script resources
110
+ if (isBundler(defRegistry)) {
111
+ for (const specifier of preloadModules) {
112
+ // eslint-disable-next-line no-await-in-loop
113
+ await getPreloadModulesMeta(specifier, viewPreloads, bundleConfig, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams);
111
114
  }
112
115
  }
113
- // Add import mappings for known dynamic imports
114
- for (const dynamicDep of bootstrapModuleGraph.graphs[0].dynamicRefs) {
115
- const uri = bootstrapModuleGraph.uriMap[dynamicDep];
116
- if (uri) {
117
- imports[dynamicDep] = uri;
116
+ if (isAMD) {
117
+ // ADD bootstrap module as required
118
+ requiredAmdModules.push(versionedSpecifier);
119
+ // ADD bootstrap module uri addressability
120
+ imports[versionedSpecifier] = uri;
121
+ // PRELOAD bootstrap module static deps as link resource
122
+ for (const staticDep of bootstrapModuleGraph.graphs[0].static) {
123
+ const uri = bootstrapModuleGraph.uriMap[staticDep];
124
+ // ADD static module dep uri addressability
125
+ imports[staticDep] = uri;
126
+ // ADD bootstrap module static deps to requiredAmdModules if services, otherwise preloadModules
127
+ if (services && services.length) {
128
+ requiredAmdModules.push(staticDep);
129
+ }
118
130
  }
119
- else {
120
- logger.warn('Skipping unknown dynamic import ' + dynamicDep);
131
+ // Add import mappings for known dynamic imports
132
+ for (const dynamicDep of bootstrapModuleGraph.graphs[0].dynamicRefs) {
133
+ const uri = bootstrapModuleGraph.uriMap[dynamicDep];
134
+ if (uri) {
135
+ imports[dynamicDep] = uri;
136
+ }
137
+ else {
138
+ logger.warn('Skipping unknown dynamic import ' + dynamicDep);
139
+ }
121
140
  }
122
141
  }
142
+ importMetadata = await toImportMetadata(bootstrapModuleGraph, { imports: {}, index: {} }, moduleRegistry, runtimeEnvironment, runtimeParams);
123
143
  }
124
- let importMetadata = await toImportMetadata(bootstrapModuleGraph, { imports: {}, index: {} }, moduleRegistry, runtimeEnvironment, runtimeParams);
125
144
  // ------- View related custom element moduleResources
126
- const customElementsRecords = [];
127
- const flattenedElements = flattenCustomElements(customElements, isSSR);
128
- for (const { tagName: element } of flattenedElements) {
145
+ for (const { tagName: element, props } of flattenedElements) {
129
146
  // eslint-disable-next-line no-await-in-loop
130
147
  const graph = await getModuleGraphs(kebabCaseToModuleSpecifier(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
131
148
  // add to the viewRecord
132
149
  customElementsRecords.push({ elementName: element, flatGraph: graph });
133
- // PRELOAD the custom element module as a link resource
134
- const specifier = graph.graphs[0].specifier;
135
- const uri = graph.uriMap[specifier];
136
- preloadModulesMeta.set(specifier, uri);
137
- // PRELOAD custom element static deps as link resources when bundling is ON
138
- if (bundle) {
139
- for (const depSpecifier of graph.graphs[0].static) {
140
- if (!isExternal(depSpecifier)) {
141
- const uri = graph.uriMap[depSpecifier];
142
- preloadModulesMeta.set(depSpecifier, uri);
150
+ // Only process custom elements that are to be hydrated
151
+ if (!isSSR || hasHydrateDirective(props)) {
152
+ // PRELOAD the custom element module as a link resource
153
+ const specifier = graph.graphs[0].specifier;
154
+ const uri = graph.uriMap[specifier];
155
+ setPreloadModulesMeta(specifier, uri, groups, viewPreloads);
156
+ // PRELOAD custom element static deps as link resources when bundling is ON
157
+ if (bundle) {
158
+ for (const depSpecifier of graph.graphs[0].static) {
159
+ if (!isExternal(depSpecifier)) {
160
+ const uri = graph.uriMap[depSpecifier];
161
+ setPreloadModulesMeta(depSpecifier, uri, groups, viewPreloads);
162
+ }
143
163
  }
144
164
  }
145
- }
146
- // ADD register custom elements as a uri addressable rootComponents
147
- rootComponents.push(specifier);
148
- imports[specifier] = uri;
149
- if (isAMD) {
150
- for (const staticDep of graph.graphs[0].static) {
151
- const uri = graph.uriMap[staticDep];
152
- // AMD ADD static module dep uri addressability
153
- imports[staticDep] = uri;
154
- }
155
- // AMD ADD dynamic imports module dep uri addressability
156
- for (const dynamicDep of graph.graphs[0].dynamicRefs) {
157
- const uri = graph.uriMap[dynamicDep];
158
- imports[dynamicDep] = uri;
165
+ // ADD register custom elements as a uri addressable rootComponents
166
+ rootComponents.push(specifier);
167
+ imports[specifier] = uri;
168
+ if (isAMD) {
169
+ for (const staticDep of graph.graphs[0].static) {
170
+ const uri = graph.uriMap[staticDep];
171
+ // AMD ADD static module dep uri addressability
172
+ imports[staticDep] = uri;
173
+ }
174
+ // AMD ADD dynamic imports module dep uri addressability
175
+ for (const dynamicDep of graph.graphs[0].dynamicRefs) {
176
+ const uri = graph.uriMap[dynamicDep];
177
+ imports[dynamicDep] = uri;
178
+ }
159
179
  }
180
+ // eslint-disable-next-line no-await-in-loop
181
+ importMetadata = await toImportMetadata(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
160
182
  }
161
- // eslint-disable-next-line no-await-in-loop
162
- importMetadata = await toImportMetadata(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
163
183
  }
164
- // ADD configuration of the bootstrapModule
165
- configResources.unshift(await getViewBootstrapConfigurationResource({
166
- id: view.id,
167
- url: viewParams?.page?.url,
168
- configAsSrc: view.bootstrap?.configAsSrc || false,
169
- }, {
170
- appId: appIdentity.appName,
171
- bootstrapModule: versionedSpecifier,
172
- autoBoot: view.bootstrap?.autoBoot === false ? false : true,
173
- imports: importMetadata?.imports,
174
- index: importMetadata?.index,
175
- rootComponents,
176
- ...(isAMD && { requiredModules: requiredAmdModules }),
177
- // in AMD we need to tell the loader what modules we are preloading
178
- ...(isAMD && { preloadModules: Array.from(preloadModulesMeta.keys()) }),
179
- }, runtimeEnvironment, runtimeParams));
184
+ if (viewContainsHydratedElements) {
185
+ // ADD configuration of the bootstrapModule
186
+ configResources.unshift(getViewBootstrapConfigurationResource({
187
+ id: view.id,
188
+ url: viewParams?.page?.url,
189
+ configAsSrc: view.bootstrap?.configAsSrc || false,
190
+ }, {
191
+ appId: appIdentity.appName,
192
+ bootstrapModule: versionedSpecifier,
193
+ autoBoot: view.bootstrap?.autoBoot === false ? false : true,
194
+ imports: importMetadata?.imports,
195
+ index: importMetadata?.index,
196
+ rootComponents,
197
+ ...(isAMD && { requiredModules: requiredAmdModules }),
198
+ // in AMD we need to tell the loader what modules we are preloading
199
+ ...(isAMD && { preloadModules: viewPreloads.specifiers }),
200
+ }, runtimeEnvironment, runtimeParams));
201
+ }
180
202
  if (!isAMD && hmrEnabled) {
181
- configResources.unshift(await getViewHmrConfigurationResource(view, viewMetadata));
203
+ configResources.unshift(getViewHmrConfigurationResource(view, viewMetadata));
182
204
  }
183
205
  // PRELOAD script resources for preload module URIs after the bootstrap module
184
- for (const [, preloadUri] of preloadModulesMeta) {
206
+ const dedupedUris = [...new Set(viewPreloads.uris)];
207
+ for (const preloadUri of dedupedUris) {
185
208
  moduleResources.push(getModuleResourceByUri(preloadUri, runtimeEnvironment, { isPreload: true, isSSR }));
186
209
  }
187
210
  // generate html partial
@@ -199,11 +222,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
199
222
  customElements: customElementsRecords,
200
223
  endpoints,
201
224
  importMetadata,
202
- bootstrapModule: {
203
- specifier: bootstrapModuleGraph.graphs[0].specifier,
204
- flatGraph: bootstrapModuleGraph,
205
- resources: configResources,
206
- },
225
+ bootstrapModule: bootstrapModuleRef,
207
226
  },
208
227
  };
209
228
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.10.0-alpha.13",
7
+ "version": "0.10.0-alpha.14",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,15 +30,15 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/app-service": "0.10.0-alpha.13",
34
- "@lwrjs/diagnostics": "0.10.0-alpha.13",
35
- "@lwrjs/shared-utils": "0.10.0-alpha.13"
33
+ "@lwrjs/app-service": "0.10.0-alpha.14",
34
+ "@lwrjs/diagnostics": "0.10.0-alpha.14",
35
+ "@lwrjs/shared-utils": "0.10.0-alpha.14"
36
36
  },
37
37
  "devDependencies": {
38
- "@lwrjs/types": "0.10.0-alpha.13"
38
+ "@lwrjs/types": "0.10.0-alpha.14"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=16.0.0 <20"
42
42
  },
43
- "gitHead": "f6d142d5a027554cb1685389e0b173734149683d"
43
+ "gitHead": "f80dc1c18719b77c183f339027313be11d69f9dc"
44
44
  }