@lynx-js/web-core 0.15.0 → 0.15.2
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 +34 -0
- package/dist/apis/LynxView.js +22 -15
- package/dist/apis/createLynxView.d.ts +2 -1
- package/dist/apis/createLynxView.js +2 -2
- package/dist/uiThread/createRenderAllOnUI.d.ts +2 -2
- package/dist/uiThread/createRenderAllOnUI.js +35 -4
- package/dist/uiThread/startUIThread.d.ts +2 -2
- package/dist/uiThread/startUIThread.js +2 -2
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @lynx-js/web-core
|
|
2
2
|
|
|
3
|
+
## 0.15.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: support SSR for all-on-ui ([#1029](https://github.com/lynx-family/lynx-stack/pull/1029))
|
|
8
|
+
|
|
9
|
+
- feat: move SSR hydrate essential info to the ssr attribute ([#1292](https://github.com/lynx-family/lynx-stack/pull/1292))
|
|
10
|
+
|
|
11
|
+
We found that in browser there is no simple tool to decode a base64 string
|
|
12
|
+
|
|
13
|
+
Therefore we move the data to `ssr` attribute
|
|
14
|
+
|
|
15
|
+
Also fix some ssr issues
|
|
16
|
+
|
|
17
|
+
- feat: support \_\_MarkTemplateElement, \_\_MarkPartElement and \_\_GetTemplateParts for all-on-ui ([#1275](https://github.com/lynx-family/lynx-stack/pull/1275))
|
|
18
|
+
|
|
19
|
+
- feat: mark template elements for SSR and update part ID handling ([#1286](https://github.com/lynx-family/lynx-stack/pull/1286))
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`cebda59`](https://github.com/lynx-family/lynx-stack/commit/cebda592ac5c7d152c877c2ac5ec403d477077e1), [`1443e46`](https://github.com/lynx-family/lynx-stack/commit/1443e468a353363e29aab0d90cd8b91c232a5525), [`5062128`](https://github.com/lynx-family/lynx-stack/commit/5062128c68e21abcf276ebcb40d7cc8f6e54244b), [`f656b7f`](https://github.com/lynx-family/lynx-stack/commit/f656b7f0d390d69c0da0d11a6c9b3f66ae877ac8)]:
|
|
22
|
+
- @lynx-js/web-mainthread-apis@0.15.2
|
|
23
|
+
- @lynx-js/web-constants@0.15.2
|
|
24
|
+
- @lynx-js/web-worker-runtime@0.15.2
|
|
25
|
+
- @lynx-js/web-worker-rpc@0.15.2
|
|
26
|
+
|
|
27
|
+
## 0.15.1
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies []:
|
|
32
|
+
- @lynx-js/web-mainthread-apis@0.15.1
|
|
33
|
+
- @lynx-js/web-worker-runtime@0.15.1
|
|
34
|
+
- @lynx-js/web-constants@0.15.1
|
|
35
|
+
- @lynx-js/web-worker-rpc@0.15.1
|
|
36
|
+
|
|
3
37
|
## 0.15.0
|
|
4
38
|
|
|
5
39
|
### Minor Changes
|
package/dist/apis/LynxView.js
CHANGED
|
@@ -247,6 +247,7 @@ export class LynxView extends HTMLElement {
|
|
|
247
247
|
* reload the current page
|
|
248
248
|
*/
|
|
249
249
|
reload() {
|
|
250
|
+
this.removeAttribute('ssr');
|
|
250
251
|
this.#render();
|
|
251
252
|
}
|
|
252
253
|
/**
|
|
@@ -341,6 +342,7 @@ export class LynxView extends HTMLElement {
|
|
|
341
342
|
this.#rendering = true;
|
|
342
343
|
queueMicrotask(() => {
|
|
343
344
|
this.#rendering = false;
|
|
345
|
+
const ssrData = this.getAttribute('ssr');
|
|
344
346
|
if (this.#instance) {
|
|
345
347
|
this.disconnectedCallback();
|
|
346
348
|
}
|
|
@@ -402,23 +404,28 @@ export class LynxView extends HTMLElement {
|
|
|
402
404
|
},
|
|
403
405
|
customTemplateLoader: this.customTemplateLoader,
|
|
404
406
|
},
|
|
407
|
+
ssr: ssrData
|
|
408
|
+
? JSON.parse(decodeURI(ssrData))
|
|
409
|
+
: undefined,
|
|
405
410
|
});
|
|
406
411
|
this.#instance = lynxView;
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
412
|
+
if (!ssrData) {
|
|
413
|
+
const styleElement = document.createElement('style');
|
|
414
|
+
this.shadowRoot.append(styleElement);
|
|
415
|
+
const styleSheet = styleElement.sheet;
|
|
416
|
+
for (const rule of inShadowRootStyles) {
|
|
417
|
+
styleSheet.insertRule(rule);
|
|
418
|
+
}
|
|
419
|
+
for (const rule of this.injectStyleRules) {
|
|
420
|
+
styleSheet.insertRule(rule);
|
|
421
|
+
}
|
|
422
|
+
const injectHeadLinks = this.getAttribute('inject-head-links') !== 'false';
|
|
423
|
+
if (injectHeadLinks) {
|
|
424
|
+
document.head.querySelectorAll('link[rel="stylesheet"]').forEach((linkElement) => {
|
|
425
|
+
const href = linkElement.href;
|
|
426
|
+
styleSheet.insertRule(`@import url("${href}");`);
|
|
427
|
+
});
|
|
428
|
+
}
|
|
422
429
|
}
|
|
423
430
|
}
|
|
424
431
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Cloneable, I18nResourceTranslationOptions, InitI18nResources, NapiModulesMap, NativeModulesMap, sendGlobalEventEndpoint, UpdateDataType } from '@lynx-js/web-constants';
|
|
1
|
+
import type { Cloneable, SSRDumpInfo, I18nResourceTranslationOptions, InitI18nResources, NapiModulesMap, NativeModulesMap, sendGlobalEventEndpoint, UpdateDataType } from '@lynx-js/web-constants';
|
|
2
2
|
import { type StartUIThreadCallbacks } from '../uiThread/startUIThread.js';
|
|
3
3
|
import type { RpcCallType } from '@lynx-js/web-worker-rpc';
|
|
4
4
|
export interface LynxViewConfigs {
|
|
@@ -13,6 +13,7 @@ export interface LynxViewConfigs {
|
|
|
13
13
|
lynxGroupId: number | undefined;
|
|
14
14
|
threadStrategy: 'all-on-ui' | 'multi-thread';
|
|
15
15
|
initI18nResources: InitI18nResources;
|
|
16
|
+
ssr?: SSRDumpInfo;
|
|
16
17
|
}
|
|
17
18
|
export interface LynxView {
|
|
18
19
|
updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
|
|
@@ -6,7 +6,7 @@ const pixelRatio = window.devicePixelRatio;
|
|
|
6
6
|
const screenWidth = window.screen.availWidth * pixelRatio;
|
|
7
7
|
const screenHeight = window.screen.availHeight * pixelRatio;
|
|
8
8
|
export function createLynxView(configs) {
|
|
9
|
-
const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, lynxGroupId, threadStrategy = 'multi-thread', initI18nResources, } = configs;
|
|
9
|
+
const { shadowRoot, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, lynxGroupId, threadStrategy = 'multi-thread', initI18nResources, ssr, } = configs;
|
|
10
10
|
return startUIThread(templateUrl, {
|
|
11
11
|
tagMap,
|
|
12
12
|
initData,
|
|
@@ -19,6 +19,6 @@ export function createLynxView(configs) {
|
|
|
19
19
|
pixelHeight: screenHeight,
|
|
20
20
|
},
|
|
21
21
|
initI18nResources,
|
|
22
|
-
}, shadowRoot, lynxGroupId, threadStrategy, callbacks);
|
|
22
|
+
}, shadowRoot, lynxGroupId, threadStrategy, callbacks, ssr);
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=createLynxView.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type StartMainThreadContextConfig, type Cloneable } from '@lynx-js/web-constants';
|
|
1
|
+
import { type StartMainThreadContextConfig, type Cloneable, type SSRDumpInfo } from '@lynx-js/web-constants';
|
|
2
2
|
import { Rpc } from '@lynx-js/web-worker-rpc';
|
|
3
3
|
export declare function createRenderAllOnUI(mainToBackgroundRpc: Rpc, shadowRoot: ShadowRoot, markTimingInternal: (timingKey: string, pipelineId?: string, timeStamp?: number) => void, flushMarkTimingInternal: () => void, callbacks: {
|
|
4
4
|
onError?: (err: Error, release: string, fileName: string) => void;
|
|
5
|
-
}): {
|
|
5
|
+
}, ssrDumpInfo: SSRDumpInfo | undefined): {
|
|
6
6
|
start: (configs: StartMainThreadContextConfig) => Promise<void>;
|
|
7
7
|
updateDataMainThread: (args_0: Cloneable, args_1: Record<string, string>) => Promise<void>;
|
|
8
8
|
updateI18nResourcesMainThread: (data: Cloneable) => void;
|
|
@@ -1,12 +1,12 @@
|
|
|
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 { i18nResourceMissedEventName, I18nResources, } from '@lynx-js/web-constants';
|
|
4
|
+
import { i18nResourceMissedEventName, I18nResources, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
|
|
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
8
|
const { prepareMainThreadAPIs, } = await import('@lynx-js/web-mainthread-apis');
|
|
9
|
-
export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingInternal, flushMarkTimingInternal, callbacks) {
|
|
9
|
+
export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingInternal, flushMarkTimingInternal, callbacks, ssrDumpInfo) {
|
|
10
10
|
if (!globalThis.module) {
|
|
11
11
|
Object.assign(globalThis, { module: {} });
|
|
12
12
|
}
|
|
@@ -23,8 +23,39 @@ export function createRenderAllOnUI(mainToBackgroundRpc, shadowRoot, markTimingI
|
|
|
23
23
|
});
|
|
24
24
|
let mtsGlobalThis;
|
|
25
25
|
const start = async (configs) => {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if (ssrDumpInfo) {
|
|
27
|
+
const lynxUniqueIdToElement = [];
|
|
28
|
+
const allLynxElements = shadowRoot.querySelectorAll(`[${lynxUniqueIdAttribute}]`);
|
|
29
|
+
const length = allLynxElements.length;
|
|
30
|
+
for (let ii = 0; ii < length; ii++) {
|
|
31
|
+
const element = allLynxElements[ii];
|
|
32
|
+
const lynxUniqueId = Number(element.getAttribute(lynxUniqueIdAttribute));
|
|
33
|
+
lynxUniqueIdToElement[lynxUniqueId] = new WeakRef(element);
|
|
34
|
+
}
|
|
35
|
+
const hydrateStyleElement = shadowRoot.querySelector(`style:nth-of-type(2)`);
|
|
36
|
+
const styleSheet = hydrateStyleElement?.sheet;
|
|
37
|
+
const lynxUniqueIdToStyleRulesIndex = [];
|
|
38
|
+
const cssRulesLength = styleSheet?.cssRules.length ?? 0;
|
|
39
|
+
for (let ii = 0; ii < cssRulesLength; ii++) {
|
|
40
|
+
const cssRule = styleSheet?.cssRules[ii];
|
|
41
|
+
if (cssRule?.constructor.name === 'CSSStyleRule') {
|
|
42
|
+
const lynxUniqueId = parseFloat(cssRule.selectorText.substring(lynxUniqueIdAttribute.length + 3));
|
|
43
|
+
if (lynxUniqueId !== undefined && !isNaN(lynxUniqueId)) {
|
|
44
|
+
lynxUniqueIdToStyleRulesIndex[lynxUniqueId] = ii;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
mtsGlobalThis = await startMainThread(configs, {
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
lynxUniqueIdToElement: lynxUniqueIdToElement,
|
|
51
|
+
lynxUniqueIdToStyleRulesIndex,
|
|
52
|
+
...ssrDumpInfo,
|
|
53
|
+
cardStyleElement: hydrateStyleElement,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
mtsGlobalThis = await startMainThread(configs);
|
|
58
|
+
}
|
|
28
59
|
};
|
|
29
60
|
const updateDataMainThread = async (...args) => {
|
|
30
61
|
mtsGlobalThis.updatePage?.(...args);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { LynxView } from '../apis/createLynxView.js';
|
|
2
|
-
import { type LynxTemplate, type StartMainThreadContextConfig, type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
|
|
2
|
+
import { type LynxTemplate, type StartMainThreadContextConfig, type NapiModulesCall, type NativeModulesCall, type SSRDumpInfo } 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
7
|
customTemplateLoader?: (url: string) => Promise<LynxTemplate>;
|
|
8
8
|
};
|
|
9
|
-
export declare function startUIThread(templateUrl: string, configs: Omit<StartMainThreadContextConfig, 'template'>, shadowRoot: ShadowRoot, lynxGroupId: number | undefined, threadStrategy: 'all-on-ui' | 'multi-thread', callbacks: StartUIThreadCallbacks): LynxView;
|
|
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;
|
|
@@ -9,7 +9,7 @@ import { createUpdateData } from './crossThreadHandlers/createUpdateData.js';
|
|
|
9
9
|
import { startBackground } from './startBackground.js';
|
|
10
10
|
import { createRenderMultiThread } from './createRenderMultiThread.js';
|
|
11
11
|
import { createRenderAllOnUI } from './createRenderAllOnUI.js';
|
|
12
|
-
export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, threadStrategy, callbacks) {
|
|
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
15
|
const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers(lynxGroupId, allOnUI);
|
|
@@ -30,7 +30,7 @@ export function startUIThread(templateUrl, configs, shadowRoot, lynxGroupId, thr
|
|
|
30
30
|
const flushMarkTimingInternal = () => flushMarkTiming(markTiming, cacheMarkTimings);
|
|
31
31
|
const { start, updateDataMainThread, updateI18nResourcesMainThread } = allOnUI
|
|
32
32
|
? createRenderAllOnUI(
|
|
33
|
-
/* main-to-bg rpc*/ mainThreadRpc, shadowRoot, markTimingInternal, flushMarkTimingInternal, callbacks)
|
|
33
|
+
/* main-to-bg rpc*/ mainThreadRpc, shadowRoot, markTimingInternal, flushMarkTimingInternal, callbacks, ssr)
|
|
34
34
|
: createRenderMultiThread(
|
|
35
35
|
/* main-to-ui rpc*/ mainThreadRpc, shadowRoot, callbacks);
|
|
36
36
|
markTimingInternal('create_lynx_start', undefined, createLynxStartTiming);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-core",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@lynx-js/offscreen-document": "0.1.3",
|
|
28
|
-
"@lynx-js/web-constants": "0.15.
|
|
29
|
-
"@lynx-js/web-mainthread-apis": "0.15.
|
|
30
|
-
"@lynx-js/web-worker-rpc": "0.15.
|
|
31
|
-
"@lynx-js/web-worker-runtime": "0.15.
|
|
28
|
+
"@lynx-js/web-constants": "0.15.2",
|
|
29
|
+
"@lynx-js/web-mainthread-apis": "0.15.2",
|
|
30
|
+
"@lynx-js/web-worker-rpc": "0.15.2",
|
|
31
|
+
"@lynx-js/web-worker-runtime": "0.15.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@lynx-js/lynx-core": "0.1.2",
|
|
35
|
-
"@lynx-js/web-elements": "0.8.
|
|
35
|
+
"@lynx-js/web-elements": "0.8.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@lynx-js/lynx-core": "0.1.2",
|