Skip to content

Commit 27e4fdc

Browse files
committed
fix: always import worklet-runtime.js & remove logs
1 parent 7f85f59 commit 27e4fdc

File tree

8 files changed

+33
-26
lines changed

8 files changed

+33
-26
lines changed

packages/react/runtime/src/lifecycle/patch/commit.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import { takeWorkletRefInitValuePatch } from '../../worklet/workletRefPool.js';
3131
import { getReloadVersion } from '../pass.js';
3232
import type { SnapshotPatch } from './snapshotPatch.js';
3333
import { takeGlobalSnapshotPatch } from './snapshotPatch.js';
34-
import { prettyFormatSnapshotPatch } from '../../debug/formatPatch.js';
35-
import { printSnapshotInstance } from '../../debug/printSnapshot.js';
3634

3735
let globalFlushOptions: FlushOptions = {};
3836
function takeGlobalFlushOptions() {
@@ -176,11 +174,11 @@ function commitPatchUpdate(patchList: PatchList, patchOptions: GlobalPatchOption
176174
data: string;
177175
patchOptions: PatchOptions;
178176
} {
179-
console.debug('********** JS update:');
180-
printSnapshotInstance(
181-
(backgroundSnapshotInstanceManager.values.get(1) ?? backgroundSnapshotInstanceManager.values.get(-1))!,
182-
);
183-
console.debug('commitPatchUpdate:', prettyFormatSnapshotPatch(patchList.patchList[0]?.snapshotPatch));
177+
// console.debug('********** JS update:');
178+
// printSnapshotInstance(
179+
// (backgroundSnapshotInstanceManager.values.get(1) ?? backgroundSnapshotInstanceManager.values.get(-1))!,
180+
// );
181+
// console.debug('commitPatchUpdate:', prettyFormatSnapshotPatch(patchList.patchList[0]?.snapshotPatch));
184182

185183
if (__PROFILE__) {
186184
console.profile('commitChanges');

packages/react/runtime/src/lifecycle/patch/updateMainThread.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import { updateWorkletRefInitValueChanges } from '@lynx-js/react/worklet-runtime
77
import type { PatchList, PatchOptions } from './commit.js';
88
import { setMainThreadHydrating } from './isMainThreadHydrating.js';
99
import { snapshotPatchApply } from './snapshotPatchApply.js';
10-
import { printSnapshotInstance } from '../../debug/printSnapshot.js';
1110
import { LifecycleConstant } from '../../lifecycleConstant.js';
1211
import { markTiming, setPipeline } from '../../lynx/performance.js';
1312
import { __pendingListUpdates } from '../../pendingListUpdates.js';
1413
import { applyRefQueue } from '../../snapshot/workletRef.js';
15-
import { __page, snapshotInstanceManager } from '../../snapshot.js';
14+
import { __page } from '../../snapshot.js';
1615
import { getReloadVersion } from '../pass.js';
1716

1817
function updateMainThread(
@@ -52,8 +51,8 @@ function updateMainThread(
5251
snapshotPatchApply(snapshotPatch);
5352
}
5453
__pendingListUpdates.flush();
55-
console.debug('********** Lepus updatePatch:');
56-
printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);
54+
// console.debug('********** Lepus updatePatch:');
55+
// printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);
5756
}
5857
} finally {
5958
markTiming('patchChangesEnd');

packages/react/runtime/src/snapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ export class SnapshotInstance {
557557
}
558558

559559
insertBefore(newNode: SnapshotInstance, existingNode?: SnapshotInstance): void {
560-
console.log('yra insertBefore', this.__id, newNode.__id);
560+
// console.log('yra insertBefore', this.__id, newNode.__id);
561561
const __snapshot_def = this.__snapshot_def;
562562
if (__snapshot_def.isListHolder) {
563563
if (__pendingListUpdates.values) {
@@ -714,7 +714,7 @@ interface MTCProps extends Attributes {
714714
}
715715

716716
function renderMTC(snapshotInstance: SnapshotInstance, props: MTCProps) {
717-
console.log('yra renderMTC', snapshotInstance.__id, props);
717+
// console.log('yra renderMTC', snapshotInstance.__id, props);
718718
if (snapshotInstance.__elements === undefined) {
719719
return;
720720
}

packages/react/runtime/src/snapshot/event.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License Version 2.0 that can be found in the
33
// LICENSE file in the root directory of this source tree.
44

5+
import { loadWorkletRuntime } from '@lynx-js/react/worklet-runtime/bindings';
56
import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings';
67
import type { BaseEvent } from '@lynx-js/types';
78

@@ -14,6 +15,20 @@ function registerMTCEvent(
1415
id: string,
1516
callback: undefined | ((e: BaseEvent) => void),
1617
): Record<string, unknown> | undefined {
18+
if (!globalThis.lynxWorkletImpl) {
19+
// @ts-ignore
20+
loadWorkletRuntime(typeof globDynamicComponentEntry === 'undefined' ? undefined : globDynamicComponentEntry);
21+
// @ts-ignore
22+
globalThis.runMTCEvent = (ctx: Worklet, e: [any]) => {
23+
const event = {
24+
...e[0],
25+
target: new Element(e[0].target.elementRefptr),
26+
currentTarget: new Element(e[0].currentTarget.elementRefptr),
27+
} as BaseEvent;
28+
mtcEvents.get(ctx._wkltId)!(event);
29+
};
30+
}
31+
1732
if (!callback) {
1833
mtcEvents.delete(id);
1934
return undefined;
@@ -28,16 +43,6 @@ function registerMTCEvent(
2843
};
2944
}
3045

31-
// @ts-ignore
32-
globalThis.runWorklet = (ctx: Worklet, e: [any]) => {
33-
const event = {
34-
...e[0],
35-
target: new Element(e[0].target.elementRefptr),
36-
currentTarget: new Element(e[0].currentTarget.elementRefptr),
37-
} as BaseEvent;
38-
mtcEvents.get(ctx._wkltId)!(event);
39-
};
40-
4146
function updateEvent(
4247
snapshot: SnapshotInstance,
4348
expIndex: number,

packages/react/runtime/src/snapshot/ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function updateRef(
7272
}
7373

7474
const value: unknown = snapshot.__values![expIndex];
75-
console.log('yra updateRef', value);
75+
// console.log('yra updateRef', value);
7676
let ref;
7777
if (!value) {
7878
// do nothing

packages/react/runtime/src/snapshot/workletRef.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function addToRefQueue(worklet: Ref, element: Element): void {
4141
}
4242

4343
export function workletUnRef(value: Ref): void {
44-
console.log('yra workletUnRef', value);
44+
// console.log('yra workletUnRef', value);
4545
if ('_wvid' in value) {
4646
update(value as WorkletRefImpl<Element>, null);
4747
} else if ('_wkltId' in value) {

packages/react/worklet-runtime/src/workletRuntime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ function runWorklet(ctx: Worklet, params: ClosureValueType[]): unknown {
5050
console.warn('Worklet: Invalid worklet object: ' + JSON.stringify(ctx));
5151
return;
5252
}
53+
if (ctx._workletType === 'mtc') {
54+
// @ts-ignore
55+
globalThis.runMTCEvent(ctx, params);
56+
return;
57+
}
5358
if ('_lepusWorkletHash' in ctx) {
5459
delayExecUntilJsReady(ctx._lepusWorkletHash, params);
5560
return;

packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class ReactWebpackPlugin {
257257
if (
258258
lepusCode.root?.source.source().toString()?.includes(
259259
'registerWorkletInternal',
260-
)
260+
) || true
261261
) {
262262
const path = compiler.options.mode === 'development'
263263
? '@lynx-js/react/worklet-dev-runtime'

0 commit comments

Comments
 (0)