@lwrjs/view-registry 0.17.2-alpha.6 → 0.17.2-alpha.7

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.
@@ -32,6 +32,7 @@ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
32
32
  var import_utils = __toModule(require("./utils.cjs"));
33
33
  var import_link_lwr_resources = __toModule(require("./linkers/link-lwr-resources.cjs"));
34
34
  var import_lru_cache = __toModule(require("lru-cache"));
35
+ var import_crypto = __toModule(require("crypto"));
35
36
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
36
37
  var import_view_handler = __toModule(require("./view-handler.cjs"));
37
38
  var LwrViewRegistry = class {
@@ -40,6 +41,7 @@ var LwrViewRegistry = class {
40
41
  this.compiledViews = new Map();
41
42
  this.immutableAssets = new Map();
42
43
  this.pendingViewDefinitions = new import_shared_utils.InflightTasks();
44
+ this.metadataCache = new Map();
43
45
  this.name = "lwr-view-registry";
44
46
  this.resourceRegistry = context.resourceRegistry;
45
47
  this.runtimeEnvironment = context.runtimeEnvironment;
@@ -243,6 +245,10 @@ var LwrViewRegistry = class {
243
245
  lwr_resources: lwrResourcesId
244
246
  }, runtimeParams, runtimeEnvironment);
245
247
  normalizedRenderOptions = (0, import_utils.normalizeRenderOptions)(this.runtimeEnvironment, renderedLayout.options, normalizedRenderOptions);
248
+ const warnings = [
249
+ ...renderedContent.metadata.serverDebug?.warnings || [],
250
+ ...renderedLayout.metadata.serverDebug?.warnings || []
251
+ ];
246
252
  const renderedViewDef = await this.link({
247
253
  ...renderedLayout,
248
254
  compiledView: {
@@ -262,10 +268,7 @@ var LwrViewRegistry = class {
262
268
  ...renderedContent.metadata.serverData,
263
269
  ...renderedLayout.metadata.serverData
264
270
  },
265
- serverDebug: {
266
- ...renderedContent.metadata.serverDebug,
267
- ...renderedLayout.metadata.serverDebug
268
- },
271
+ serverDebug: {warnings},
269
272
  serverBundles: renderedContent.metadata.serverBundles
270
273
  },
271
274
  cache: renderedContent.cache
@@ -325,7 +328,17 @@ var LwrViewRegistry = class {
325
328
  ssr: view.bootstrap?.ssr === true
326
329
  }
327
330
  }, () => {
328
- const linkedMetadata2 = skipMetadataCollection ? renderedViewMetadata : (0, import_shared_utils.extractMetadataFromHtml)(renderedViewContent, renderedViewMetadata, this.globalConfig);
331
+ let linkedMetadata2 = renderedViewMetadata;
332
+ if (!skipMetadataCollection) {
333
+ const contentHash = (0, import_crypto.createHash)("md5").update(renderedViewContent).digest("hex");
334
+ const cacheKey = `${view.id}:${contentHash}`;
335
+ if (this.metadataCache.has(cacheKey)) {
336
+ linkedMetadata2 = this.metadataCache.get(cacheKey);
337
+ } else {
338
+ linkedMetadata2 = (0, import_shared_utils.extractMetadataFromHtml)(renderedViewContent, renderedViewMetadata, this.globalConfig);
339
+ this.metadataCache.set(cacheKey, linkedMetadata2);
340
+ }
341
+ }
329
342
  const stringBuilder2 = (0, import_shared_utils.createStringBuilder)(renderedViewContent);
330
343
  return {linkedMetadata: linkedMetadata2, stringBuilder: stringBuilder2};
331
344
  });
@@ -251,7 +251,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
251
251
  }
252
252
  }
253
253
  }));
254
- if (viewContainsLiveElements || serverDebug?.message) {
254
+ if (viewContainsLiveElements || serverDebug?.warnings?.length) {
255
255
  if ((0, import_shared_utils.isLocalDev)()) {
256
256
  const localDevSpecifier = "lwr_local_dev/bootstrap";
257
257
  rootComponents.push(localDevSpecifier);
@@ -278,7 +278,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
278
278
  serverData,
279
279
  ...isAMD && {requiredModules: requiredAmdModules},
280
280
  ...isAMD && {preloadModules: viewPreloads.specifiers}
281
- }, runtimeEnvironment, runtimeParams, serverDebug?.message));
281
+ }, runtimeEnvironment, runtimeParams, serverDebug?.warnings));
282
282
  }
