piral-blazor 1.0.0-pre.2217 → 1.0.0
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/LICENSE +1 -1
- package/README.md +55 -12
- package/convert.d.ts +13 -10
- package/convert.js +17 -12
- package/esm/converter.d.ts +10 -6
- package/esm/converter.js +164 -48
- package/esm/converter.js.map +1 -1
- package/esm/create.d.ts +21 -1
- package/esm/create.js +29 -15
- package/esm/create.js.map +1 -1
- package/esm/dependencies.d.ts +6 -3
- package/esm/dependencies.js +104 -14
- package/esm/dependencies.js.map +1 -1
- package/esm/events.d.ts +6 -0
- package/esm/events.js +145 -0
- package/esm/events.js.map +1 -0
- package/esm/interop.d.ts +29 -0
- package/esm/interop.js +205 -0
- package/esm/interop.js.map +1 -0
- package/esm/navigation.d.ts +2 -0
- package/esm/navigation.js +30 -0
- package/esm/navigation.js.map +1 -0
- package/esm/types.d.ts +97 -4
- package/infra.codegen +53 -68
- package/lib/converter.d.ts +10 -6
- package/lib/converter.js +164 -48
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +21 -1
- package/lib/create.js +31 -17
- package/lib/create.js.map +1 -1
- package/lib/dependencies.d.ts +6 -3
- package/lib/dependencies.js +104 -14
- package/lib/dependencies.js.map +1 -1
- package/lib/events.d.ts +6 -0
- package/lib/events.js +154 -0
- package/lib/events.js.map +1 -0
- package/lib/index.js +1 -1
- package/lib/interop.d.ts +29 -0
- package/lib/interop.js +226 -0
- package/lib/interop.js.map +1 -0
- package/lib/navigation.d.ts +2 -0
- package/lib/navigation.js +35 -0
- package/lib/navigation.js.map +1 -0
- package/lib/types.d.ts +97 -4
- package/package.json +26 -13
- package/src/converter.ts +237 -57
- package/src/create.ts +53 -9
- package/src/dependencies.ts +122 -14
- package/src/events.ts +174 -0
- package/src/interop.ts +273 -0
- package/src/navigation.ts +36 -0
- package/src/types.ts +115 -4
- package/convert.ts +0 -17
- package/esm/internal/Environment.d.ts +0 -3
- package/esm/internal/Environment.js +0 -6
- package/esm/internal/Environment.js.map +0 -1
- package/esm/internal/Platform/BootConfig.d.ts +0 -20
- package/esm/internal/Platform/BootConfig.js +0 -10
- package/esm/internal/Platform/BootConfig.js.map +0 -1
- package/esm/internal/Platform/Mono/MonoDebugger.d.ts +0 -3
- package/esm/internal/Platform/Mono/MonoDebugger.js +0 -43
- package/esm/internal/Platform/Mono/MonoDebugger.js.map +0 -1
- package/esm/internal/Platform/Mono/MonoPlatform.d.ts +0 -2
- package/esm/internal/Platform/Mono/MonoPlatform.js +0 -403
- package/esm/internal/Platform/Mono/MonoPlatform.js.map +0 -1
- package/esm/internal/Platform/Mono/TimezoneDataFile.d.ts +0 -1
- package/esm/internal/Platform/Mono/TimezoneDataFile.js +0 -51
- package/esm/internal/Platform/Mono/TimezoneDataFile.js.map +0 -1
- package/esm/internal/Platform/Platform.d.ts +0 -31
- package/esm/internal/Platform/Platform.js +0 -2
- package/esm/internal/Platform/Platform.js.map +0 -1
- package/esm/internal/Platform/Url.d.ts +0 -2
- package/esm/internal/Platform/Url.js +0 -11
- package/esm/internal/Platform/Url.js.map +0 -1
- package/esm/internal/Platform/WebAssemblyConfigLoader.d.ts +0 -4
- package/esm/internal/Platform/WebAssemblyConfigLoader.js +0 -64
- package/esm/internal/Platform/WebAssemblyConfigLoader.js.map +0 -1
- package/esm/internal/Platform/WebAssemblyResourceLoader.d.ts +0 -24
- package/esm/internal/Platform/WebAssemblyResourceLoader.js +0 -223
- package/esm/internal/Platform/WebAssemblyResourceLoader.js.map +0 -1
- package/esm/internal/Platform/WebAssemblyStartOptions.d.ts +0 -13
- package/esm/internal/Platform/WebAssemblyStartOptions.js +0 -2
- package/esm/internal/Platform/WebAssemblyStartOptions.js.map +0 -1
- package/esm/internal/Rendering/BrowserRenderer.d.ts +0 -38
- package/esm/internal/Rendering/BrowserRenderer.js +0 -458
- package/esm/internal/Rendering/BrowserRenderer.js.map +0 -1
- package/esm/internal/Rendering/ElementReferenceCapture.d.ts +0 -1
- package/esm/internal/Rendering/ElementReferenceCapture.js +0 -24
- package/esm/internal/Rendering/ElementReferenceCapture.js.map +0 -1
- package/esm/internal/Rendering/EventDelegator.d.ts +0 -20
- package/esm/internal/Rendering/EventDelegator.js +0 -236
- package/esm/internal/Rendering/EventDelegator.js.map +0 -1
- package/esm/internal/Rendering/EventFieldInfo.d.ts +0 -6
- package/esm/internal/Rendering/EventFieldInfo.js +0 -32
- package/esm/internal/Rendering/EventFieldInfo.js.map +0 -1
- package/esm/internal/Rendering/EventForDotNet.d.ts +0 -10
- package/esm/internal/Rendering/EventForDotNet.js +0 -194
- package/esm/internal/Rendering/EventForDotNet.js.map +0 -1
- package/esm/internal/Rendering/LogicalElements.d.ts +0 -19
- package/esm/internal/Rendering/LogicalElements.js +0 -250
- package/esm/internal/Rendering/LogicalElements.js.map +0 -1
- package/esm/internal/Rendering/RenderBatch/BinaryDecoder.d.ts +0 -5
- package/esm/internal/Rendering/RenderBatch/BinaryDecoder.js +0 -34
- package/esm/internal/Rendering/RenderBatch/BinaryDecoder.js.map +0 -1
- package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.d.ts +0 -18
- package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js +0 -190
- package/esm/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js.map +0 -1
- package/esm/internal/Rendering/RenderBatch/RenderBatch.d.ts +0 -87
- package/esm/internal/Rendering/RenderBatch/RenderBatch.js +0 -26
- package/esm/internal/Rendering/RenderBatch/RenderBatch.js.map +0 -1
- package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.d.ts +0 -52
- package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js +0 -103
- package/esm/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js.map +0 -1
- package/esm/internal/Rendering/RenderBatch/Utf8Decoder.d.ts +0 -1
- package/esm/internal/Rendering/RenderBatch/Utf8Decoder.js +0 -63
- package/esm/internal/Rendering/RenderBatch/Utf8Decoder.js.map +0 -1
- package/esm/internal/Rendering/Renderer.d.ts +0 -8
- package/esm/internal/Rendering/Renderer.js +0 -69
- package/esm/internal/Rendering/Renderer.js.map +0 -1
- package/esm/internal/Rendering/RendererEventDispatcher.d.ts +0 -4
- package/esm/internal/Rendering/RendererEventDispatcher.js +0 -11
- package/esm/internal/Rendering/RendererEventDispatcher.js.map +0 -1
- package/esm/internal/Services/NavigationManager.d.ts +0 -16
- package/esm/internal/Services/NavigationManager.js +0 -138
- package/esm/internal/Services/NavigationManager.js.map +0 -1
- package/esm/internal/globals.d.ts +0 -1
- package/esm/internal/globals.js +0 -5
- package/esm/internal/globals.js.map +0 -1
- package/esm/internal/index.d.ts +0 -15
- package/esm/internal/index.js +0 -152
- package/esm/internal/index.js.map +0 -1
- package/lib/internal/Environment.d.ts +0 -3
- package/lib/internal/Environment.js +0 -9
- package/lib/internal/Environment.js.map +0 -1
- package/lib/internal/Platform/BootConfig.d.ts +0 -20
- package/lib/internal/Platform/BootConfig.js +0 -13
- package/lib/internal/Platform/BootConfig.js.map +0 -1
- package/lib/internal/Platform/Mono/MonoDebugger.d.ts +0 -3
- package/lib/internal/Platform/Mono/MonoDebugger.js +0 -48
- package/lib/internal/Platform/Mono/MonoDebugger.js.map +0 -1
- package/lib/internal/Platform/Mono/MonoPlatform.d.ts +0 -2
- package/lib/internal/Platform/Mono/MonoPlatform.js +0 -406
- package/lib/internal/Platform/Mono/MonoPlatform.js.map +0 -1
- package/lib/internal/Platform/Mono/TimezoneDataFile.d.ts +0 -1
- package/lib/internal/Platform/Mono/TimezoneDataFile.js +0 -55
- package/lib/internal/Platform/Mono/TimezoneDataFile.js.map +0 -1
- package/lib/internal/Platform/Platform.d.ts +0 -31
- package/lib/internal/Platform/Platform.js +0 -3
- package/lib/internal/Platform/Platform.js.map +0 -1
- package/lib/internal/Platform/Url.d.ts +0 -2
- package/lib/internal/Platform/Url.js +0 -16
- package/lib/internal/Platform/Url.js.map +0 -1
- package/lib/internal/Platform/WebAssemblyConfigLoader.d.ts +0 -4
- package/lib/internal/Platform/WebAssemblyConfigLoader.js +0 -67
- package/lib/internal/Platform/WebAssemblyConfigLoader.js.map +0 -1
- package/lib/internal/Platform/WebAssemblyResourceLoader.d.ts +0 -24
- package/lib/internal/Platform/WebAssemblyResourceLoader.js +0 -226
- package/lib/internal/Platform/WebAssemblyResourceLoader.js.map +0 -1
- package/lib/internal/Platform/WebAssemblyStartOptions.d.ts +0 -13
- package/lib/internal/Platform/WebAssemblyStartOptions.js +0 -3
- package/lib/internal/Platform/WebAssemblyStartOptions.js.map +0 -1
- package/lib/internal/Rendering/BrowserRenderer.d.ts +0 -38
- package/lib/internal/Rendering/BrowserRenderer.js +0 -461
- package/lib/internal/Rendering/BrowserRenderer.js.map +0 -1
- package/lib/internal/Rendering/ElementReferenceCapture.d.ts +0 -1
- package/lib/internal/Rendering/ElementReferenceCapture.js +0 -28
- package/lib/internal/Rendering/ElementReferenceCapture.js.map +0 -1
- package/lib/internal/Rendering/EventDelegator.d.ts +0 -20
- package/lib/internal/Rendering/EventDelegator.js +0 -239
- package/lib/internal/Rendering/EventDelegator.js.map +0 -1
- package/lib/internal/Rendering/EventFieldInfo.d.ts +0 -6
- package/lib/internal/Rendering/EventFieldInfo.js +0 -35
- package/lib/internal/Rendering/EventFieldInfo.js.map +0 -1
- package/lib/internal/Rendering/EventForDotNet.d.ts +0 -10
- package/lib/internal/Rendering/EventForDotNet.js +0 -197
- package/lib/internal/Rendering/EventForDotNet.js.map +0 -1
- package/lib/internal/Rendering/LogicalElements.d.ts +0 -19
- package/lib/internal/Rendering/LogicalElements.js +0 -265
- package/lib/internal/Rendering/LogicalElements.js.map +0 -1
- package/lib/internal/Rendering/RenderBatch/BinaryDecoder.d.ts +0 -5
- package/lib/internal/Rendering/RenderBatch/BinaryDecoder.js +0 -42
- package/lib/internal/Rendering/RenderBatch/BinaryDecoder.js.map +0 -1
- package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.d.ts +0 -18
- package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js +0 -193
- package/lib/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.js.map +0 -1
- package/lib/internal/Rendering/RenderBatch/RenderBatch.d.ts +0 -87
- package/lib/internal/Rendering/RenderBatch/RenderBatch.js +0 -29
- package/lib/internal/Rendering/RenderBatch/RenderBatch.js.map +0 -1
- package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.d.ts +0 -52
- package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js +0 -106
- package/lib/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.js.map +0 -1
- package/lib/internal/Rendering/RenderBatch/Utf8Decoder.d.ts +0 -1
- package/lib/internal/Rendering/RenderBatch/Utf8Decoder.js +0 -66
- package/lib/internal/Rendering/RenderBatch/Utf8Decoder.js.map +0 -1
- package/lib/internal/Rendering/Renderer.d.ts +0 -8
- package/lib/internal/Rendering/Renderer.js +0 -76
- package/lib/internal/Rendering/Renderer.js.map +0 -1
- package/lib/internal/Rendering/RendererEventDispatcher.d.ts +0 -4
- package/lib/internal/Rendering/RendererEventDispatcher.js +0 -16
- package/lib/internal/Rendering/RendererEventDispatcher.js.map +0 -1
- package/lib/internal/Services/NavigationManager.d.ts +0 -16
- package/lib/internal/Services/NavigationManager.js +0 -144
- package/lib/internal/Services/NavigationManager.js.map +0 -1
- package/lib/internal/globals.d.ts +0 -1
- package/lib/internal/globals.js +0 -7
- package/lib/internal/globals.js.map +0 -1
- package/lib/internal/index.d.ts +0 -15
- package/lib/internal/index.js +0 -161
- package/lib/internal/index.js.map +0 -1
- package/src/internal/Environment.ts +0 -11
- package/src/internal/Platform/BootConfig.ts +0 -21
- package/src/internal/Platform/Mono/MonoDebugger.ts +0 -48
- package/src/internal/Platform/Mono/MonoPlatform.ts +0 -494
- package/src/internal/Platform/Mono/MonoTypes.d.ts +0 -27
- package/src/internal/Platform/Mono/TimezoneDataFile.ts +0 -46
- package/src/internal/Platform/Platform.ts +0 -40
- package/src/internal/Platform/Url.ts +0 -11
- package/src/internal/Platform/WebAssemblyConfigLoader.ts +0 -34
- package/src/internal/Platform/WebAssemblyResourceLoader.ts +0 -234
- package/src/internal/Platform/WebAssemblyStartOptions.ts +0 -22
- package/src/internal/Rendering/BrowserRenderer.ts +0 -616
- package/src/internal/Rendering/ElementReferenceCapture.ts +0 -27
- package/src/internal/Rendering/EventDelegator.ts +0 -293
- package/src/internal/Rendering/EventFieldInfo.ts +0 -31
- package/src/internal/Rendering/EventForDotNet.ts +0 -370
- package/src/internal/Rendering/LogicalElements.ts +0 -289
- package/src/internal/Rendering/RenderBatch/BinaryDecoder.ts +0 -43
- package/src/internal/Rendering/RenderBatch/OutOfProcessRenderBatch.ts +0 -244
- package/src/internal/Rendering/RenderBatch/RenderBatch.ts +0 -100
- package/src/internal/Rendering/RenderBatch/SharedMemoryRenderBatch.ts +0 -137
- package/src/internal/Rendering/RenderBatch/Utf8Decoder.ts +0 -66
- package/src/internal/Rendering/Renderer.ts +0 -98
- package/src/internal/Rendering/RendererEventDispatcher.ts +0 -20
- package/src/internal/Services/NavigationManager.ts +0 -157
- package/src/internal/globals.ts +0 -5
- package/src/internal/index.ts +0 -170
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { toAbsoluteUri } from '../Services/NavigationManager';
|
|
2
|
-
import { BootJsonData, ResourceList } from './BootConfig';
|
|
3
|
-
import { WebAssemblyStartOptions, WebAssemblyBootResourceType } from './WebAssemblyStartOptions';
|
|
4
|
-
|
|
5
|
-
const networkFetchCacheMode = 'no-cache';
|
|
6
|
-
|
|
7
|
-
export class WebAssemblyResourceLoader {
|
|
8
|
-
private usedCacheKeys: { [key: string]: boolean } = {};
|
|
9
|
-
private networkLoads: { [name: string]: LoadLogEntry } = {};
|
|
10
|
-
private cacheLoads: { [name: string]: LoadLogEntry } = {};
|
|
11
|
-
|
|
12
|
-
static async initAsync(
|
|
13
|
-
bootConfig: BootJsonData,
|
|
14
|
-
startOptions: Partial<WebAssemblyStartOptions>,
|
|
15
|
-
): Promise<WebAssemblyResourceLoader> {
|
|
16
|
-
const cache = await getCacheToUseIfEnabled(bootConfig);
|
|
17
|
-
return new WebAssemblyResourceLoader(bootConfig, cache, startOptions);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
readonly bootConfig: BootJsonData,
|
|
22
|
-
readonly cacheIfUsed: Cache | null,
|
|
23
|
-
readonly startOptions: Partial<WebAssemblyStartOptions>,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
loadResources(
|
|
27
|
-
resources: ResourceList,
|
|
28
|
-
url: (name: string) => string,
|
|
29
|
-
resourceType: WebAssemblyBootResourceType,
|
|
30
|
-
): LoadingResource[] {
|
|
31
|
-
return Object.keys(resources).map((name) => this.loadResource(name, url(name), resources[name], resourceType));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
loadResource(
|
|
35
|
-
name: string,
|
|
36
|
-
url: string,
|
|
37
|
-
contentHash: string,
|
|
38
|
-
resourceType: WebAssemblyBootResourceType,
|
|
39
|
-
): LoadingResource {
|
|
40
|
-
const response = this.cacheIfUsed
|
|
41
|
-
? this.loadResourceWithCaching(this.cacheIfUsed, name, url, contentHash, resourceType)
|
|
42
|
-
: this.loadResourceWithoutCaching(name, url, contentHash, resourceType);
|
|
43
|
-
|
|
44
|
-
return { name, url, response };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
logToConsole() {
|
|
48
|
-
const cacheLoadsEntries = Object.values(this.cacheLoads);
|
|
49
|
-
const networkLoadsEntries = Object.values(this.networkLoads);
|
|
50
|
-
const cacheResponseBytes = countTotalBytes(cacheLoadsEntries);
|
|
51
|
-
const networkResponseBytes = countTotalBytes(networkLoadsEntries);
|
|
52
|
-
const totalResponseBytes = cacheResponseBytes + networkResponseBytes;
|
|
53
|
-
if (totalResponseBytes === 0) {
|
|
54
|
-
// We have no perf stats to display, likely because caching is not in use.
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const linkerDisabledWarning = this.bootConfig.linkerEnabled
|
|
59
|
-
? '%c'
|
|
60
|
-
: '\n%cThis application was built with linking (tree shaking) disabled. Published applications will be significantly smaller.';
|
|
61
|
-
console.groupCollapsed(
|
|
62
|
-
`%cblazor%c Loaded ${toDataSizeString(totalResponseBytes)} resources${linkerDisabledWarning}`,
|
|
63
|
-
'background: purple; color: white; padding: 1px 3px; border-radius: 3px;',
|
|
64
|
-
'font-weight: bold;',
|
|
65
|
-
'font-weight: normal;',
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
if (cacheLoadsEntries.length) {
|
|
69
|
-
console.groupCollapsed(`Loaded ${toDataSizeString(cacheResponseBytes)} resources from cache`);
|
|
70
|
-
console.table(this.cacheLoads);
|
|
71
|
-
console.groupEnd();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (networkLoadsEntries.length) {
|
|
75
|
-
console.groupCollapsed(`Loaded ${toDataSizeString(networkResponseBytes)} resources from network`);
|
|
76
|
-
console.table(this.networkLoads);
|
|
77
|
-
console.groupEnd();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
console.groupEnd();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async purgeUnusedCacheEntriesAsync() {
|
|
84
|
-
// We want to keep the cache small because, even though the browser will evict entries if it
|
|
85
|
-
// gets too big, we don't want to be considered problematic by the end user viewing storage stats
|
|
86
|
-
const cache = this.cacheIfUsed;
|
|
87
|
-
if (cache) {
|
|
88
|
-
const cachedRequests = await cache.keys();
|
|
89
|
-
const deletionPromises = cachedRequests.map(async (cachedRequest) => {
|
|
90
|
-
if (!(cachedRequest.url in this.usedCacheKeys)) {
|
|
91
|
-
await cache.delete(cachedRequest);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
await Promise.all(deletionPromises);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
private async loadResourceWithCaching(
|
|
100
|
-
cache: Cache,
|
|
101
|
-
name: string,
|
|
102
|
-
url: string,
|
|
103
|
-
contentHash: string,
|
|
104
|
-
resourceType: WebAssemblyBootResourceType,
|
|
105
|
-
) {
|
|
106
|
-
// Since we are going to cache the response, we require there to be a content hash for integrity
|
|
107
|
-
// checking. We don't want to cache bad responses. There should always be a hash, because the build
|
|
108
|
-
// process generates this data.
|
|
109
|
-
if (!contentHash || contentHash.length === 0) {
|
|
110
|
-
throw new Error('Content hash is required');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const cacheKey = toAbsoluteUri(`${url}.${contentHash}`);
|
|
114
|
-
this.usedCacheKeys[cacheKey] = true;
|
|
115
|
-
|
|
116
|
-
const cachedResponse = await cache.match(cacheKey);
|
|
117
|
-
if (cachedResponse) {
|
|
118
|
-
// It's in the cache.
|
|
119
|
-
const responseBytes = parseInt(cachedResponse.headers.get('content-length') || '0');
|
|
120
|
-
this.cacheLoads[name] = { responseBytes };
|
|
121
|
-
return cachedResponse;
|
|
122
|
-
} else {
|
|
123
|
-
// It's not in the cache. Fetch from network.
|
|
124
|
-
const networkResponse = await this.loadResourceWithoutCaching(name, url, contentHash, resourceType);
|
|
125
|
-
this.addToCacheAsync(cache, name, cacheKey, networkResponse); // Don't await - add to cache in background
|
|
126
|
-
return networkResponse;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private loadResourceWithoutCaching(
|
|
131
|
-
name: string,
|
|
132
|
-
url: string,
|
|
133
|
-
contentHash: string,
|
|
134
|
-
resourceType: WebAssemblyBootResourceType,
|
|
135
|
-
): Promise<Response> {
|
|
136
|
-
// Allow developers to override how the resource is loaded
|
|
137
|
-
if (this.startOptions.loadBootResource) {
|
|
138
|
-
const customLoadResult = this.startOptions.loadBootResource(resourceType, name, url, contentHash);
|
|
139
|
-
if (customLoadResult instanceof Promise) {
|
|
140
|
-
// They are supplying an entire custom response, so just use that
|
|
141
|
-
return customLoadResult;
|
|
142
|
-
} else if (typeof customLoadResult === 'string') {
|
|
143
|
-
// They are supplying a custom URL, so use that with the default fetch behavior
|
|
144
|
-
url = customLoadResult;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Note that if cacheBootResources was explicitly disabled, we also bypass hash checking
|
|
149
|
-
// This is to give developers an easy opt-out from the entire caching/validation flow if
|
|
150
|
-
// there's anything they don't like about it.
|
|
151
|
-
return fetch(url, {
|
|
152
|
-
cache: networkFetchCacheMode,
|
|
153
|
-
integrity: this.bootConfig.cacheBootResources ? contentHash : undefined,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
private async addToCacheAsync(cache: Cache, name: string, cacheKey: string, response: Response) {
|
|
158
|
-
// We have to clone in order to put this in the cache *and* not prevent other code from
|
|
159
|
-
// reading the original response stream.
|
|
160
|
-
const responseData = await response.clone().arrayBuffer();
|
|
161
|
-
|
|
162
|
-
// Now is an ideal moment to capture the performance stats for the request, since it
|
|
163
|
-
// only just completed and is most likely to still be in the buffer. However this is
|
|
164
|
-
// only done on a 'best effort' basis. Even if we do receive an entry, some of its
|
|
165
|
-
// properties may be blanked out if it was a CORS request.
|
|
166
|
-
const performanceEntry = getPerformanceEntry(response.url);
|
|
167
|
-
const responseBytes = (performanceEntry && performanceEntry.encodedBodySize) || undefined;
|
|
168
|
-
this.networkLoads[name] = { responseBytes };
|
|
169
|
-
|
|
170
|
-
// Add to cache as a custom response object so we can track extra data such as responseBytes
|
|
171
|
-
// We can't rely on the server sending content-length (ASP.NET Core doesn't by default)
|
|
172
|
-
await cache.put(
|
|
173
|
-
cacheKey,
|
|
174
|
-
new Response(responseData, {
|
|
175
|
-
headers: {
|
|
176
|
-
'content-type': response.headers.get('content-type') || '',
|
|
177
|
-
'content-length': (responseBytes || response.headers.get('content-length') || '').toString(),
|
|
178
|
-
},
|
|
179
|
-
}),
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async function getCacheToUseIfEnabled(bootConfig: BootJsonData): Promise<Cache | null> {
|
|
185
|
-
// caches will be undefined if we're running on an insecure origin (secure means https or localhost)
|
|
186
|
-
if (!bootConfig.cacheBootResources || typeof caches === 'undefined') {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Define a separate cache for each base href, so we're isolated from any other
|
|
191
|
-
// Blazor application running on the same origin. We need this so that we're free
|
|
192
|
-
// to purge from the cache anything we're not using and don't let it keep growing,
|
|
193
|
-
// since we don't want to be worst offenders for space usage.
|
|
194
|
-
const relativeBaseHref = document.baseURI.substring(document.location.origin.length);
|
|
195
|
-
const cacheName = `blazor-resources-${relativeBaseHref}`;
|
|
196
|
-
|
|
197
|
-
try {
|
|
198
|
-
// There's a Chromium bug we need to be aware of here: the CacheStorage APIs say that when
|
|
199
|
-
// caches.open(name) returns a promise that succeeds, the value is meant to be a Cache instance.
|
|
200
|
-
// However, if the browser was launched with a --user-data-dir param that's "too long" in some sense,
|
|
201
|
-
// then even through the promise resolves as success, the value given is `undefined`.
|
|
202
|
-
// See https://stackoverflow.com/a/46626574 and https://bugs.chromium.org/p/chromium/issues/detail?id=1054541
|
|
203
|
-
// If we see this happening, return "null" to mean "proceed without caching".
|
|
204
|
-
return (await caches.open(cacheName)) || null;
|
|
205
|
-
} catch {
|
|
206
|
-
// There's no known scenario where we should get an exception here, but considering the
|
|
207
|
-
// Chromium bug above, let's tolerate it and treat as "proceed without caching".
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function countTotalBytes(loads: LoadLogEntry[]) {
|
|
213
|
-
return loads.reduce((prev, item) => prev + (item.responseBytes || 0), 0);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function toDataSizeString(byteCount: number) {
|
|
217
|
-
return `${(byteCount / (1024 * 1024)).toFixed(2)} MB`;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function getPerformanceEntry(url: string): PerformanceResourceTiming | undefined {
|
|
221
|
-
if (typeof performance !== 'undefined') {
|
|
222
|
-
return performance.getEntriesByName(url)[0] as PerformanceResourceTiming;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
interface LoadLogEntry {
|
|
227
|
-
responseBytes: number | undefined;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export interface LoadingResource {
|
|
231
|
-
name: string;
|
|
232
|
-
url: string;
|
|
233
|
-
response: Promise<Response>;
|
|
234
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface WebAssemblyStartOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Overrides the built-in boot resource loading mechanism so that boot resources can be fetched
|
|
4
|
-
* from a custom source, such as an external CDN.
|
|
5
|
-
* @param type The type of the resource to be loaded.
|
|
6
|
-
* @param name The name of the resource to be loaded.
|
|
7
|
-
* @param defaultUri The URI from which the framework would fetch the resource by default. The URI may be relative or absolute.
|
|
8
|
-
* @param integrity The integrity string representing the expected content in the response.
|
|
9
|
-
* @returns A URI string or a Response promise to override the loading process, or null/undefined to allow the default loading behavior.
|
|
10
|
-
*/
|
|
11
|
-
loadBootResource(
|
|
12
|
-
type: WebAssemblyBootResourceType,
|
|
13
|
-
name: string,
|
|
14
|
-
defaultUri: string,
|
|
15
|
-
integrity: string,
|
|
16
|
-
): string | Promise<Response> | null | undefined;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// This type doesn't have to align with anything in BootConfig.
|
|
20
|
-
// Instead, this represents the public API through which certain aspects
|
|
21
|
-
// of boot resource loading can be customized.
|
|
22
|
-
export type WebAssemblyBootResourceType = 'assembly' | 'pdb' | 'dotnetjs' | 'dotnetwasm' | 'timezonedata';
|