@lynx-js/web-core 0.15.7 → 0.16.1
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/CHANGELOG.md +45 -0
- package/dist/uiThread/bootWorkers.d.ts +2 -1
- package/dist/uiThread/bootWorkers.js +12 -7
- package/dist/uiThread/createRenderAllOnUI.d.ts +3 -4
- package/dist/uiThread/createRenderAllOnUI.js +71 -7
- package/dist/uiThread/createRenderMultiThread.d.ts +3 -3
- package/dist/uiThread/createRenderMultiThread.js +3 -2
- package/dist/uiThread/startUIThread.d.ts +2 -2
- package/dist/uiThread/startUIThread.js +6 -7
- package/dist/utils/loadTemplate.d.ts +2 -2
- package/dist/utils/loadTemplate.js +24 -17
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# @lynx-js/web-core
|
|
2
2
|
|
|
3
|
+
## 0.16.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- refactor: improve chunk loading ([#1703](https://github.com/lynx-family/lynx-stack/pull/1703))
|
|
8
|
+
|
|
9
|
+
- feat: supports lazy bundle. (This feature requires `@lynx-js/lynx-core >= 0.1.3`) ([#1235](https://github.com/lynx-family/lynx-stack/pull/1235))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`608f375`](https://github.com/lynx-family/lynx-stack/commit/608f375e20732cc4c9f141bfbf9800ba6896100b)]:
|
|
12
|
+
- @lynx-js/web-mainthread-apis@0.16.1
|
|
13
|
+
- @lynx-js/web-worker-runtime@0.16.1
|
|
14
|
+
- @lynx-js/web-constants@0.16.1
|
|
15
|
+
- @lynx-js/web-worker-rpc@0.16.1
|
|
16
|
+
|
|
17
|
+
## 0.16.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- refactor: provide the mts a real globalThis ([#1589](https://github.com/lynx-family/lynx-stack/pull/1589))
|
|
22
|
+
|
|
23
|
+
Before this change, We create a function wrapper and a fake globalThis for Javascript code.
|
|
24
|
+
|
|
25
|
+
This caused some issues.
|
|
26
|
+
|
|
27
|
+
After this change, we will create an iframe for createing an isolated Javascript context.
|
|
28
|
+
|
|
29
|
+
This means the globalThis will be the real one.
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- refactor: add `:not([l-e-name])` at the end of selector for lazy component ([#1622](https://github.com/lynx-family/lynx-stack/pull/1622))
|
|
34
|
+
|
|
35
|
+
- feat: remove multi-thread mts heating ([#1597](https://github.com/lynx-family/lynx-stack/pull/1597))
|
|
36
|
+
|
|
37
|
+
The default rendering mode is "all-on-ui". Therefore the preheating for "multi-thread" will be removed.
|
|
38
|
+
|
|
39
|
+
- fix: the SystemInfo in bts should be assigned to the globalThis ([#1599](https://github.com/lynx-family/lynx-stack/pull/1599))
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [[`1a32dd8`](https://github.com/lynx-family/lynx-stack/commit/1a32dd886fe736c95639f67028cf7685377d9769), [`bb53d9a`](https://github.com/lynx-family/lynx-stack/commit/bb53d9a035f607e7c89952098d4ed77877a2e3c1), [`1a32dd8`](https://github.com/lynx-family/lynx-stack/commit/1a32dd886fe736c95639f67028cf7685377d9769), [`c1f8715`](https://github.com/lynx-family/lynx-stack/commit/c1f8715a81b2e69ff46fc363013626db4468c209)]:
|
|
42
|
+
- @lynx-js/web-mainthread-apis@0.16.0
|
|
43
|
+
- @lynx-js/web-constants@0.16.0
|
|
44
|
+
- @lynx-js/web-worker-runtime@0.16.0
|
|
45
|
+
- @lynx-js/offscreen-document@0.1.4
|
|
46
|
+
- @lynx-js/web-worker-rpc@0.16.0
|
|
47
|
+
|
|
3
48
|
## 0.15.7
|
|
4
49
|
|
|
5
50
|
### Patch Changes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { type BrowserConfig } from '@lynx-js/web-constants';
|
|
1
2
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
3
|
interface LynxViewRpc {
|
|
3
4
|
mainThreadRpc: Rpc;
|
|
4
5
|
backgroundRpc: Rpc;
|
|
5
6
|
terminateWorkers: () => void;
|
|
6
7
|
}
|
|
7
|
-
export declare function bootWorkers(lynxGroupId: number | undefined, allOnUI
|
|
8
|
+
export declare function bootWorkers(lynxGroupId: number | undefined, allOnUI: boolean, browserConfig: BrowserConfig): LynxViewRpc;
|
|
8
9
|
export {};
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { systemInfo } from '@lynx-js/web-constants';
|
|
4
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
5
6
|
const backgroundWorkerContextCount = [];
|
|
6
7
|
const contextIdToBackgroundWorker = [];
|
|
7
|
-
|
|
8
|
-
export function bootWorkers(lynxGroupId, allOnUI) {
|
|
8
|
+
export function bootWorkers(lynxGroupId, allOnUI, browserConfig) {
|
|
9
9
|
let curMainWorker;
|
|
10
10
|
if (allOnUI) {
|
|
11
11
|
curMainWorker = createUIChannel();
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
curMainWorker =
|
|
15
|
-
preHeatedMainWorker = createMainWorker();
|
|
14
|
+
curMainWorker = createMainWorker();
|
|
16
15
|
}
|
|
17
|
-
const curBackgroundWorker = createBackgroundWorker(lynxGroupId, curMainWorker.channelMainThreadWithBackground);
|
|
16
|
+
const curBackgroundWorker = createBackgroundWorker(lynxGroupId, curMainWorker.channelMainThreadWithBackground, browserConfig);
|
|
18
17
|
if (lynxGroupId !== undefined) {
|
|
19
18
|
if (backgroundWorkerContextCount[lynxGroupId]) {
|
|
20
19
|
backgroundWorkerContextCount[lynxGroupId]++;
|
|
@@ -71,7 +70,7 @@ function createMainWorker() {
|
|
|
71
70
|
channelMainThreadWithBackground,
|
|
72
71
|
};
|
|
73
72
|
}
|
|
74
|
-
function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground) {
|
|
73
|
+
function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground, browserConfig) {
|
|
75
74
|
const channelToBackground = new MessageChannel();
|
|
76
75
|
let backgroundThreadWorker;
|
|
77
76
|
if (lynxGroupId) {
|
|
@@ -86,6 +85,7 @@ function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground) {
|
|
|
86
85
|
mode: 'background',
|
|
87
86
|
toUIThread: channelToBackground.port2,
|
|
88
87
|
toPeerThread: channelMainThreadWithBackground.port2,
|
|
88
|
+
systemInfo: { ...systemInfo, ...browserConfig },
|
|
89
89
|
};
|
|
90
90
|
backgroundThreadWorker.postMessage(backgroundThreadMessage, [
|
|
91
91
|
channelToBackground.port2,
|
|
@@ -95,7 +95,12 @@ function createBackgroundWorker(lynxGroupId, channelMainThreadWithBackground) {
|
|
|
95
95
|
return { backgroundRpc, backgroundThreadWorker };
|
|
96
96
|
}
|
|
97
97
|
function createWebWorker(name) {
|
|
98
|
-
return new Worker(
|
|
98
|
+
return new Worker(
|
|
99
|
+
/* webpackFetchPriority: "high" */
|
|
100
|
+
/* webpackChunkName: "web-core-worker-runtime" */
|
|
101
|
+
/* webpackPrefetch: true */
|
|
102
|
+
/* webpackPreload: true */
|
|
103
|
+
new URL('@lynx-js/web-worker-runtime', import.meta.url), {
|
|
99
104
|
type: 'module',
|
|
100
105
|
name,
|
|
101
106
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { type StartMainThreadContextConfig, type Cloneable, type SSRDumpInfo } from '@lynx-js/web-constants';
|
|
1
|
+
import { type StartMainThreadContextConfig, type Cloneable, type SSRDumpInfo, type TemplateLoader } from '@lynx-js/web-constants';
|
|
2
2
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}, ssrDumpInfo: SSRDumpInfo | undefined): {
|
|
3
|
+
import type { StartUIThreadCallbacks } from './startUIThread.js';
|
|
4
|
+
export declare function createRenderAllOnUI(mainToBackgroundRpc: Rpc, shadowRoot: ShadowRoot, loadTemplate: TemplateLoader, markTimingInternal: (timingKey: string, pipelineId?: string, timeStamp?: number) => void, flushMarkTimingInternal: () => void, callbacks: StartUIThreadCallbacks, ssrDumpInfo: SSRDumpInfo | undefined): {
|
|
6
5
|
start: (configs: StartMainThreadContextConfig) => Promise<void>;
|
|
7
6
|
updateDataMainThread: (args_0: Cloneable, args_1: Record<string, string>) => Promise<void>;
|
|
8
7
|
updateI18nResourcesMainThread: (data: Cloneable) => void;
|
|
@@ -5,8 +5,71 @@ import { i18nResourceMissedEventName, I18nResources, lynxUniqueIdAttribute, } fr
|
|
|
5
5
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
6
6
|
import { dispatchLynxViewEvent } from '../utils/dispatchLynxViewEvent.js';
|
|
7
7
|
import { createExposureMonitor } from './crossThreadHandlers/createExposureMonitor.js';
|
|
8
|
-
const { prepareMainThreadAPIs, } = await import(
|
|
9
|
-
|
|
8
|
+
const { prepareMainThreadAPIs, } = await import(
|
|
9
|
+
/* webpackChunkName: "web-core-main-thread-apis" */
|
|
10
|
+
/* webpackMode: "lazy-once" */
|
|
11
|
+
/* webpackPreload: true */
|
|
12
|
+
/* webpackPrefetch: true */
|
|
13
|
+
/* webpackFetchPriority: "high" */
|
|
14
|
+
'@lynx-js/web-mainthread-apis');
|
|
15
|
+
/**
|
|
16
|
+
* Creates a isolated JavaScript context for executing mts code.
|
|
17
|
+
* This context has its own global variables and functions.
|
|
18
|
+
*/
|
|
19
|
+
function createIFrameRealm(parent) {
|
|
20
|
+
const iframe = document.createElement('iframe');
|
|
21
|
+
const iframeLoaded = new Promise((resolve) => {
|
|
22
|
+
iframe.onload = () => resolve();
|
|
23
|
+
});
|
|
24
|
+
iframe.style.display = 'none';
|
|
25
|
+
iframe.src = 'about:blank';
|
|
26
|
+
parent.appendChild(iframe);
|
|
27
|
+
const iframeWindow = iframe.contentWindow;
|
|
28
|
+
const iframeDocument = iframe.contentDocument;
|
|
29
|
+
const loadScript = (url) => {
|
|
30
|
+
return new Promise(async (resolve, reject) => {
|
|
31
|
+
if (iframeDocument.readyState !== 'complete') {
|
|
32
|
+
await iframeLoaded;
|
|
33
|
+
}
|
|
34
|
+
const script = iframeDocument.createElement('script');
|
|
35
|
+
script.src = url;
|
|
36
|
+
script.fetchPriority = 'high';
|
|
37
|
+
script.defer = true;
|
|
38
|
+
script.async = false;
|
|
39
|
+
script.onload = () => {
|
|
40
|
+
const ret = iframeWindow?.module?.exports;
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
iframeWindow.module = { exports: undefined };
|
|
43
|
+
resolve(ret);
|
|
44
|
+
};
|
|
45
|
+
script.onerror = (err) => reject(new Error(`Failed to load script: ${url}`, { cause: err }));
|
|
46
|
+
// @ts-expect-error
|
|
47
|
+
iframeWindow.module = { exports: undefined };
|
|
48
|
+
iframe.contentDocument.head.appendChild(script);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const loadScriptSync = (url) => {
|
|
52
|
+
const xhr = new XMLHttpRequest();
|
|
53
|
+
xhr.open('GET', url, false); // Synchronous request
|
|
54
|
+
xhr.send(null);
|
|
55
|
+
if (xhr.status === 200) {
|
|
56
|
+
const script = iframe.contentDocument.createElement('script');
|
|
57
|
+
script.textContent = xhr.responseText;
|
|
58
|
+
// @ts-expect-error
|
|
59
|
+
iframeWindow.module = { exports: undefined };
|
|
60
|
+
iframe.contentDocument.head.appendChild(script);
|
|
61
|
+
const ret = iframeWindow?.module?.exports;
|
|
62
|
+
// @ts-expect-error
|
|
63
|
+
iframeWindow.module = { exports: undefined };
|
|
64
|
+
return ret;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(`Failed to load script: ${url}`, { cause: xhr });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return { globalWindow: iframeWindow, loadScript, loadScriptSync };
|
|
71
|
+
}
|
|
72
|
+
export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, loadTemplate, markTimingInternal, flushMarkTimingInternal, callbacks, ssrDumpInfo) {
|
|
10
73
|
if (!globalThis.module) {
|
|
11
74
|
Object.assign(globalThis, { module: {} });
|
|
12
75
|
}
|
|
@@ -15,13 +78,14 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
|
|
|
15
78
|
};
|
|
16
79
|
const i18nResources = new I18nResources();
|
|
17
80
|
const { exposureChangedCallback } = createExposureMonitor(shadowRoot);
|
|
18
|
-
const
|
|
81
|
+
const mtsRealm = createIFrameRealm(shadowRoot);
|
|
82
|
+
const mtsGlobalThis = mtsRealm.globalWindow;
|
|
83
|
+
const { startMainThread } = prepareMainThreadAPIs(mainToBackgroundRpc, shadowRoot, document, mtsRealm, exposureChangedCallback, markTimingInternal, flushMarkTimingInternal, (err, _, release) => {
|
|
19
84
|
callbacks.onError?.(err, release, 'lepus.js');
|
|
20
85
|
}, triggerI18nResourceFallback, (initI18nResources) => {
|
|
21
86
|
i18nResources.setData(initI18nResources);
|
|
22
87
|
return i18nResources;
|
|
23
|
-
});
|
|
24
|
-
let mtsGlobalThis;
|
|
88
|
+
}, loadTemplate);
|
|
25
89
|
const pendingUpdateCalls = [];
|
|
26
90
|
const start = async (configs) => {
|
|
27
91
|
if (ssrDumpInfo) {
|
|
@@ -46,7 +110,7 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
|
|
|
46
110
|
}
|
|
47
111
|
}
|
|
48
112
|
}
|
|
49
|
-
|
|
113
|
+
await startMainThread(configs, {
|
|
50
114
|
// @ts-expect-error
|
|
51
115
|
lynxUniqueIdToElement: lynxUniqueIdToElement,
|
|
52
116
|
lynxUniqueIdToStyleRulesIndex,
|
|
@@ -55,7 +119,7 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
|
|
|
55
119
|
});
|
|
56
120
|
}
|
|
57
121
|
else {
|
|
58
|
-
|
|
122
|
+
await startMainThread(configs);
|
|
59
123
|
}
|
|
60
124
|
// Process any pending update calls that were queued while mtsGlobalThis was undefined
|
|
61
125
|
for (const args of pendingUpdateCalls) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { type TemplateLoader } from '@lynx-js/web-constants';
|
|
1
2
|
import type { Rpc } from '@lynx-js/web-worker-rpc';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}): {
|
|
3
|
+
import type { StartUIThreadCallbacks } from './startUIThread.js';
|
|
4
|
+
export declare function createRenderMultiThread(mainThreadRpc: Rpc, shadowRoot: ShadowRoot, loadTemplate: TemplateLoader, callbacks: StartUIThreadCallbacks): {
|
|
5
5
|
start: (args_0: import("@lynx-js/web-constants").StartMainThreadContextConfig) => void;
|
|
6
6
|
updateDataMainThread: (args_0: import("@lynx-js/web-constants").Cloneable, args_1: Record<string, string>) => Promise<void>;
|
|
7
7
|
updateI18nResourcesMainThread: (args_0: import("@lynx-js/web-constants").Cloneable) => void;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
// Copyright 2023 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
-
import { mainThreadStartEndpoint, updateDataEndpoint, updateI18nResourcesEndpoint, } from '@lynx-js/web-constants';
|
|
4
|
+
import { loadTemplateMultiThread, mainThreadStartEndpoint, updateDataEndpoint, updateI18nResourcesEndpoint, } from '@lynx-js/web-constants';
|
|
5
5
|
import { registerReportErrorHandler } from './crossThreadHandlers/registerReportErrorHandler.js';
|
|
6
6
|
import { registerFlushElementTreeHandler } from './crossThreadHandlers/registerFlushElementTreeHandler.js';
|
|
7
7
|
import { registerDispatchLynxViewEventHandler } from './crossThreadHandlers/registerDispatchLynxViewEventHandler.js';
|
|
8
8
|
import { createExposureMonitorForMultiThread } from './crossThreadHandlers/createExposureMonitor.js';
|
|
9
|
-
export function createRenderMultiThread(mainThreadRpc, shadowRoot, callbacks) {
|
|
9
|
+
export function createRenderMultiThread(mainThreadRpc, shadowRoot, loadTemplate, callbacks) {
|
|
10
10
|
registerReportErrorHandler(mainThreadRpc, 'lepus.js', callbacks.onError);
|
|
11
11
|
registerFlushElementTreeHandler(mainThreadRpc, { shadowRoot });
|
|
12
12
|
registerDispatchLynxViewEventHandler(mainThreadRpc, shadowRoot);
|
|
13
13
|
createExposureMonitorForMultiThread(mainThreadRpc, shadowRoot);
|
|
14
|
+
mainThreadRpc.registerHandler(loadTemplateMultiThread, loadTemplate);
|
|
14
15
|
const start = mainThreadRpc.createCall(mainThreadStartEndpoint);
|
|
15
16
|
const updateDataMainThread = mainThreadRpc.createCall(updateDataEndpoint);
|
|
16
17
|
const updateI18nResourcesMainThread = mainThreadRpc.createCall(updateI18nResourcesEndpoint);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { LynxView } from '../apis/createLynxView.js';
|
|
2
|
-
import { type
|
|
2
|
+
import { type StartMainThreadContextConfig, type NapiModulesCall, type NativeModulesCall, type SSRDumpInfo, type TemplateLoader } from '@lynx-js/web-constants';
|
|
3
3
|
export type StartUIThreadCallbacks = {
|
|
4
4
|
nativeModulesCall: NativeModulesCall;
|
|
5
5
|
napiModulesCall: NapiModulesCall;
|
|
6
6
|
onError?: (err: Error, release: string, fileName: string) => void;
|
|
7
|
-
customTemplateLoader?:
|
|
7
|
+
customTemplateLoader?: TemplateLoader;
|
|
8
8
|
};
|
|
9
9
|
export declare function startUIThread(templateUrl: string, configs: Omit<StartMainThreadContextConfig, 'template'>, shadowRoot: ShadowRoot, lynxGroupId: number | undefined, threadStrategy: 'all-on-ui' | 'multi-thread', callbacks: StartUIThreadCallbacks, ssr?: SSRDumpInfo): LynxView;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { bootWorkers } from './bootWorkers.js';
|
|
5
5
|
import { createDispose } from './crossThreadHandlers/createDispose.js';
|
|
6
6
|
import { updateGlobalPropsEndpoint, dispatchMarkTiming, flushMarkTiming, } from '@lynx-js/web-constants';
|
|
7
|
-
import {
|
|
7
|
+
import { createTemplateLoader } from '../utils/loadTemplate.js';
|
|
8
8
|
import { createUpdateData } from './crossThreadHandlers/createUpdateData.js';
|
|
9
9
|
import { startBackground } from './startBackground.js';
|
|
10
10
|
import { createRenderMultiThread } from './createRenderMultiThread.js';
|
|
@@ -12,7 +12,7 @@ import { createRenderAllOnUI } from './createRenderAllOnUI.js';
|
|
|
12
12
|
export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, threadStrategy, callbacks, ssr) {
|
|
13
13
|
const createLynxStartTiming = performance.now() + performance.timeOrigin;
|
|
14
14
|
const allOnUI = threadStrategy === 'all-on-ui';
|
|
15
|
-
const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId, allOnUI);
|
|
15
|
+
const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId, allOnUI, configs.browserConfig);
|
|
16
16
|
const { markTiming, sendGlobalEvent, updateDataBackground, updateI18nResourceBackground, } = startBackground(backgroundRpc, shadowRoot, callbacks);
|
|
17
17
|
const cacheMarkTimings = {
|
|
18
18
|
records: [],
|
|
@@ -28,15 +28,14 @@ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, thr
|
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
const flushMarkTimingInternal = () => flushMarkTiming(markTiming, cacheMarkTimings);
|
|
31
|
+
const templateLoader = createTemplateLoader(callbacks.customTemplateLoader, markTimingInternal);
|
|
31
32
|
const { start, updateDataMainThread, updateI18nResourcesMainThread } = allOnUI
|
|
32
33
|
? createRenderAllOnUI(
|
|
33
|
-
/* main-to-bg rpc*/ mainThreadRpc, shadowRoot, markTimingInternal, flushMarkTimingInternal, callbacks, ssr)
|
|
34
|
+
/* main-to-bg rpc*/ mainThreadRpc, shadowRoot, templateLoader, markTimingInternal, flushMarkTimingInternal, callbacks, ssr)
|
|
34
35
|
: createRenderMultiThread(
|
|
35
|
-
/* main-to-ui rpc*/ mainThreadRpc, shadowRoot, callbacks);
|
|
36
|
+
/* main-to-ui rpc*/ mainThreadRpc, shadowRoot, templateLoader, callbacks);
|
|
36
37
|
markTimingInternal('create_lynx_start', undefined, createLynxStartTiming);
|
|
37
|
-
|
|
38
|
-
loadTemplate(templateUrl, callbacks.customTemplateLoader).then((template) => {
|
|
39
|
-
markTimingInternal('load_template_end');
|
|
38
|
+
templateLoader(templateUrl).then((template) => {
|
|
40
39
|
flushMarkTimingInternal();
|
|
41
40
|
start({
|
|
42
41
|
...configs,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function
|
|
1
|
+
import { type MarkTimingInternal, type TemplateLoader } from '@lynx-js/web-constants';
|
|
2
|
+
export declare function createTemplateLoader(customTemplateLoader: TemplateLoader | undefined, markTimingInternal: MarkTimingInternal): TemplateLoader;
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import { generateTemplate } from '@lynx-js/web-constants';
|
|
1
|
+
import { generateTemplate, } from '@lynx-js/web-constants';
|
|
2
2
|
const templateCache = {};
|
|
3
3
|
function createJsModuleUrl(content) {
|
|
4
4
|
return URL.createObjectURL(new Blob([content], { type: 'text/javascript' }));
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
export function createTemplateLoader(customTemplateLoader, markTimingInternal) {
|
|
7
|
+
const loadTemplate = async (url) => {
|
|
8
|
+
markTimingInternal('load_template_start');
|
|
9
|
+
const cachedTemplate = templateCache[url];
|
|
10
|
+
if (cachedTemplate) {
|
|
11
|
+
markTimingInternal('load_template_end');
|
|
12
|
+
return cachedTemplate;
|
|
13
|
+
}
|
|
14
|
+
const template = customTemplateLoader
|
|
15
|
+
? await customTemplateLoader(url)
|
|
16
|
+
: (await (await fetch(url, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
})).json());
|
|
19
|
+
const decodedTemplate = await generateTemplate(template, createJsModuleUrl);
|
|
20
|
+
templateCache[url] = decodedTemplate;
|
|
21
|
+
/**
|
|
22
|
+
* This will cause a memory leak, which is expected.
|
|
23
|
+
* We cannot ensure that the `URL.createObjectURL` created url will never be used, therefore here we keep it for the entire lifetime of this page.
|
|
24
|
+
*/
|
|
25
|
+
markTimingInternal('load_template_end');
|
|
26
|
+
return decodedTemplate;
|
|
27
|
+
};
|
|
28
|
+
return loadTemplate;
|
|
22
29
|
}
|
|
23
30
|
//# sourceMappingURL=loadTemplate.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"**/*.css"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@lynx-js/offscreen-document": "0.1.
|
|
28
|
-
"@lynx-js/web-constants": "0.
|
|
29
|
-
"@lynx-js/web-mainthread-apis": "0.
|
|
30
|
-
"@lynx-js/web-worker-rpc": "0.
|
|
31
|
-
"@lynx-js/web-worker-runtime": "0.
|
|
27
|
+
"@lynx-js/offscreen-document": "0.1.4",
|
|
28
|
+
"@lynx-js/web-constants": "0.16.1",
|
|
29
|
+
"@lynx-js/web-mainthread-apis": "0.16.1",
|
|
30
|
+
"@lynx-js/web-worker-rpc": "0.16.1",
|
|
31
|
+
"@lynx-js/web-worker-runtime": "0.16.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@lynx-js/lynx-core": "0.1.3",
|
|
35
|
-
"@lynx-js/web-elements": "0.8.
|
|
35
|
+
"@lynx-js/web-elements": "0.8.6"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@lynx-js/lynx-core": "0.1.3",
|