283
283
  if (!isAMD && hmrEnabled) {
284
284
  configResources.unshift((0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
@@ -29,9 +29,10 @@ __export(exports, {
29
29
  getViewBootstrapConfigurationResource: () => getViewBootstrapConfigurationResource,
30
30
  getViewHmrConfigurationResource: () => getViewHmrConfigurationResource
31
31
  });
32
+ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
32
33
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
33
34
  var CONTENT_TYPE = "application/javascript";
34
- function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams, debugMessage) {
35
+ function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams, warnings) {
35
36
  const {compat, debug, hmrEnabled, apiVersion, format} = runtimeEnvironment;
36
37
  const isESM = format === "esm";
37
38
  const defaultUrl = (0, import_shared_utils.getModuleUriPrefix)(runtimeEnvironment, runtimeParams);
@@ -53,6 +54,9 @@ function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironm
53
54
  SSR: false,
54
55
  ...(0, import_shared_utils.buildEnvironmentContext)(runtimeParams)
55
56
  };
57
+ let warnMessages = `console.group('Server-side rendering warnings:');`;
58
+ warnings?.forEach((warning) => warnMessages += `console.warn('${(0, import_diagnostics.stringifyError)(warning)}');`);
59
+ warnMessages += "console.groupEnd();";
56
60
  const configString = [
57
61
  "/* This script is generated */",
58
62
  "/* Client Bootstrap configuration */",
@@ -64,7 +68,7 @@ function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironm
64
68
  `globalThis.LWR = {...globalThis.LWR, env: ${JSON.stringify(lwrEnv)}};`,
65
69
  `globalThis.process={...globalThis.process,env:{...globalThis.process?.env,...${JSON.stringify(nodeEnv)}}};`,
66
70
  `globalThis.lwcRuntimeFlags = { ENABLE_MIXED_SHADOW_MODE: ${viewInfo.mixedMode}, ENABLE_WIRE_SYNC_EMIT: ${viewInfo.ssr} };`,
67
- debug && debugMessage && `console.error(${JSON.stringify(debugMessage)});`
71
+ warnings?.length && warnMessages
68
72
  ].filter(Boolean).join("\n");
69
73
  if (viewInfo.configAsSrc) {
70
74
  const viewUrl = viewInfo.url || "/";
@@ -234,7 +234,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
234
234
  importMetadata = await (0, import_shared_utils.toImportMetadata)(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
235
235
  }
236
236
  }
237
- if (viewContainsLiveElements || serverDebug?.message) {
237
+ if (viewContainsLiveElements || serverDebug?.warnings?.length) {
238
238
  configResources.unshift((0, import_utils2.getViewBootstrapConfigurationResource)({
239
239
  id: view.id,
240
240
  url: viewParams?.page?.url,
@@ -252,7 +252,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
252
252
  serverData,
253
253
  ...isAMD && {requiredModules: requiredAmdModules},
254
254
  ...isAMD && {preloadModules: viewPreloads.specifiers}
255
- }, runtimeEnvironment, runtimeParams, serverDebug?.message));
255
+ }, runtimeEnvironment, runtimeParams, serverDebug?.warnings));
256
256
  }
