-
Notifications
You must be signed in to change notification settings - Fork 122
feat: add dual-thread commutation logs #2081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@lynx-js/react": patch | ||
| --- | ||
|
|
||
| Add dual-thread commutation logs for troubleshooting when `REACT_ALOG=true` or global define `__ALOG__` is set. |
50 changes: 50 additions & 0 deletions
50
packages/react/runtime/__test__/alog/elementPAPICall.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { describe, it, vi } from 'vitest'; | ||
| import { initElementPAPICallAlog } from '../../src/alog/elementPAPICall'; | ||
| import { globalEnvManager } from '../utils/envManager'; | ||
| import { expect } from 'vitest'; | ||
|
|
||
| describe('ElementPAPICall Alog', () => { | ||
| it('should log ElementPAPICall as ALog', () => { | ||
| globalEnvManager.switchToMainThread(); | ||
| console.alog = vi.fn(); | ||
| initElementPAPICallAlog(); | ||
|
|
||
| const page = __CreatePage('0', 0); | ||
| __SetCSSId([page], 0); | ||
| const text0 = __CreateText(0); | ||
| const rawText0 = __CreateRawText('2', text0.$$uiSign); | ||
| __AppendElement(text0, rawText0); | ||
| __AppendElement(page, text0); | ||
| __AddDataset(text0, 'testid', 'count-value'); | ||
| __OnLifecycleEvent(['rLynxFirstScreen', { 'root': '{}', 'jsReadyEventIdSwap': {} }]); | ||
|
|
||
| expect(console.alog.mock.calls).toMatchInlineSnapshot(` | ||
| [ | ||
| [ | ||
| "[ReactLynxDebug] FiberElement API call #1: __CreatePage("0", 0) => page#0", | ||
| ], | ||
| [ | ||
| "[ReactLynxDebug] FiberElement API call #2: __SetCSSId([page#0], 0)", | ||
| ], | ||
| [ | ||
| "[ReactLynxDebug] FiberElement API call #3: __CreateText(0) => text#1", | ||
| ], | ||
| [ | ||
| "[ReactLynxDebug] FiberElement API call #4: __CreateRawText("2", 1) => raw-text#2", | ||
| ], | ||
| [ | ||
| "[ReactLynxDebug] FiberElement API call #5: __AppendElement(text#1, raw-text#2)", | ||
| ], | ||
| [ | ||
| "[ReactLynxDebug] FiberElement API call #6: __AppendElement(page#0, text#1)", | ||
| ], | ||
| [ | ||
| "[ReactLynxDebug] FiberElement API call #7: __AddDataset(text#1, "testid", "count-value")", | ||
| ], | ||
| [ | ||
| "[ReactLynxDebug] FiberElement API call #8: __OnLifecycleEvent(["rLynxFirstScreen", {"root":"{}","jsReadyEventIdSwap":{}}])", | ||
| ], | ||
| ] | ||
| `); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // 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 { profileEnd, profileStart } from '../debug/utils.js'; | ||
|
|
||
| const fiberElementPAPINameList = [ | ||
| '__CreatePage', | ||
| '__CreateElement', | ||
| '__CreateWrapperElement', | ||
| '__CreateText', | ||
| '__CreateImage', | ||
| '__CreateView', | ||
| '__CreateRawText', | ||
| '__CreateList', | ||
| '__AppendElement', | ||
| '__InsertElementBefore', | ||
| '__RemoveElement', | ||
| '__ReplaceElement', | ||
| '__FirstElement', | ||
| '__LastElement', | ||
| '__NextElement', | ||
| '__GetPageElement', | ||
| '__GetTemplateParts', | ||
| '__AddDataset', | ||
| '__SetDataset', | ||
| '__GetDataset', | ||
| '__SetAttribute', | ||
| '__GetAttributes', | ||
| '__GetAttributeByName', | ||
| '__GetAttributeNames', | ||
| '__SetClasses', | ||
| '__SetCSSId', | ||
| '__AddInlineStyle', | ||
| '__SetInlineStyles', | ||
| '__AddEvent', | ||
| '__SetID', | ||
| '__GetElementUniqueID', | ||
| '__GetTag', | ||
| '__FlushElementTree', | ||
| '__UpdateListCallbacks', | ||
| '__OnLifecycleEvent', | ||
| '__QueryComponent', | ||
| '__SetGestureDetector', | ||
| ]; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| export function initElementPAPICallAlog(globalWithIndex: Record<string, unknown> = globalThis): void { | ||
| let count = 0; | ||
| const fiberElementMap = new Map<any, { | ||
| tag: string; | ||
| uniqueId: number; | ||
| }>(); | ||
| function formatFiberElement(fiberElement: FiberElement): string { | ||
| const fiberElementInfo = fiberElementMap.get(fiberElement)!; | ||
| return `${fiberElementInfo.tag}#${fiberElementInfo.uniqueId}`; | ||
| } | ||
| const filteredFiberElementPAPINameList = fiberElementPAPINameList.filter(fiberElementPAPIName => | ||
| typeof globalWithIndex[fiberElementPAPIName] === 'function' | ||
| ); | ||
| const originalFiberElementPAPIs = filteredFiberElementPAPINameList.reduce((prev, fiberElementPAPIName) => ({ | ||
| ...prev, | ||
| [fiberElementPAPIName]: globalWithIndex[fiberElementPAPIName] as (...args: unknown[]) => unknown, | ||
| }), {} as Record<string, (...args: unknown[]) => unknown>); | ||
|
|
||
| filteredFiberElementPAPINameList.forEach(fiberElementPAPIName => { | ||
| const oldFiberElementPAPI = globalWithIndex[fiberElementPAPIName]; | ||
| if (typeof oldFiberElementPAPI === 'function') { | ||
| globalWithIndex[fiberElementPAPIName] = (...args: unknown[]): unknown => { | ||
| if (__PROFILE__) { | ||
|
upupming marked this conversation as resolved.
|
||
| profileStart(`FiberElementPAPI: ${fiberElementPAPIName}`, { | ||
| args: { | ||
| args: JSON.stringify(args), | ||
| }, | ||
| }); | ||
| } | ||
| const result = (oldFiberElementPAPI as (...args: unknown[]) => unknown)(...args); | ||
| if (__PROFILE__) { | ||
| profileEnd(); | ||
| } | ||
|
|
||
| const formattedArgs = [...args]; | ||
|
|
||
| for (let i = 0; i < formattedArgs.length; i++) { | ||
| const arg = formattedArgs[i]; | ||
| if (Array.isArray(arg)) { | ||
| formattedArgs[i] = '[' + arg.map((item: unknown) => { | ||
| if (fiberElementMap.has(item)) { | ||
| return formatFiberElement(item as FiberElement); | ||
| } | ||
| return JSON.stringify(item); | ||
| }).join(', ') + ']'; | ||
| } else if (fiberElementMap.has(arg)) { | ||
| formattedArgs[i] = formatFiberElement(arg as FiberElement); | ||
| } else { | ||
| formattedArgs[i] = JSON.stringify(arg); | ||
| } | ||
| } | ||
|
|
||
| if ( | ||
| fiberElementPAPIName === '__CreatePage' | ||
| || fiberElementPAPIName === '__CreateElement' | ||
| || fiberElementPAPIName === '__CreateWrapperElement' | ||
| || fiberElementPAPIName === '__CreateText' | ||
| || fiberElementPAPIName === '__CreateImage' | ||
| || fiberElementPAPIName === '__CreateView' | ||
| || fiberElementPAPIName === '__CreateRawText' | ||
| || fiberElementPAPIName === '__CreateList' | ||
| ) { | ||
| fiberElementMap.set(result as FiberElement, { | ||
| tag: originalFiberElementPAPIs['__GetTag']!(result as FiberElement) as string, | ||
| uniqueId: originalFiberElementPAPIs['__GetElementUniqueID']!(result as FiberElement) as number, | ||
| }); | ||
|
upupming marked this conversation as resolved.
|
||
| } | ||
|
|
||
| let formattedResult; | ||
| if (fiberElementMap.has(result)) { | ||
| formattedResult = formatFiberElement(result as FiberElement); | ||
| } else if (result !== null) { | ||
| formattedResult = JSON.stringify(result); | ||
| } | ||
|
|
||
| console.alog?.( | ||
| `[ReactLynxDebug] FiberElement API call #${++count}: ${fiberElementPAPIName}(${formattedArgs.join(', ')})${ | ||
| formattedResult == null ? '' : ` => ${formattedResult}` | ||
| }`, | ||
| ); | ||
| return result; | ||
| }; | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| // 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(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.