Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/olive-hounds-enter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react": patch
---

Add alog and trace for BTS event handlers.
4 changes: 2 additions & 2 deletions packages/react/runtime/src/lifecycle/event/delayEvents.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 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.
let delayedEvents: [handlerName: string, data: unknown][] | undefined;
let delayedEvents: [handlerName: string, data: EventDataType][] | undefined;

function delayedPublishEvent(handlerName: string, data: unknown): void {
function delayedPublishEvent(handlerName: string, data: EventDataType): void {
delayedEvents ??= [];
delayedEvents.push([handlerName, data]);
}
Expand Down
45 changes: 39 additions & 6 deletions packages/react/runtime/src/lynx/tt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function onLifecycleEventImpl(type: LifecycleConstant, data: unknown): void {
break;
}
case LifecycleConstant.publishEvent: {
const { handlerName, data: d } = data as { handlerName: string; data: unknown };
const { handlerName, data: d } = data as { handlerName: string; data: EventDataType };
lynxCoreInject.tt.publishEvent(handlerName, d);
break;
}
Expand All @@ -201,25 +201,58 @@ function flushDelayedLifecycleEvents(): void {
flushingDelayedLifecycleEvents = false;
}

function publishEvent(handlerName: string, data: unknown) {
function publishEvent(handlerName: string, data: EventDataType) {
lynxCoreInject.tt.callBeforePublishEvent?.(data);
const eventHandler = backgroundSnapshotInstanceManager.getValueBySign(
handlerName,
);
) as ((...args: unknown[]) => void) | undefined;

if (__PROFILE__) {
profileStart(`ReactLynx::publishEvent`, {
args: {
handlerName,
type: data.type,
snapshotInstanceType: backgroundSnapshotInstanceManager.values.get(
Number(handlerName.split(':')[0]),
)?.type ?? '',
jsFunctionName: eventHandler?.name ?? '',
},
});
}
if (typeof __ALOG__ !== 'undefined' && __ALOG__) {
console.alog?.(
`[ReactLynxDebug] BTS received event:\n` + JSON.stringify(
{
handlerName,
type: data.type,
snapshotInstanceType: backgroundSnapshotInstanceManager.values.get(
Number(handlerName.split(':')[0]),
)?.type ?? '',
jsFunctionName: eventHandler?.name ?? '',
},
null,
2,
),
);
}

if (eventHandler) {
try {
(eventHandler as (...args: unknown[]) => void)(data);
eventHandler(data);
} catch (e) {
lynx.reportError(e as Error);
}
}
if (__PROFILE__) {
profileEnd();
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

function publicComponentEvent(_componentId: string, handlerName: string, data: unknown) {
function publicComponentEvent(_componentId: string, handlerName: string, data: EventDataType) {
publishEvent(handlerName, data);
}

function delayedPublicComponentEvent(_componentId: string, handlerName: string, data: unknown) {
function delayedPublicComponentEvent(_componentId: string, handlerName: string, data: EventDataType) {
delayedPublishEvent(handlerName, data);
}

Expand Down
9 changes: 7 additions & 2 deletions packages/react/runtime/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ declare global {
removeComponents: () => void;
}

declare interface EventDataType {
type: string;
[prop: string]: unknown;
}

namespace lynxCoreInject {
const tt: {
_params: {
Expand All @@ -185,8 +190,8 @@ declare global {
};

OnLifecycleEvent: ([type, data]: [LifecycleConstant, unknown]) => void;
publishEvent: (handlerName: string, data: unknown) => void;
publicComponentEvent: (componentId: string, handlerName: string, data: unknown) => void;
publishEvent: (handlerName: string, data: EventDataType) => void;
publicComponentEvent: (componentId: string, handlerName: string, data: EventDataType) => void;
Comment thread
upupming marked this conversation as resolved.
callDestroyLifetimeFun: () => void;
updateGlobalProps: (newData: Record<string, unknown>) => void;
updateCardData: (newData: Record<string, any>, options?: Record<string, unknown>) => void;
Expand Down
Loading
Loading