257
257
  if (!isAMD && hmrEnabled) {
258
258
  configResources.unshift((0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
@@ -47,6 +47,7 @@ export declare class LwrViewRegistry implements ViewRegistry {
47
47
  getViewDefinition(view: View, viewParams: ViewParams, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, renderOptions?: RenderOptions): Promise<LinkedViewDefinition>;
48
48
  private renderView;
49
49
  private render;
50
+ private metadataCache;
50
51
  private link;
51
52
  }
52
53
  //# sourceMappingURL=index.d.ts.map
package/build/es/index.js CHANGED
@@ -4,6 +4,7 @@ import { generateViewNonce, getViewNonce, normalizeRenderOptions, normalizeRende
4
4
  import { linkLwrResources } from './linkers/link-lwr-resources.js';
5
5
  // TODO: investigate perf impact W-16056356
6
6
  import { LRUCache } from 'lru-cache';
7
+ import { createHash } from 'crypto';
7
8
  import { LwrError, LwrServerError, descriptions, logger } from '@lwrjs/diagnostics';
8
9
  export { LwrViewHandler } from './view-handler.js';
9
10
  export class LwrViewRegistry {
@@ -19,6 +20,7 @@ export class LwrViewRegistry {
19
20
  // Pending view definitions are tracked to prevent concurrent resolution of the same view.
20
21
  // Subsequent requests for the same view will await the original promise.
21
22
  this.pendingViewDefinitions = new InflightTasks();
23
+ this.metadataCache = new Map();
22
24
  this.name = 'lwr-view-registry';
23
25
  this.resourceRegistry = context.resourceRegistry;
24
26
  this.runtimeEnvironment = context.runtimeEnvironment;
@@ -264,6 +266,10 @@ export class LwrViewRegistry {
264
266
  lwr_resources: lwrResourcesId,
265
267
  }, runtimeParams, runtimeEnvironment);
266
268
  normalizedRenderOptions = normalizeRenderOptions(this.runtimeEnvironment, renderedLayout.options, normalizedRenderOptions);
269
+ const warnings = [
270
+ ...(renderedContent.metadata.serverDebug?.warnings || []),
271
+ ...(renderedLayout.metadata.serverDebug?.warnings || []),
272
+ ];
267
273
  const renderedViewDef = await this.link({
268
274
  ...renderedLayout,
269
275
  // Rendered Layout view's immutability is a composite of the layouts mutability and the body's mutability
@@ -285,10 +291,7 @@ export class LwrViewRegistry {
285
291
  ...renderedContent.metadata.serverData,
286
292
  ...renderedLayout.metadata.serverData,
287
293
  },
288
- serverDebug: {
289
- ...renderedContent.metadata.serverDebug,
290
- ...renderedLayout.metadata.serverDebug,
291
- },
294
+ serverDebug: { warnings },
292
295
  serverBundles: renderedContent.metadata.serverBundles, // 1st pass of SSR
293
296
  },
294
297
  cache: renderedContent.cache,
@@ -351,9 +354,19 @@ export class LwrViewRegistry {
351
354
  ssr: view.bootstrap?.ssr === true,
352
355
  },
353
356
  }, () => {
354
- const linkedMetadata = skipMetadataCollection
355
- ? renderedViewMetadata
356
- : extractMetadataFromHtml(renderedViewContent, renderedViewMetadata, this.globalConfig);
357
+ let linkedMetadata = renderedViewMetadata;
358
+ if (!skipMetadataCollection) {
359
+ // Create a unique key based on view ID and content hash
360
+ const contentHash = createHash('md5').update(renderedViewContent).digest('hex');
361
+ const cacheKey = `${view.id}:${contentHash}`;
362
+ if (this.metadataCache.has(cacheKey)) {
363
+ linkedMetadata = this.metadataCache.get(cacheKey);
364
+ }
365
+ else {
366
+ linkedMetadata = extractMetadataFromHtml(renderedViewContent, renderedViewMetadata, this.globalConfig);
367
+ this.metadataCache.set(cacheKey, linkedMetadata);
368
+ }
369
+ }
357
370
  const stringBuilder = createStringBuilder(renderedViewContent);
358
371
  return { linkedMetadata, stringBuilder };
359
372
  });
@@ -290,7 +290,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
290
290
  }
291
291
  }
292
292
  }));
293
- if (viewContainsLiveElements || serverDebug?.message) {
293
+ if (viewContainsLiveElements || serverDebug?.warnings?.length) {
294
294
  if (isLocalDev()) {
295
295
  // ADD the client-side bootstrap module and mapping for local-dev
296
296
  const localDevSpecifier = 'lwr_local_dev/bootstrap';
@@ -320,7 +320,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
320
320
  ...(isAMD && { requiredModules: requiredAmdModules }),
321
321
  // in AMD we need to tell the loader what modules we are preloading
322
322
  ...(isAMD && { preloadModules: viewPreloads.specifiers }),
323
- }, runtimeEnvironment, runtimeParams, serverDebug?.message));
323
+ }, runtimeEnvironment, runtimeParams, serverDebug?.warnings));
324
324
  }
