@lynx-js/web-core-server 0.13.4 → 0.13.5

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.13.5
4
+
5
+ ### Patch Changes
6
+
7
+ - refactor: move some internal status to dom's attribute ([#945](https://github.com/lynx-family/lynx-stack/pull/945))
8
+
9
+ It's essential for SSR
10
+
11
+ - refactor: move component config info to attribute ([#984](https://github.com/lynx-family/lynx-stack/pull/984))
12
+
13
+ - refactor: save dataset on an attribute ([#981](https://github.com/lynx-family/lynx-stack/pull/981))
14
+
15
+ On lynx, the `data-*` attributes have different behaviors than the HTMLElement has.
16
+
17
+ The dataset will be treated as properties, the key will not be applied the camel-case <-> hyphenate name transformation.
18
+
19
+ Before this commit we use it as a runtime data, but after this commit we will use encodeURI(JSON.stringify(dataset)) to encode it as a string.
20
+
21
+ - fix: dump encode data in comment ([#989](https://github.com/lynx-family/lynx-stack/pull/989))
22
+
3
23
  ## 0.13.4
4
24
 
5
25
  ### Patch Changes
@@ -6,6 +6,7 @@ interface LynxViewConfig extends Pick<StartMainThreadContextConfig, 'browserConf
6
6
  overrideElementTemplates?: Record<string, ((attributes: Record<string, string>) => string) | string>;
7
7
  autoSize?: boolean;
8
8
  lynxViewStyle?: string;
9
+ threadStrategy?: 'all-on-ui';
9
10
  }
10
11
  export declare function createLynxView(config: LynxViewConfig): Promise<{
11
12
  renderToString: () => Promise<string>;
@@ -35,7 +35,7 @@ OffscreenElement.prototype.toJSON = function toJSON() {
35
35
  };
36
36
  };
37
37
  export async function createLynxView(config) {
38
- const { template: rawTemplate, browserConfig, tagMap, initData, globalProps, overrideElementTemplates = {}, hydrateUrl, autoSize, injectStyles, lynxViewStyle, } = config;
38
+ const { template: rawTemplate, browserConfig, tagMap, initData, globalProps, overrideElementTemplates = {}, hydrateUrl, autoSize, injectStyles, lynxViewStyle, threadStrategy = 'all-on-ui', } = config;
39
39
  const template = await loadTemplate(rawTemplate, config.templateName);
40
40
  const { promise: firstPaintReadyPromise, resolve: firstPaintReady } = Promise
41
41
  .withResolvers();
@@ -72,20 +72,21 @@ export async function createLynxView(config) {
72
72
  await firstPaintReadyPromise;
73
73
  const ssrEncodeData = runtime?.ssrEncode?.();
74
74
  const buffer = [];
75
- buffer.push('<lynx-view url="', hydrateUrl, '" ssr');
75
+ buffer.push('<lynx-view url="', hydrateUrl, '" ssr ', 'thread-strategy="', threadStrategy, '"');
76
76
  if (autoSize) {
77
77
  buffer.push(' height="auto" width="auto"');
78
78
  }
79
79
  if (lynxViewStyle) {
80
80
  buffer.push(' style="', lynxViewStyle, '"');
81
81
  }
82
+ buffer.push('><template shadowrootmode="open">', '<style>', injectStyles, '\n', inShadowRootStyles.join('\n'), '</style>');
83
+ dumpHTMLString(buffer, offscreenDocument, elementTemplates);
84
+ buffer.push('</template>');
82
85
  if (ssrEncodeData) {
83
86
  const encodeDataEncoded = ssrEncodeData ? encodeURI(ssrEncodeData) : ''; // to avoid XSS
84
- buffer.push(' ssr-encode-data="', encodeDataEncoded, '"');
87
+ buffer.push('<!--', encodeDataEncoded, '-->');
85
88
  }
86
- buffer.push('><template shadowrootmode="open">', '<style>', injectStyles, '\n', inShadowRootStyles.join('\n'), '</style>');
87
- dumpHTMLString(buffer, offscreenDocument, elementTemplates);
88
- buffer.push('</template>', '</lynx-view>');
89
+ buffer.push('</lynx-view>');
89
90
  return buffer.join('');
90
91
  }
91
92
  return {
@@ -1,4 +1,5 @@
1
1
  import { _attributes, _children, innerHTML, } from '@lynx-js/offscreen-document/webworker';
2
+ import { escapeHtml } from './utils/escapeHtml.js';
2
3
  function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
3
4
  const localName = element.localName;
4
5
  buffer.push('<');
@@ -7,7 +8,7 @@ function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
7
8
  buffer.push(' ');
8
9
  buffer.push(key);
9
10
  buffer.push('="');
10
- buffer.push(value);
11
+ buffer.push(escapeHtml(value));
11
12
  buffer.push('"');
12
13
  }
13
14
  buffer.push('>');
@@ -0,0 +1 @@
1
+ export declare function escapeHtml(string: string): string;
@@ -0,0 +1,67 @@
1
+ /**
2
+ *
3
+ * MIT License
4
+
5
+ Copyright (c) Facebook, Inc. and its affiliates.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ *
25
+ *
26
+ * forked from facebook/react
27
+ */
28
+ const matchHtmlRegExp = /["'&<>]/;
29
+ export function escapeHtml(string) {
30
+ const str = '' + string;
31
+ const match = matchHtmlRegExp.exec(str);
32
+ if (!match) {
33
+ return str;
34
+ }
35
+ let escape;
36
+ let html = '';
37
+ let index;
38
+ let lastIndex = 0;
39
+ for (index = match.index; index < str.length; index++) {
40
+ switch (str.charCodeAt(index)) {
41
+ case 34: // "
42
+ escape = '&quot;';
43
+ break;
44
+ case 38: // &
45
+ escape = '&amp;';
46
+ break;
47
+ case 39: // '
48
+ escape = '&#x27;'; // modified from escape-html; used to be '&#39'
49
+ break;
50
+ case 60: // <
51
+ escape = '&lt;';
52
+ break;
53
+ case 62: // >
54
+ escape = '&gt;';
55
+ break;
56
+ default:
57
+ continue;
58
+ }
59
+ if (lastIndex !== index) {
60
+ html += str.substring(lastIndex, index);
61
+ }
62
+ lastIndex = index + 1;
63
+ html += escape;
64
+ }
65
+ return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
66
+ }
67
+ //# sourceMappingURL=escapeHtml.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core-server",
3
- "version": "0.13.4",
3
+ "version": "0.13.5",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -22,10 +22,10 @@
22
22
  "README.md"
23
23
  ],
24
24
  "devDependencies": {
25
- "@lynx-js/offscreen-document": "0.1.0",
26
- "@lynx-js/web-constants": "0.13.4",
27
- "@lynx-js/web-elements-template": "0.7.4",
28
- "@lynx-js/web-mainthread-apis": "0.13.4",
29
- "@lynx-js/web-worker-rpc": "0.13.4"
25
+ "@lynx-js/offscreen-document": "0.1.1",
26
+ "@lynx-js/web-constants": "0.13.5",
27
+ "@lynx-js/web-elements-template": "0.7.5",
28
+ "@lynx-js/web-mainthread-apis": "0.13.5",
29
+ "@lynx-js/web-worker-rpc": "0.13.5"
30
30
  }
31
31
  }