@lynx-js/web-core-server-canary 0.16.1-canary-20250915-74388494 → 0.16.1-canary-20250915-608f375e

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,11 +1,13 @@
1
1
  # @lynx-js/web-core-server
2
2
 
3
- ## 0.16.1-canary-20250915064132-743884945342f58670e037c1a5dab06b782639c2
3
+ ## 0.16.1-canary-20250915073423-608f375e20732cc4c9f141bfbf9800ba6896100b
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - refactor: improve chunk loading ([#1703](https://github.com/lynx-family/lynx-stack/pull/1703))
8
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
+
9
11
  ## 0.16.0
10
12
 
11
13
  ### Minor Changes
package/dist/index.js CHANGED
@@ -648,6 +648,9 @@ createRpcEndpoint('updateGlobalProps', false, false);
648
648
  createRpcEndpoint('updateI18nResources', false, false);
649
649
  createRpcEndpoint('updateI18nResource', false, false);
650
650
  const dispatchI18nResourceEndpoint = createRpcEndpoint('dispatchI18nResource', false, false);
651
+ const queryComponentEndpoint = createRpcEndpoint('queryComponent', false, true);
652
+ const updateBTSTemplateCacheEndpoint = createRpcEndpoint('updateBTSTemplateCacheEndpoint', false, true);
653
+ createRpcEndpoint('loadTemplateMultiThread', false, true);
651
654
  var NativeApp_IdentifierType;
652
655
  (function(IdentifierType) {
653
656
  IdentifierType[IdentifierType["ID_SELECTOR"] = 0] = "ID_SELECTOR";
@@ -740,28 +743,25 @@ const templateUpgraders = [
740
743
  template.appType = template.lepusCode.root.startsWith('(function (globDynamicComponentEntry') ? 'lazy' : 'card';
741
744
  template.manifest = Object.fromEntries(Object.entries(template.manifest).map(([key, value])=>[
742
745
  key,
743
- `module.exports={init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:null}; ${value}\n return module.exports; } }`
744
- ]));
745
- template.lepusCode = Object.fromEntries(Object.entries(template.lepusCode).map(([key, value])=>[
746
- key,
747
- `(()=>{${value}\n})();`
746
+ `module.exports={init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:{}}; var exports=module.exports; ${value}\n return module.exports; } }`
748
747
  ]));
749
748
  template.version = 2;
750
749
  return template;
751
750
  }
752
751
  ];
753
- const generateModuleContent = (content, eager)=>[
752
+ const generateModuleContent = (content, eager, appType)=>[
754
753
  eager ? '//# allFunctionsCalledOnLoad' : '',
755
754
  '\n(function() { "use strict"; const ',
756
755
  globalDisallowedVars.join('=void 0,'),
757
756
  '=void 0;\n',
757
+ 'lazy' === appType ? 'module.exports=\n' : '',
758
758
  content,
759
759
  '\n})()'
760
760
  ].join('');
761
- async function generateJavascriptUrl(obj, createJsModuleUrl, eager, templateName) {
761
+ async function generateJavascriptUrl(obj, createJsModuleUrl, eager, appType, templateName) {
762
762
  const processEntry = async ([name, content])=>[
763
763
  name,
764
- await createJsModuleUrl(generateModuleContent(content, eager), `${templateName}-${name.replaceAll('/', '')}.js`)
764
+ await createJsModuleUrl(generateModuleContent(content, eager, appType), `${templateName}-${name.replaceAll('/', '')}.js`)
765
765
  ];
766
766
  return Promise.all(Object.entries(obj).filter(([_, content])=>'string' == typeof content).map(processEntry)).then(Object.fromEntries);
767
767
  }
@@ -772,8 +772,8 @@ async function generateTemplate(template, createJsModuleUrl, templateName) {
772
772
  while(template.version < currentSupportedTemplateVersion && (upgrader = templateUpgraders[template.version - 1]))template = upgrader(template);
773
773
  return {
774
774
  ...template,
775
- lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, true, templateName),
776
- manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, false, templateName)
775
+ lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, true, template.appType, templateName),
776
+ manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, false, template.appType, templateName)
777
777
  };
778
778
  }
779
779
  function registerCallLepusMethodHandler(rpc, runtime) {
@@ -1196,8 +1196,11 @@ const __UpdateComponentInfo = /*#__PURE__*/ (element, params)=>{
1196
1196
  void 0 !== params.cssID && element.setAttribute(cssIdAttribute, params.cssID + '');
1197
1197
  void 0 !== params.name && element.setAttribute('name', params.name);
1198
1198
  };
1199
- const __SetCSSId = /*#__PURE__*/ (elements, cssId)=>{
1200
- for (const element of elements)element.setAttribute(cssIdAttribute, cssId + '');
1199
+ const __SetCSSId = /*#__PURE__*/ (elements, cssId, entryName)=>{
1200
+ for (const element of elements){
1201
+ element.setAttribute(cssIdAttribute, cssId + '');
1202
+ entryName && element.setAttribute(lynxEntryNameAttribute, entryName);
1203
+ }
1201
1204
  };
1202
1205
  const __SetClasses = /*#__PURE__*/ (element, classname)=>{
1203
1206
  classname ? element.setAttribute('class', classname) : element.removeAttribute('class');
@@ -1685,6 +1688,7 @@ function createMainThreadGlobalThis(config) {
1685
1688
  __LoadLepusChunk,
1686
1689
  __GetPageElement,
1687
1690
  __globalProps: globalProps,
1691
+ __QueryComponent: callbacks.__QueryComponent,
1688
1692
  SystemInfo,
1689
1693
  lynx: createMainThreadLynx(config, SystemInfo),
1690
1694
  _ReportError: (err, _)=>callbacks._ReportError(err, _, release),
@@ -1819,7 +1823,7 @@ function genCssContent(styleInfo, pageConfig, entryName) {
1819
1823
  function getExtraSelectors(cssId) {
1820
1824
  let suffix;
1821
1825
  suffix = pageConfig.enableRemoveCSSScope ? `[${lynxTagAttribute}]` : void 0 !== cssId ? `[${cssIdAttribute}="${cssId}"]` : `[${lynxTagAttribute}]`;
1822
- suffix = entryName ? `${suffix}[${lynxEntryNameAttribute}="${entryName}"]` : `${suffix}:not([${lynxEntryNameAttribute}])`;
1826
+ suffix = entryName ? `${suffix}[${lynxEntryNameAttribute}=${JSON.stringify(entryName)}]` : `${suffix}:not([${lynxEntryNameAttribute}])`;
1823
1827
  return suffix;
1824
1828
  }
1825
1829
  const finalCssContent = [];
@@ -1883,12 +1887,63 @@ function appendStyleElement(styleInfo, pageConfig, rootDom, document, entryName,
1883
1887
  lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
1884
1888
  }
1885
1889
  };
1890
+ const updateLazyComponentStyle = (styleInfo, entryName)=>{
1891
+ flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
1892
+ transformToWebCss(styleInfo);
1893
+ const newStyleSheet = genCssContent(styleInfo, pageConfig, entryName);
1894
+ cardStyleElement.textContent += newStyleSheet;
1895
+ };
1886
1896
  return {
1887
- updateCssOGStyle
1897
+ updateCssOGStyle,
1898
+ updateLazyComponentStyle
1899
+ };
1900
+ }
1901
+ function createQueryComponent(loadTemplate, updateLazyComponentStyle, backgroundThreadRpc, mtsGlobalThisRef, jsContext, mtsRealm) {
1902
+ const updateBTSTemplateCache = backgroundThreadRpc.createCall(updateBTSTemplateCacheEndpoint);
1903
+ const __QueryComponentImpl = (url, callback)=>{
1904
+ loadTemplate(url).then(async (template)=>{
1905
+ const updateBTSCachePromise = updateBTSTemplateCache(url, template);
1906
+ let lepusRootChunkExport = await mtsRealm.loadScript(template.lepusCode.root);
1907
+ if (mtsGlobalThisRef.mtsGlobalThis.processEvalResult) lepusRootChunkExport = mtsGlobalThisRef.mtsGlobalThis.processEvalResult(lepusRootChunkExport, url);
1908
+ updateLazyComponentStyle(template.styleInfo, url);
1909
+ await updateBTSCachePromise;
1910
+ jsContext.dispatchEvent({
1911
+ type: '__OnDynamicJSSourcePrepared',
1912
+ data: url
1913
+ });
1914
+ callback?.({
1915
+ code: 0,
1916
+ data: {
1917
+ url,
1918
+ evalResult: lepusRootChunkExport
1919
+ }
1920
+ });
1921
+ }).catch((error)=>{
1922
+ console.error("lynx web: lazy bundle load failed:", error);
1923
+ callback?.({
1924
+ code: -1,
1925
+ data: void 0
1926
+ });
1927
+ });
1928
+ return null;
1888
1929
  };
1930
+ backgroundThreadRpc.registerHandler(queryComponentEndpoint, (url)=>{
1931
+ const ret = new Promise((resolve)=>{
1932
+ __QueryComponentImpl(url, (result)=>{
1933
+ resolve({
1934
+ code: result.code,
1935
+ detail: {
1936
+ schema: url
1937
+ }
1938
+ });
1939
+ });
1940
+ });
1941
+ return ret;
1942
+ });
1943
+ return __QueryComponentImpl;
1889
1944
  }
1890
1945
  const initWasmPromise = initWasm();
1891
- function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, ssrHooks) {
1946
+ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, loadTemplate, ssrHooks) {
1892
1947
  const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
1893
1948
  const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
1894
1949
  const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
@@ -1908,7 +1963,11 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm,
1908
1963
  sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint
1909
1964
  });
1910
1965
  const i18nResources = initialI18nResources(initI18nResources);
1911
- const { updateCssOGStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, void 0, ssrHydrateInfo);
1966
+ const { updateCssOGStyle, updateLazyComponentStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, void 0, ssrHydrateInfo);
1967
+ const mtsGlobalThisRef = {
1968
+ mtsGlobalThis: void 0
1969
+ };
1970
+ const __QueryComponent = createQueryComponent(loadTemplate, updateLazyComponentStyle, backgroundThreadRpc, mtsGlobalThisRef, jsContext, mtsRealm);
1912
1971
  const mtsGlobalThis = createMainThreadGlobalThis({
1913
1972
  lynxTemplate: template,
1914
1973
  mtsRealm,
@@ -1992,9 +2051,11 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm,
1992
2051
  dispatchI18nResource(matchedInitI18nResources?.resource);
1993
2052
  if (matchedInitI18nResources) return matchedInitI18nResources.resource;
1994
2053
  return triggerI18nResourceFallback(options);
1995
- }
2054
+ },
2055
+ __QueryComponent
1996
2056
  }
1997
2057
  });
