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/legal-spoons-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/web-core": patch
---

fix: enableJSDataProcessor not work
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"styleInfo": {},
"lepusCode": {
"root": "const self = globalThis.parent??globalThis;self.runtime = globalThis;self.__lynx_worker_type = 'main'; self.processData = (d) => ({...d, processed: true}); self.registerDataProcessor='pass'; self.registerDataProcessor = registerDataProcessor; self.updatePage = (d) => { self.__lastData = d; };",
"manifest-chunk.js": "module.exports = 'hello';",
"manifest-chunk2.js": "module.exports = 'world';"
},
"manifest": {
"/app-service.js": "globalThis.runtime = lynxCoreInject.tt; globalThis.runtime.updateData = (d) => { globalThis.__lastData = d; }; globalThis.__lynx_worker_type = 'background'",
"/manifest-chunk.js": "module.exports = 'hello';",
"/manifest-chunk2.js": "module.exports = 'world';",
"/json": "{}"
},
"customSections": {},
"cardType": "react",
"appType": "card",
"pageConfig": {
"enableFiberArch": true,
"useLepusNG": true,
"enableReuseContext": true,
"bundleModuleMode": "ReturnByFunction",
"templateDebugUrl": "",
"debugInfoOutside": true,
"defaultDisplayLinear": true,
"enableCSSInvalidation": true,
"enableCSSSelector": true,
"enableLepusDebug": false,
"enableRemoveCSSScope": true,
"targetSdkVersion": "2.10",
"enableJSDataProcessor": true
}
}
36 changes: 34 additions & 2 deletions packages/web-platform/web-core-e2e/tests/web-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ const wait = async (ms: number) => {
});
};

const goto = async (page: Page, title?: string) => {
await page.goto('/?resourceName=web-core.main-thread.json', {
const goto = async (
page: Page,
resourceName: string = 'web-core.main-thread.json',
) => {
await page.goto(`/?resourceName=${resourceName}`, {
waitUntil: 'load',
});
await wait(500);
Expand Down Expand Up @@ -169,6 +172,35 @@ test.describe('web core tests', () => {
expect(fail).toBe(false);
});

test('api-enableJSDataProcessor disables processData', async ({ page, browserName }) => {
test.skip(browserName === 'firefox');
await goto(page, 'web-core.enable-js-data-processor.json');

await page.evaluate(() => {
const root = globalThis.runtime.__CreatePage('0', '0', {});
const element = globalThis.runtime.__CreateElement('view', '0', {});
globalThis.runtime.__AppendElement(root, element);
globalThis.runtime.__FlushElementTree();
});

const worker = await getBackgroundThreadWorker(page);

await page.evaluate(() => {
const lynxView = document.querySelector('lynx-view') as LynxViewElement;
lynxView.updateData({ mock: 'data' });
});

await wait(300);

const isProcessed = await worker.evaluate(() => {
return (globalThis as any).__lastData?.processed === true;
});

// Because enableJSDataProcessor is true, the processData logic should NOT run
// so if we pass some mock data, it should not have `.processed = true`!
expect(isProcessed).toBeFalsy();
});

test('api-nativeApp-readScript', async ({ page, browserName }) => {
// firefox dose not support this.
test.skip(browserName === 'firefox');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ export class LynxViewInstance implements AsyncDisposable {
this.backgroundThread.markTiming('lepus_execute_end');
this.webElementsLoadingPromises.length = 0;
this.backgroundThread.markTiming('data_processor_start');
const processedData = this.mainThreadGlobalThis.processData
const processedData = this.#pageConfig?.['enableJSDataProcessor'] !== 'true'
&& this.mainThreadGlobalThis.processData
? this.mainThreadGlobalThis.processData?.(this.initData)
: this.initData;
this.backgroundThread.markTiming('data_processor_end');
Expand Down Expand Up @@ -249,7 +250,8 @@ export class LynxViewInstance implements AsyncDisposable {
data: Cloneable,
processorName?: string,
): Promise<void> {
const processedData = this.mainThreadGlobalThis.processData
const processedData = this.#pageConfig!['enableJSDataProcessor'] !== 'true'
&& this.mainThreadGlobalThis.processData
? this.mainThreadGlobalThis.processData(data, processorName)
: data;
this.mainThreadGlobalThis.updatePage?.(processedData, { processorName });
Expand Down
4 changes: 3 additions & 1 deletion packages/web-platform/web-core/ts/server/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export function executeTemplate(
const renderPageFunction = sandbox['renderPage'];
if (typeof renderPageFunction === 'function') {
const processData = sandbox['processData'];
const processedData = processData
const processedData = (config['enableJSDataProcessor'] !== 'true'
&& config['enableJSDataProcessor'] !== true)
&& processData
? processData(initData)
: initData;
renderPageFunction(processedData);
Expand Down
Loading