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
5 changes: 5 additions & 0 deletions .changeset/curvy-shrimps-stay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-core": patch
---

Conditionally pass Card and Component params based on cardType in background thread.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import type {
BundleInitReturnObj,
} from '../../../types/index.js';

export function createChunkLoading(entryTemplateUrl: string): {
export function createChunkLoading(
entryTemplateUrl: string,
cardType: string,
): {
readScript: NativeApp['readScript'];
loadScript: NativeApp['loadScript'];
loadScriptAsync: NativeApp['loadScriptAsync'];
Expand Down Expand Up @@ -59,18 +62,18 @@ export function createChunkLoading(entryTemplateUrl: string): {
const createBundleInitReturnObj = (
jsContent: string,
): BundleInitReturnObj => {
const foo = new Function(
const paramNames: string[] = [
'postMessage',
'module',
'exports',
'lynxCoreInject',
'Card',
...(cardType !== 'react' ? ['Card'] : []),
'setTimeout',
'setInterval',
'clearInterval',
'clearTimeout',
'NativeModules',
'Component',
...(cardType !== 'react' ? ['Component'] : []),
Comment thread
gaoachao marked this conversation as resolved.
'ReactLynx',
'nativeAppId',
'Behavior',
Expand Down Expand Up @@ -98,24 +101,27 @@ export function createChunkLoading(entryTemplateUrl: string): {
// Lynx API
'requestAnimationFrame',
'cancelAnimationFrame',
];
const foo = new Function(
...paramNames,
jsContent,
) as BTSChunkEntry;
return {
init(lynxCoreInject) {
const module = { exports: {} };
const tt = lynxCoreInject.tt as any;
foo(
const args: unknown[] = [
undefined,
module,
module.exports,
lynxCoreInject,
tt.Card.bind(tt),
...(cardType !== 'react' ? [tt.Card.bind(tt)] : []),
tt.setTimeout,
tt.setInterval,
tt.clearInterval,
tt.clearTimeout,
tt.NativeModules,
tt.Component.bind(tt),
...(cardType !== 'react' ? [tt.Component.bind(tt)] : []),
tt.ReactLynx,
tt.nativeAppId,
tt.Behavior,
Expand All @@ -142,7 +148,8 @@ export function createChunkLoading(entryTemplateUrl: string): {
tt.global,
tt.requestAnimationFrame,
tt.cancelAnimationFrame,
);
];
(foo as Function).apply(undefined, args);
return module.exports;
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function createNativeApp(
timingSystem: TimingSystem,
nativeModulesMap: NativeModulesMap,
entryTemplateUrl: string,
cardType: string,
): Promise<NativeApp> {
const performanceApis = createPerformanceApis(
timingSystem,
Expand All @@ -69,7 +70,7 @@ export async function createNativeApp(
);
const reportError = mainThreadRpc.createCall(reportErrorEndpoint);
const { templateCache, loadScript, loadScriptAsync, readScript } =
createChunkLoading(entryTemplateUrl);
createChunkLoading(entryTemplateUrl, cardType);

mainThreadRpc.registerHandler(
updateBTSChunkEndpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function startBackgroundThread(
timingSystem,
nativeModulesMap,
entryTemplateUrl,
cardType,
);
const lynxCore = import(
/* webpackChunkName: "lynx-core-chunk" */
Expand Down
Loading