@lwrjs/view-registry 0.15.0-alpha.26 → 0.15.0-alpha.27
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.
package/build/cjs/index.cjs
CHANGED
|
@@ -145,11 +145,15 @@ var LwrViewRegistry = class {
|
|
|
145
145
|
const {contentTemplate, rootComponent} = viewId;
|
|
146
146
|
const compiledViewCacheKey = (0, import_shared_utils.getCacheKeyFromJson)({contentTemplate, rootComponent});
|
|
147
147
|
import_diagnostics.logger.debug(`[view-registry][getView] compiledViewCacheKey=${compiledViewCacheKey}`);
|
|
148
|
-
|
|
148
|
+
const route = this.globalConfig.routes.find((r) => r.id === viewId.id);
|
|
149
|
+
const skipCaching = route?.cache?.ttl === 0;
|
|
150
|
+
if (!skipCaching && this.compiledViews.has(compiledViewCacheKey)) {
|
|
149
151
|
return this.compiledViews.get(compiledViewCacheKey);
|
|
150
152
|
}
|
|
151
153
|
const compiledView = await this.delegateGetView(viewId);
|
|
152
|
-
|
|
154
|
+
if (!skipCaching) {
|
|
155
|
+
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
156
|
+
}
|
|
153
157
|
return compiledView;
|
|
154
158
|
}
|
|
155
159
|
hasViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions) {
|
|
@@ -329,19 +333,37 @@ var LwrViewRegistry = class {
|
|
|
329
333
|
metadata: renderedViewMetadata,
|
|
330
334
|
compiledView: {immutable = true}
|
|
331
335
|
} = renderedView;
|
|
332
|
-
const linkedMetadata =
|
|
336
|
+
const {linkedMetadata, stringBuilder} = await (0, import_instrumentation.getTracer)().trace({
|
|
337
|
+
name: import_instrumentation.ViewSpan.ParseView,
|
|
338
|
+
attributes: {
|
|
339
|
+
view: view.id,
|
|
340
|
+
ssr: view.bootstrap?.ssr === true
|
|
341
|
+
}
|
|
342
|
+
}, async () => {
|
|
343
|
+
const linkedMetadata2 = skipMetadataCollection ? renderedViewMetadata : await (0, import_shared_utils.extractMetadataFromHtml)(renderedViewContent, renderedViewMetadata, this.globalConfig);
|
|
344
|
+
const stringBuilder2 = (0, import_shared_utils.createStringBuilder)(renderedViewContent);
|
|
345
|
+
return {linkedMetadata: linkedMetadata2, stringBuilder: stringBuilder2};
|
|
346
|
+
});
|
|
333
347
|
const mergedViewContext = {
|
|
334
348
|
...viewContext,
|
|
335
349
|
config: this.globalConfig,
|
|
336
350
|
runtimeEnvironment,
|
|
337
351
|
importer: importer || renderedView.compiledView.filePath
|
|
338
352
|
};
|
|
339
|
-
const stringBuilder = (0, import_shared_utils.createStringBuilder)(renderedViewContent);
|
|
340
353
|
let pageTtl = renderedView.cache.ttl;
|
|
354
|
+
let pageRedirect = renderedView.redirect;
|
|
341
355
|
for (const viewTransformer of this.viewTransformers) {
|
|
342
|
-
const linkResults = await
|
|
356
|
+
const linkResults = await (0, import_instrumentation.getTracer)().trace({
|
|
357
|
+
name: import_instrumentation.ViewSpan.Transform,
|
|
358
|
+
attributes: {
|
|
359
|
+
name: viewTransformer.name
|
|
360
|
+
}
|
|
361
|
+
}, () => viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata));
|
|
343
362
|
const ttl = linkResults && linkResults.cache?.ttl;
|
|
344
363
|
pageTtl = (0, import_shared_utils.shortestTtl)(ttl || void 0, pageTtl);
|
|
364
|
+
if (!pageRedirect) {
|
|
365
|
+
pageRedirect = linkResults ? linkResults.redirect : void 0;
|
|
366
|
+
}
|
|
345
367
|
}
|
|
346
368
|
const linkedAssetContent = stringBuilder.toString();
|
|
347
369
|
if (linkedAssetContent.includes(lwrResourcesId)) {
|
|
@@ -363,7 +385,7 @@ var LwrViewRegistry = class {
|
|
|
363
385
|
...viewRecord
|
|
364
386
|
},
|
|
365
387
|
cache: {ttl: pageTtl},
|
|
366
|
-
redirect:
|
|
388
|
+
redirect: pageRedirect
|
|
367
389
|
};
|
|
368
390
|
}
|
|
369
391
|
return {
|
|
@@ -374,7 +396,7 @@ var LwrViewRegistry = class {
|
|
|
374
396
|
moduleResources: []
|
|
375
397
|
},
|
|
376
398
|
cache: {ttl: pageTtl},
|
|
377
|
-
redirect:
|
|
399
|
+
redirect: pageRedirect
|
|
378
400
|
};
|
|
379
401
|
}
|
|
380
402
|
};
|
|
@@ -32,16 +32,16 @@ var import_legacy_view_bootstrap = __toModule(require("./legacy_view_bootstrap.c
|
|
|
32
32
|
async function linkLwrResources(source, view, viewParams, cxt) {
|
|
33
33
|
const {lwrResourcesId, ...resourceContext} = cxt;
|
|
34
34
|
const LEGACY_LOADER = !!resourceContext.runtimeEnvironment.featureFlags.LEGACY_LOADER;
|
|
35
|
-
|
|
35
|
+
return await (0, import_instrumentation.getTracer)().trace({
|
|
36
36
|
name: import_instrumentation.ViewSpan.Generate,
|
|
37
37
|
attributes: {
|
|
38
38
|
legacyLoader: LEGACY_LOADER
|
|
39
39
|
}
|
|
40
|
-
}, () => {
|
|
41
|
-
|
|
40
|
+
}, async () => {
|
|
41
|
+
const {partial, viewRecord} = await (LEGACY_LOADER ? (0, import_legacy_view_bootstrap.getHtmlResources)(view, viewParams, resourceContext) : (0, import_view_bootstrap.getHtmlResources)(view, viewParams, resourceContext));
|
|
42
|
+
return {
|
|
43
|
+
renderedView: source.replace(lwrResourcesId, () => partial),
|
|
44
|
+
viewRecord
|
|
45
|
+
};
|
|
42
46
|
});
|
|
43
|
-
return {
|
|
44
|
-
renderedView: source.replace(lwrResourcesId, () => partial),
|
|
45
|
-
viewRecord
|
|
46
|
-
};
|
|
47
47
|
}
|
package/build/es/index.js
CHANGED
|
@@ -132,12 +132,18 @@ export class LwrViewRegistry {
|
|
|
132
132
|
const { contentTemplate, rootComponent } = viewId;
|
|
133
133
|
const compiledViewCacheKey = getCacheKeyFromJson({ contentTemplate, rootComponent });
|
|
134
134
|
logger.debug(`[view-registry][getView] compiledViewCacheKey=${compiledViewCacheKey}`);
|
|
135
|
+
// For now we are only supporting ttl 0 == skipCaching.
|
|
136
|
+
const route = this.globalConfig.routes.find((r) => r.id === viewId.id);
|
|
137
|
+
const skipCaching = route?.cache?.ttl === 0;
|
|
135
138
|
// use cached compiledView if available
|
|
136
|
-
if (this.compiledViews.has(compiledViewCacheKey)) {
|
|
139
|
+
if (!skipCaching && this.compiledViews.has(compiledViewCacheKey)) {
|
|
137
140
|
return this.compiledViews.get(compiledViewCacheKey);
|
|
138
141
|
}
|
|
139
142
|
const compiledView = await this.delegateGetView(viewId);
|
|
140
|
-
|
|
143
|
+
// cache the compiled view
|
|
144
|
+
if (!skipCaching) {
|
|
145
|
+
this.compiledViews.set(compiledViewCacheKey, compiledView);
|
|
146
|
+
}
|
|
141
147
|
return compiledView;
|
|
142
148
|
}
|
|
143
149
|
hasViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions) {
|
|
@@ -354,24 +360,43 @@ export class LwrViewRegistry {
|
|
|
354
360
|
const runtimeEnvironment = { ...runtimeEnv, immutableAssets: freezeAssets };
|
|
355
361
|
// normalize/extract metadata
|
|
356
362
|
const { renderedView: renderedViewContent, metadata: renderedViewMetadata, compiledView: { immutable = true }, } = renderedView;
|
|
357
|
-
const linkedMetadata =
|
|
358
|
-
|
|
359
|
-
:
|
|
363
|
+
const { linkedMetadata, stringBuilder } = await getTracer().trace({
|
|
364
|
+
name: ViewSpan.ParseView,
|
|
365
|
+
attributes: {
|
|
366
|
+
view: view.id,
|
|
367
|
+
ssr: view.bootstrap?.ssr === true,
|
|
368
|
+
},
|
|
369
|
+
}, async () => {
|
|
370
|
+
const linkedMetadata = skipMetadataCollection
|
|
371
|
+
? renderedViewMetadata
|
|
372
|
+
: await extractMetadataFromHtml(renderedViewContent, renderedViewMetadata, this.globalConfig);
|
|
373
|
+
const stringBuilder = createStringBuilder(renderedViewContent);
|
|
374
|
+
return { linkedMetadata, stringBuilder };
|
|
375
|
+
});
|
|
360
376
|
const mergedViewContext = {
|
|
361
377
|
...viewContext,
|
|
362
378
|
config: this.globalConfig,
|
|
363
379
|
runtimeEnvironment,
|
|
364
380
|
importer: importer || renderedView.compiledView.filePath,
|
|
365
381
|
};
|
|
366
|
-
const stringBuilder = createStringBuilder(renderedViewContent);
|
|
367
382
|
// Note: this is the TTL for the page NOT for the view registry cache
|
|
368
383
|
let pageTtl = renderedView.cache.ttl;
|
|
384
|
+
let pageRedirect = renderedView.redirect;
|
|
369
385
|
for (const viewTransformer of this.viewTransformers) {
|
|
370
386
|
// eslint-disable-next-line no-await-in-loop
|
|
371
|
-
const linkResults = await
|
|
387
|
+
const linkResults = await getTracer().trace({
|
|
388
|
+
name: ViewSpan.Transform,
|
|
389
|
+
attributes: {
|
|
390
|
+
name: viewTransformer.name,
|
|
391
|
+
},
|
|
392
|
+
}, () => viewTransformer.link?.(stringBuilder, mergedViewContext, linkedMetadata));
|
|
372
393
|
// Keep track of the shortest TTL from each view transformer (e.g. lwcSsrViewTransformer)
|
|
373
394
|
const ttl = linkResults && linkResults.cache?.ttl;
|
|
374
395
|
pageTtl = shortestTtl(ttl || undefined, pageTtl);
|
|
396
|
+
// Set the redirect info, if it doesn't already exist
|
|
397
|
+
if (!pageRedirect) {
|
|
398
|
+
pageRedirect = linkResults ? linkResults.redirect : undefined;
|
|
399
|
+
}
|
|
375
400
|
}
|
|
376
401
|
const linkedAssetContent = stringBuilder.toString();
|
|
377
402
|
// Link LWR related resources
|
|
@@ -397,7 +422,7 @@ export class LwrViewRegistry {
|
|
|
397
422
|
...viewRecord,
|
|
398
423
|
},
|
|
399
424
|
cache: { ttl: pageTtl },
|
|
400
|
-
redirect:
|
|
425
|
+
redirect: pageRedirect,
|
|
401
426
|
};
|
|
402
427
|
}
|
|
403
428
|
return {
|
|
@@ -408,7 +433,7 @@ export class LwrViewRegistry {
|
|
|
408
433
|
moduleResources: [],
|
|
409
434
|
},
|
|
410
435
|
cache: { ttl: pageTtl },
|
|
411
|
-
redirect:
|
|
436
|
+
redirect: pageRedirect,
|
|
412
437
|
};
|
|
413
438
|
}
|
|
414
439
|
}
|
|
@@ -4,22 +4,22 @@ import { getHtmlResources as getLegacyHtmlResource } from './legacy_view_bootstr
|
|
|
4
4
|
export async function linkLwrResources(source, view, viewParams, cxt) {
|
|
5
5
|
const { lwrResourcesId, ...resourceContext } = cxt;
|
|
6
6
|
const LEGACY_LOADER = !!resourceContext.runtimeEnvironment.featureFlags.LEGACY_LOADER;
|
|
7
|
-
|
|
7
|
+
return await getTracer().trace({
|
|
8
8
|
name: ViewSpan.Generate,
|
|
9
9
|
attributes: {
|
|
10
10
|
legacyLoader: LEGACY_LOADER,
|
|
11
11
|
},
|
|
12
|
-
}, () => {
|
|
13
|
-
|
|
12
|
+
}, async () => {
|
|
13
|
+
const { partial, viewRecord } = await (LEGACY_LOADER
|
|
14
14
|
? getLegacyHtmlResource(view, viewParams, resourceContext)
|
|
15
|
-
: getHtmlResources(view, viewParams, resourceContext);
|
|
15
|
+
: getHtmlResources(view, viewParams, resourceContext));
|
|
16
|
+
// Finally replace the token with the real resources
|
|
17
|
+
return {
|
|
18
|
+
// partial may contain regex-token-like characters such as $$,
|
|
19
|
+
// so we want to bypass regex replacement
|
|
20
|
+
renderedView: source.replace(lwrResourcesId, () => partial),
|
|
21
|
+
viewRecord,
|
|
22
|
+
};
|
|
16
23
|
});
|
|
17
|
-
// Finally replace the token with the real resources
|
|
18
|
-
return {
|
|
19
|
-
// partial may contain regex-token-like characters such as $$,
|
|
20
|
-
// so we want to bypass regex replacement
|
|
21
|
-
renderedView: source.replace(lwrResourcesId, () => partial),
|
|
22
|
-
viewRecord,
|
|
23
|
-
};
|
|
24
24
|
}
|
|
25
25
|
//# sourceMappingURL=link-lwr-resources.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.15.0-alpha.
|
|
7
|
+
"version": "0.15.0-alpha.27",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -33,17 +33,20 @@
|
|
|
33
33
|
"build": "tsc -b"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@lwrjs/app-service": "0.15.0-alpha.
|
|
37
|
-
"@lwrjs/diagnostics": "0.15.0-alpha.
|
|
38
|
-
"@lwrjs/instrumentation": "0.15.0-alpha.
|
|
39
|
-
"@lwrjs/shared-utils": "0.15.0-alpha.
|
|
36
|
+
"@lwrjs/app-service": "0.15.0-alpha.27",
|
|
37
|
+
"@lwrjs/diagnostics": "0.15.0-alpha.27",
|
|
38
|
+
"@lwrjs/instrumentation": "0.15.0-alpha.27",
|
|
39
|
+
"@lwrjs/shared-utils": "0.15.0-alpha.27",
|
|
40
40
|
"lru-cache": "^10.4.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@lwrjs/types": "0.15.0-alpha.
|
|
43
|
+
"@lwrjs/types": "0.15.0-alpha.27"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=18.0.0"
|
|
47
47
|
},
|
|
48
|
-
"
|
|
48
|
+
"volta": {
|
|
49
|
+
"extends": "../../../package.json"
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "6051c73d6009467325975f79dfa608a10bf2efa8"
|
|
49
52
|
}
|