Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/hip-apples-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@lynx-js/web-mainthread-apis": patch
"@lynx-js/web-worker-runtime": patch
"@lynx-js/web-constants": patch
"@lynx-js/web-core": patch
---

fix: the SystemInfo in bts should be assigned to the globalThis
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { Cloneable } from './Cloneable.js';
import type { LynxTemplate } from './LynxModule.js';
import type { NapiModulesMap } from './NapiModules.js';
import type { NativeModulesMap } from './NativeModules.js';
import type { BrowserConfig } from './PageConfig.js';

export interface BackMainThreadContextConfig {
initData: unknown;
Expand All @@ -16,5 +15,4 @@ export interface BackMainThreadContextConfig {
customSections: Record<string, Cloneable>;
nativeModulesMap: NativeModulesMap;
napiModulesMap: NapiModulesMap;
browserConfig: BrowserConfig;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const backgroundInjectVars = [
'globalThis',
'lynx',
'lynxCoreInject',
'SystemInfo',
];

const backgroundInjectWithBind = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { systemInfo, type BrowserConfig } from '@lynx-js/web-constants';
import { Rpc } from '@lynx-js/web-worker-rpc';
import type { WorkerStartMessage } from '@lynx-js/web-worker-runtime';

Expand All @@ -16,7 +17,8 @@ const contextIdToBackgroundWorker: (Worker | undefined)[] = [];

export function bootWorkers(
lynxGroupId: number | undefined,
allOnUI?: boolean,
allOnUI: boolean,
Comment thread
PupilTong marked this conversation as resolved.
browserConfig: BrowserConfig,
): LynxViewRpc {
let curMainWorker: {
mainThreadRpc: Rpc;
Expand All @@ -31,6 +33,7 @@ export function bootWorkers(
const curBackgroundWorker = createBackgroundWorker(
lynxGroupId,
curMainWorker.channelMainThreadWithBackground,
browserConfig,
);
if (lynxGroupId !== undefined) {
if (backgroundWorkerContextCount[lynxGroupId]) {
Expand Down Expand Up @@ -97,6 +100,7 @@ function createMainWorker() {
function createBackgroundWorker(
lynxGroupId: number | undefined,
channelMainThreadWithBackground: MessageChannel,
browserConfig: BrowserConfig,
) {
const channelToBackground = new MessageChannel();
let backgroundThreadWorker: Worker;
Expand All @@ -111,6 +115,7 @@ function createBackgroundWorker(
mode: 'background',
toUIThread: channelToBackground.port2,
toPeerThread: channelMainThreadWithBackground.port2,
systemInfo: { ...systemInfo, ...browserConfig },
};
backgroundThreadWorker.postMessage(backgroundThreadMessage, [
channelToBackground.port2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function startUIThread(
mainThreadRpc,
backgroundRpc,
terminateWorkers,
} = bootWorkers(lynxGroupId, allOnUI);
} = bootWorkers(lynxGroupId, allOnUI, configs.browserConfig);
const {
markTiming,
sendGlobalEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ export function prepareMainThreadAPIs(
),
nativeModulesMap,
napiModulesMap,
browserConfig,
});
if (!ssrHydrateInfo) {
mtsGlobalThis.renderPage!(initData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
type LynxJSModule,
type NativeApp,
type LynxCrossThreadContext,
systemInfo,
type BackMainThreadContextConfig,
I18nResource,
reportErrorEndpoint,
Expand Down Expand Up @@ -47,7 +46,6 @@ export async function createNativeApp(
template,
nativeModulesMap,
timingSystem,
browserConfig,
} = config;
const performanceApis = createPerformanceApis(
timingSystem,
Expand Down Expand Up @@ -91,9 +89,6 @@ export async function createNativeApp(
);
},
});
Object.assign(lynxCoreInject.tt, {
SystemInfo: { ...systemInfo, ...browserConfig },
});
const ret = entry?.(lynxCoreInject.tt);
return ret;
},
Expand Down
6 changes: 6 additions & 0 deletions packages/web-platform/web-worker-runtime/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare global {
var SystemInfo: Record<string, any> | undefined;
var module: { exports: any };
}

export {};
6 changes: 5 additions & 1 deletion packages/web-platform/web-worker-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ export interface WorkerStartMessage {
mode: 'main' | 'background';
toPeerThread: MessagePort;
toUIThread: MessagePort;
systemInfo?: Record<string, any>;
}

globalThis.onmessage = async (ev) => {
const { mode, toPeerThread, toUIThread } = ev
const { mode, toPeerThread, toUIThread, systemInfo } = ev
.data as WorkerStartMessage;
if (!globalThis.SystemInfo) {
globalThis.SystemInfo = systemInfo;
}
if (mode === 'main') {
const { startMainThreadWorker } = await import(
/* webpackChunkName: "web-worker-runtime-main-thread" */
Expand Down
Loading