2058
+ mtsGlobalThisRef.mtsGlobalThis = mtsGlobalThis;
1998
2059
  markTimingInternal('decode_end');
1999
2060
  await mtsRealm.loadScript(template.lepusCode.root);
2000
2061
  jsContext.__start();
@@ -2014,7 +2075,7 @@ async function loadTemplate_createJsModuleUrl(content, filename) {
2014
2075
  });
2015
2076
  return fileUrl;
2016
2077
  }
2017
- async function loadTemplate(rawTemplate, templateName = Math.random().toString(36).substring(2, 7)) {
2078
+ async function loadTemplate_loadTemplate(rawTemplate, templateName = Math.random().toString(36).substring(2, 7)) {
2018
2079
  if (templateCache.has(rawTemplate)) return templateCache.get(rawTemplate);
2019
2080
  templateName += Math.random().toString(36).substring(2, 7);
2020
2081
  const decodedTemplate = templateCache.get(rawTemplate) ?? await generateTemplate(rawTemplate, loadTemplate_createJsModuleUrl, templateName + '-lepusCode');
@@ -2208,6 +2269,9 @@ class OffscreenElement extends EventTarget {
2208
2269
  this[ancestorDocument][enableEvent](type, this[OffscreenElement_uniqueId]);
2209
2270
  super.addEventListener(type, callback, options);
2210
2271
  }
2272
+ get textContent() {
2273
+ return this[textContent];
2274
+ }
2211
2275
  set textContent(text1) {
2212
2276
  this[ancestorDocument][operations].push(OperationType.SetTextContent, this[OffscreenElement_uniqueId], text1);
2213
2277
  for (const child of this.children)child.remove();
@@ -2721,7 +2785,7 @@ OffscreenElement.prototype.toJSON = function() {
2721
2785
  };
2722
2786
  async function createLynxView(config) {
2723
2787
  const { template: rawTemplate, browserConfig, tagMap, initData, globalProps, overrideElementTemplates = {}, hydrateUrl, autoSize, injectStyles, lynxViewStyle, threadStrategy = 'all-on-ui', initI18nResources } = config;
2724
- const template = await loadTemplate(rawTemplate, config.templateName);
2788
+ const template = await loadTemplate_loadTemplate(rawTemplate, config.templateName);
2725
2789
  const { promise: firstPaintReadyPromise, resolve: firstPaintReady } = Promise.withResolvers();
2726
2790
  const mainWithBackgroundChannel = new MessageChannel();
2727
2791
  const backgroundThreadRpc = new Rpc(mainWithBackgroundChannel.port1, 'background-thread');
@@ -2782,7 +2846,7 @@ async function createLynxView(config) {
2782
2846
  }, ()=>{}, ()=>{}, ()=>{}, ()=>{}, (initI18nResources)=>{
2783
2847
  i18nResources.setData(initI18nResources);
2784
2848
  return i18nResources;
2785
- }, {
2849
+ }, ()=>{}, {
2786
2850
  __AddEvent (element, eventName, eventData, eventOptions) {
2787
2851
  events.push([
2788
2852
  Number(element.getAttribute("l-uid")),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core-server-canary",
3
- "version": "0.16.1-canary-20250915-74388494",
3
+ "version": "0.16.1-canary-20250915-608f375e",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,11 +25,11 @@
25
25
  "devDependencies": {
26
26
  "rsbuild-plugin-arethetypeswrong": "0.1.1",
27
27
  "rsbuild-plugin-publint": "0.3.3",
28
+ "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.1-canary-20250915-608f375e",
28
29
  "@lynx-js/offscreen-document": "npm:@lynx-js/offscreen-document-canary@0.1.4",
29
- "@lynx-js/web-elements-template": "npm:@lynx-js/web-elements-template-canary@0.8.6-canary-20250915-74388494",
30
- "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.16.1-canary-20250915-74388494",
31
- "@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.16.1-canary-20250915-74388494",
32
- "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.1-canary-20250915-74388494"
30
+ "@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.16.1-canary-20250915-608f375e",
31
+ "@lynx-js/web-elements-template": "npm:@lynx-js/web-elements-template-canary@0.8.6-canary-20250915-608f375e",
32
+ "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.16.1-canary-20250915-608f375e"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "rslib build",