325
325
  if (!isAMD && hmrEnabled) {
326
326
  configResources.unshift(getViewHmrConfigurationResource(view, viewMetadata));
@@ -1,5 +1,5 @@
1
1
  import type { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefinition, RenderedViewMetadata, CustomElementReference, View, ViewInfo, FlattenedModuleGraphs } from '@lwrjs/types';
2
- export declare function getViewBootstrapConfigurationResource(viewInfo: ViewInfo, config: ClientBootstrapConfig, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, debugMessage?: string): ResourceDefinition;
2
+ export declare function getViewBootstrapConfigurationResource(viewInfo: ViewInfo, config: ClientBootstrapConfig, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, warnings?: (Error | string)[]): ResourceDefinition;
3
3
  export declare function getViewHmrConfigurationResource(view: View, viewMetadata: RenderedViewMetadata): ResourceDefinition;
4
4
  export declare function flattenCustomElements(arr: CustomElementReference[], isSSR?: boolean): CustomElementReference[];
5
5
  export declare function getBundleIntegrity(bootstrapModuleGraph: FlattenedModuleGraphs, versionedSpecifier: string): string | undefined;
@@ -1,6 +1,7 @@
1
+ import { stringifyError } from '@lwrjs/diagnostics';
1
2
  import { buildEnvironmentContext, getMappingUriPrefix, getModuleUriPrefix, getClientBootstrapConfigurationUri, hashContent, } from '@lwrjs/shared-utils';
2
3
  const CONTENT_TYPE = 'application/javascript';
3
- export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams, debugMessage) {
4
+ export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams, warnings) {
4
5
  const { compat, debug, hmrEnabled, apiVersion, format } = runtimeEnvironment;
5
6
  const isESM = format === 'esm';
6
7
  const defaultUrl = getModuleUriPrefix(runtimeEnvironment, runtimeParams);
@@ -27,6 +28,9 @@ export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeE
27
28
  // Used by `lwr/environment`
28
29
  ...buildEnvironmentContext(runtimeParams),
29
30
  };
31
+ let warnMessages = `console.group('Server-side rendering warnings:');`;
32
+ warnings?.forEach((warning) => (warnMessages += `console.warn('${stringifyError(warning)}');`));
33
+ warnMessages += 'console.groupEnd();';
30
34
  const configString = [
31
35
  '/* This script is generated */',
32
36
  '/* Client Bootstrap configuration */',
@@ -39,7 +43,7 @@ export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeE
39
43
  `globalThis.process={...globalThis.process,env:{...globalThis.process?.env,...${JSON.stringify(nodeEnv)}}};`,
40
44
  // TODO: evaluate moving these to app layer
41
45
  `globalThis.lwcRuntimeFlags = { ENABLE_MIXED_SHADOW_MODE: ${viewInfo.mixedMode}, ENABLE_WIRE_SYNC_EMIT: ${viewInfo.ssr} };`,
42
- debug && debugMessage && `console.error(${JSON.stringify(debugMessage)});`,
46
+ warnings?.length && warnMessages,
43
47
  ]
44
48
  .filter(Boolean)
45
49
  .join('\n');
@@ -262,7 +262,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
262
262
  importMetadata = await toImportMetadata(graph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
263
263
  }
264
264
  }
265
- if (viewContainsLiveElements || serverDebug?.message) {
265
+ if (viewContainsLiveElements || serverDebug?.warnings?.length) {
266
266
  // ADD configuration of the bootstrapModule
267
267
  configResources.unshift(getViewBootstrapConfigurationResource({
268
268
  id: view.id,
@@ -282,7 +282,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
282
282
  ...(isAMD && { requiredModules: requiredAmdModules }),
283
283
  // in AMD we need to tell the loader what modules we are preloading
284
284
  ...(isAMD && { preloadModules: viewPreloads.specifiers }),
285
- }, runtimeEnvironment, runtimeParams, serverDebug?.message));
285
+ }, runtimeEnvironment, runtimeParams, serverDebug?.warnings));
286
286
  }
287
287
  if (!isAMD && hmrEnabled) {
288
288
  configResources.unshift(getViewHmrConfigurationResource(view, viewMetadata));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.17.2-alpha.6",
7
+ "version": "0.17.2-alpha.7",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -33,14 +33,14 @@
33
33
  "build": "tsc -b"
34
34
  },
35
35
  "dependencies": {
36
- "@lwrjs/app-service": "0.17.2-alpha.6",
37
- "@lwrjs/diagnostics": "0.17.2-alpha.6",
38
- "@lwrjs/instrumentation": "0.17.2-alpha.6",
39
- "@lwrjs/shared-utils": "0.17.2-alpha.6",
36
+ "@lwrjs/app-service": "0.17.2-alpha.7",
37
+ "@lwrjs/diagnostics": "0.17.2-alpha.7",
38
+ "@lwrjs/instrumentation": "0.17.2-alpha.7",
39
+ "@lwrjs/shared-utils": "0.17.2-alpha.7",
40
40
  "lru-cache": "^10.4.3"
41
41
  },
42
42
  "devDependencies": {
43
- "@lwrjs/types": "0.17.2-alpha.6"
43
+ "@lwrjs/types": "0.17.2-alpha.7"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18.0.0"
@@ -48,5 +48,5 @@
48
48
  "volta": {
49
49
  "extends": "../../../package.json"
50
50
  },
51
- "gitHead": "e52a06333b7cd8d6d4bdc846ea9019d13f9fb85d"
51
+ "gitHead": "13d2ef766b72903be7be11a0ddc4704fe649f77a"
52
52
  }