@lynx-js/web-core-server 0.15.1 → 0.15.3

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @lynx-js/web-core-server
2
2
 
3
+ ## 0.15.3
4
+
5
+ ## 0.15.2
6
+
7
+ ### Patch Changes
8
+
9
+ - feat: support SSR for all-on-ui ([#1029](https://github.com/lynx-family/lynx-stack/pull/1029))
10
+
11
+ - feat: move SSR hydrate essential info to the ssr attribute ([#1292](https://github.com/lynx-family/lynx-stack/pull/1292))
12
+
13
+ We found that in browser there is no simple tool to decode a base64 string
14
+
15
+ Therefore we move the data to `ssr` attribute
16
+
17
+ Also fix some ssr issues
18
+
19
+ - feat: dump the event info on ssr stage ([#1237](https://github.com/lynx-family/lynx-stack/pull/1237))
20
+
21
+ - feat: mark template elements for SSR and update part ID handling ([#1286](https://github.com/lynx-family/lynx-stack/pull/1286))
22
+
3
23
  ## 0.15.1
4
24
 
5
25
  ## 0.15.0
@@ -1,4 +1,4 @@
1
- import { I18nResources, inShadowRootStyles, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
1
+ import { I18nResources, inShadowRootStyles, lynxPartIdAttribute, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
2
2
  import { Rpc } from '@lynx-js/web-worker-rpc';
3
3
  import { prepareMainThreadAPIs } from '@lynx-js/web-mainthread-apis';
4
4
  import { loadTemplate } from './utils/loadTemplate.js';
@@ -31,7 +31,8 @@ const builtinTagTransformMap = {
31
31
  // @ts-expect-error
32
32
  OffscreenElement.prototype.toJSON = function toJSON() {
33
33
  return {
34
- ssrID: this[_attributes].get(lynxUniqueIdAttribute),
34
+ ssrID: this[_attributes].get(lynxPartIdAttribute)
35
+ ?? this[_attributes].get(lynxUniqueIdAttribute),
35
36
  };
36
37
  };
37
38
  export async function createLynxView(config) {
@@ -46,6 +47,7 @@ export async function createLynxView(config) {
46
47
  },
47
48
  });
48
49
  const i18nResources = new I18nResources();
50
+ const events = [];
49
51
  const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, offscreenDocument, offscreenDocument.createElement.bind(offscreenDocument), () => {
50
52
  firstPaintReady();
51
53
  }, () => {
@@ -59,6 +61,15 @@ export async function createLynxView(config) {
59
61
  }, (initI18nResources) => {
60
62
  i18nResources.setData(initI18nResources);
61
63
  return i18nResources;
64
+ }, {
65
+ __AddEvent(element, eventName, eventData, eventOptions) {
66
+ events.push([
67
+ Number(element.getAttribute(lynxUniqueIdAttribute)),
68
+ eventName,
69
+ eventData,
70
+ eventOptions,
71
+ ]);
72
+ },
62
73
  });
63
74
  const runtime = await startMainThread({
64
75
  template,
@@ -80,8 +91,12 @@ export async function createLynxView(config) {
80
91
  async function renderToString() {
81
92
  await firstPaintReadyPromise;
82
93
  const ssrEncodeData = runtime?.ssrEncode?.();
94
+ const ssrDumpInfo = {
95
+ ssrEncodeData,
96
+ events,
97
+ };
83
98
  const buffer = [];
84
- buffer.push('<lynx-view url="', hydrateUrl, '" ssr ', 'thread-strategy="', threadStrategy, '"');
99
+ buffer.push('<lynx-view url="', hydrateUrl, '" ssr ="', encodeURI(JSON.stringify(ssrDumpInfo)), '" ', 'thread-strategy="', threadStrategy, '"');
85
100
  if (autoSize) {
86
101
  buffer.push(' height="auto" width="auto"');
87
102
  }
@@ -91,10 +106,6 @@ export async function createLynxView(config) {
91
106
  buffer.push('><template shadowrootmode="open">', '<style>', injectStyles, '\n', inShadowRootStyles.join('\n'), '</style>');
92
107
  dumpHTMLString(buffer, offscreenDocument, elementTemplates);
93
108
  buffer.push('</template>');
94
- if (ssrEncodeData) {
95
- const encodeDataEncoded = ssrEncodeData ? encodeURI(ssrEncodeData) : ''; // to avoid XSS
96
- buffer.push('<!--', encodeDataEncoded, '-->');
97
- }
98
109
  buffer.push('</lynx-view>');
99
110
  return buffer.join('');
100
111
  }
@@ -1,5 +1,6 @@
1
1
  import { _attributes, _children, innerHTML, _cssRuleContents, } from '@lynx-js/offscreen-document/webworker';
2
2
  import { escapeHtml } from './utils/escapeHtml.js';
3
+ import { lynxPartIdAttribute, lynxUniqueIdAttribute, } from '@lynx-js/web-constants';
3
4
  function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
4
5
  const localName = element.localName;
5
6
  buffer.push('<');
@@ -7,10 +8,15 @@ function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
7
8
  for (const [key, value] of element[_attributes]) {
8
9
  buffer.push(' ');
9
10
  buffer.push(key);
10
- buffer.push('="');
11
- buffer.push(escapeHtml(value));
12
- buffer.push('"');
11
+ if (value.length > 0) {
12
+ buffer.push('="');
13
+ buffer.push(escapeHtml(value));
14
+ buffer.push('"');
15
+ }
13
16
  }
17
+ const partId = element[_attributes].get(lynxPartIdAttribute)
18
+ ?? element[_attributes].get(lynxUniqueIdAttribute);
19
+ buffer.push(' ', lynxPartIdAttribute, '="', partId, '"');
14
20
  buffer.push('>');
15
21
  const templateImpl = shadowrootTemplates[localName];
16
22
  if (templateImpl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core-server",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -23,9 +23,9 @@
23
23
  ],
24
24
  "devDependencies": {
25
25
  "@lynx-js/offscreen-document": "0.1.3",
26
- "@lynx-js/web-constants": "0.15.1",
27
- "@lynx-js/web-elements-template": "0.8.0",
28
- "@lynx-js/web-mainthread-apis": "0.15.1",
29
- "@lynx-js/web-worker-rpc": "0.15.1"
26
+ "@lynx-js/web-constants": "0.15.3",
27
+ "@lynx-js/web-elements-template": "0.8.2",
28
+ "@lynx-js/web-mainthread-apis": "0.15.3",
29
+ "@lynx-js/web-worker-rpc": "0.15.3"
30
30
  }
31
31
  }