diff --git a/.changeset/tough-cases-help.md b/.changeset/tough-cases-help.md new file mode 100644 index 0000000000..c4401e7d84 --- /dev/null +++ b/.changeset/tough-cases-help.md @@ -0,0 +1,7 @@ +--- +"@lynx-js/testing-environment": patch +"@lynx-js/react-webpack-plugin": patch +"@lynx-js/react": patch +--- + +Remove element api calls alog by default, and only enable it when `__ALOG_ELEMENT_API__` is defined to `true` or environment variable `REACT_ALOG_ELEMENT_API` is set to `true`. diff --git a/packages/react/runtime/src/alog/index.ts b/packages/react/runtime/src/alog/index.ts index d0150cbae2..765c8bb129 100644 --- a/packages/react/runtime/src/alog/index.ts +++ b/packages/react/runtime/src/alog/index.ts @@ -1,10 +1,8 @@ // Copyright 2025 The Lynx Authors. All rights reserved. // 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 { initElementPAPICallAlog } from './elementPAPICall.js'; import { initRenderAlog } from './render.js'; export function initAlog(): void { initRenderAlog(); - initElementPAPICallAlog(); } diff --git a/packages/react/runtime/src/lynx.ts b/packages/react/runtime/src/lynx.ts index 50a31a53a2..c636fe7760 100644 --- a/packages/react/runtime/src/lynx.ts +++ b/packages/react/runtime/src/lynx.ts @@ -5,6 +5,7 @@ import { options } from 'preact'; // to make sure preact's hooks to register earlier than ours import './hooks/react.js'; +import { initElementPAPICallAlog } from './alog/elementPAPICall.js'; import { initAlog } from './alog/index.js'; import { setupComponentStack } from './debug/component-stack.js'; import { initProfileHook } from './debug/profile.js'; @@ -52,6 +53,9 @@ if (typeof __ALOG__ !== 'undefined' && __ALOG__) { // We are logging both main-thread and background. initAlog(); } +if (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) { + initElementPAPICallAlog(); +} if (typeof __BACKGROUND__ !== 'undefined' && __BACKGROUND__) { // Trick Preact and TypeScript to accept our custom document adapter. diff --git a/packages/react/runtime/types/types.d.ts b/packages/react/runtime/types/types.d.ts index 4cd102d4aa..3ebeaa0bdc 100644 --- a/packages/react/runtime/types/types.d.ts +++ b/packages/react/runtime/types/types.d.ts @@ -20,6 +20,7 @@ declare global { declare const __MAIN_THREAD__: boolean; declare const __PROFILE__: boolean; declare const __ALOG__: boolean | undefined; + declare const __ALOG_ELEMENT_API__: boolean | undefined; declare const __ENABLE_SSR__: boolean; declare function __CreatePage(componentId: string, cssId: number): FiberElement; diff --git a/packages/react/testing-library/src/vitest-global-setup.js b/packages/react/testing-library/src/vitest-global-setup.js index e140a6f617..70e627e480 100644 --- a/packages/react/testing-library/src/vitest-global-setup.js +++ b/packages/react/testing-library/src/vitest-global-setup.js @@ -110,7 +110,9 @@ globalThis.onInjectMainThreadGlobals = (target) => { target.globalPipelineOptions = undefined; - initElementPAPICallAlog(target); + if (typeof __ALOG_ELEMENT_API__ !== 'undefined' && __ALOG_ELEMENT_API__) { + initElementPAPICallAlog(target); + } }; globalThis.onInjectBackgroundThreadGlobals = (target) => { if (onInjectBackgroundThreadGlobals) { diff --git a/packages/testing-library/testing-environment/src/index.ts b/packages/testing-library/testing-environment/src/index.ts index 73b2f52bc1..8d2aa611ec 100644 --- a/packages/testing-library/testing-environment/src/index.ts +++ b/packages/testing-library/testing-environment/src/index.ts @@ -240,6 +240,7 @@ function injectMainThreadGlobals(target?: any, polyfills?: any) { target.__DEV__ = true; target.__PROFILE__ = true; target.__ALOG__ = true; + target.__ALOG_ELEMENT_API__ = true; target.__JS__ = false; target.__LEPUS__ = true; target.__BACKGROUND__ = false; @@ -378,6 +379,7 @@ function injectBackgroundThreadGlobals(target?: any, polyfills?: any) { target.__DEV__ = true; target.__PROFILE__ = true; target.__ALOG__ = true; + target.__ALOG_ELEMENT_API__ = true; target.__JS__ = true; target.__LEPUS__ = false; target.__BACKGROUND__ = true; diff --git a/packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts b/packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts index 934ea745cb..b1a37f6d9c 100644 --- a/packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts +++ b/packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts @@ -184,6 +184,10 @@ class ReactWebpackPlugin { ), // User can enable ALog by environment variable `REACT_ALOG=true` __ALOG__: JSON.stringify(Boolean(process.env['REACT_ALOG'])), + // User can enable ALog of element API calls by environment variable `REACT_ALOG_ELEMENT_API=true` + __ALOG_ELEMENT_API__: JSON.stringify( + Boolean(process.env['REACT_ALOG_ELEMENT_API']), + ), __EXTRACT_STR__: JSON.stringify(Boolean(options.extractStr)), __FIRST_SCREEN_SYNC_TIMING__: JSON.stringify( options.firstScreenSyncTiming,