@lynx-js/react 0.105.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +250 -0
- package/LICENSE +202 -0
- package/README.md +20 -0
- package/components/lib/Page.d.ts +3 -0
- package/components/lib/Page.js +56 -0
- package/components/lib/Page.js.map +1 -0
- package/components/lib/index.d.ts +1 -0
- package/components/lib/index.js +5 -0
- package/components/lib/index.js.map +1 -0
- package/components/src/Page.ts +75 -0
- package/components/src/index.ts +5 -0
- package/package.json +162 -0
- package/refresh/.gitignore +1 -0
- package/refresh/.npmignore +3 -0
- package/refresh/.turbo/turbo-build.log +8 -0
- package/refresh/dist/index.js +311 -0
- package/refresh/package.json +21 -0
- package/refresh/src/index.ts +6 -0
- package/refresh/src/prefresh.d.ts +11 -0
- package/refresh/tsconfig.json +4 -0
- package/refresh/turbo.json +15 -0
- package/runtime/jsx-dev-runtime/index.d.ts +5 -0
- package/runtime/jsx-dev-runtime/index.js +4 -0
- package/runtime/jsx-runtime/index.d.ts +4 -0
- package/runtime/jsx-runtime/index.js +4 -0
- package/runtime/lazy/import.d.ts +1 -0
- package/runtime/lazy/import.js +55 -0
- package/runtime/lazy/internal.js +39 -0
- package/runtime/lazy/jsx-dev-runtime.js +12 -0
- package/runtime/lazy/jsx-runtime.js +12 -0
- package/runtime/lazy/legacy-react-runtime.js +20 -0
- package/runtime/lazy/react-lepus.js +9 -0
- package/runtime/lazy/react.js +46 -0
- package/runtime/lazy/target.js +11 -0
- package/runtime/lepus/index.d.ts +4 -0
- package/runtime/lepus/index.js +43 -0
- package/runtime/lepus/jsx-dev-runtime/index.js +4 -0
- package/runtime/lepus/jsx-runtime/index.js +66 -0
- package/runtime/lib/backgroundSnapshot.d.ts +23 -0
- package/runtime/lib/backgroundSnapshot.js +348 -0
- package/runtime/lib/backgroundSnapshot.js.map +1 -0
- package/runtime/lib/compat/componentIs.d.ts +4 -0
- package/runtime/lib/compat/componentIs.js +20 -0
- package/runtime/lib/compat/componentIs.js.map +1 -0
- package/runtime/lib/compat/initData.d.ts +43 -0
- package/runtime/lib/compat/initData.js +93 -0
- package/runtime/lib/compat/initData.js.map +1 -0
- package/runtime/lib/compat/lynxComponent.d.ts +5 -0
- package/runtime/lib/compat/lynxComponent.js +71 -0
- package/runtime/lib/compat/lynxComponent.js.map +1 -0
- package/runtime/lib/debug/debug.d.ts +2 -0
- package/runtime/lib/debug/debug.js +9 -0
- package/runtime/lib/debug/debug.js.map +1 -0
- package/runtime/lib/debug/printSnapshot.d.ts +3 -0
- package/runtime/lib/debug/printSnapshot.js +21 -0
- package/runtime/lib/debug/printSnapshot.js.map +1 -0
- package/runtime/lib/debug/profile.d.ts +1 -0
- package/runtime/lib/debug/profile.js +51 -0
- package/runtime/lib/debug/profile.js.map +1 -0
- package/runtime/lib/document.d.ts +4 -0
- package/runtime/lib/document.js +49 -0
- package/runtime/lib/document.js.map +1 -0
- package/runtime/lib/gesture/processGesture.d.ts +4 -0
- package/runtime/lib/gesture/processGesture.js +48 -0
- package/runtime/lib/gesture/processGesture.js.map +1 -0
- package/runtime/lib/gesture/processGestureBagkround.d.ts +2 -0
- package/runtime/lib/gesture/processGestureBagkround.js +16 -0
- package/runtime/lib/gesture/processGestureBagkround.js.map +1 -0
- package/runtime/lib/gesture/types.d.ts +34 -0
- package/runtime/lib/gesture/types.js +13 -0
- package/runtime/lib/gesture/types.js.map +1 -0
- package/runtime/lib/hooks/react.d.ts +26 -0
- package/runtime/lib/hooks/react.js +35 -0
- package/runtime/lib/hooks/react.js.map +1 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +29 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js +53 -0
- package/runtime/lib/hooks/useLynxGlobalEventListener.js.map +1 -0
- package/runtime/lib/hydrate.d.ts +18 -0
- package/runtime/lib/hydrate.js +271 -0
- package/runtime/lib/hydrate.js.map +1 -0
- package/runtime/lib/index.d.ts +9 -0
- package/runtime/lib/index.js +46 -0
- package/runtime/lib/index.js.map +1 -0
- package/runtime/lib/internal.d.ts +26 -0
- package/runtime/lib/internal.js +41 -0
- package/runtime/lib/internal.js.map +1 -0
- package/runtime/lib/legacy-react-runtime/index.d.ts +7 -0
- package/runtime/lib/legacy-react-runtime/index.js +34 -0
- package/runtime/lib/legacy-react-runtime/index.js.map +1 -0
- package/runtime/lib/lifecycle/delayUnmount.d.ts +8 -0
- package/runtime/lib/lifecycle/delayUnmount.js +68 -0
- package/runtime/lib/lifecycle/delayUnmount.js.map +1 -0
- package/runtime/lib/lifecycle/destroy.d.ts +2 -0
- package/runtime/lib/lifecycle/destroy.js +21 -0
- package/runtime/lib/lifecycle/destroy.js.map +1 -0
- package/runtime/lib/lifecycle/pass.d.ts +3 -0
- package/runtime/lib/lifecycle/pass.js +12 -0
- package/runtime/lib/lifecycle/pass.js.map +1 -0
- package/runtime/lib/lifecycle/patchUpdate.d.ts +23 -0
- package/runtime/lib/lifecycle/patchUpdate.js +179 -0
- package/runtime/lib/lifecycle/patchUpdate.js.map +1 -0
- package/runtime/lib/lifecycle/reload.d.ts +3 -0
- package/runtime/lib/lifecycle/reload.js +63 -0
- package/runtime/lib/lifecycle/reload.js.map +1 -0
- package/runtime/lib/lifecycle/render.d.ts +2 -0
- package/runtime/lib/lifecycle/render.js +44 -0
- package/runtime/lib/lifecycle/render.js.map +1 -0
- package/runtime/lib/lifecycleConstant.d.ts +12 -0
- package/runtime/lib/lifecycleConstant.js +17 -0
- package/runtime/lib/lifecycleConstant.js.map +1 -0
- package/runtime/lib/list.d.ts +40 -0
- package/runtime/lib/list.js +305 -0
- package/runtime/lib/list.js.map +1 -0
- package/runtime/lib/lynx/calledByNative.d.ts +2 -0
- package/runtime/lib/lynx/calledByNative.js +113 -0
- package/runtime/lib/lynx/calledByNative.js.map +1 -0
- package/runtime/lib/lynx/component.d.ts +1 -0
- package/runtime/lib/lynx/component.js +69 -0
- package/runtime/lib/lynx/component.js.map +1 -0
- package/runtime/lib/lynx/dynamic-js.d.ts +2 -0
- package/runtime/lib/lynx/dynamic-js.js +31 -0
- package/runtime/lib/lynx/dynamic-js.js.map +1 -0
- package/runtime/lib/lynx/env.d.ts +1 -0
- package/runtime/lib/lynx/env.js +92 -0
- package/runtime/lib/lynx/env.js.map +1 -0
- package/runtime/lib/lynx/injectLepusMethods.d.ts +2 -0
- package/runtime/lib/lynx/injectLepusMethods.js +50 -0
- package/runtime/lib/lynx/injectLepusMethods.js.map +1 -0
- package/runtime/lib/lynx/lazy-bundle.d.ts +9 -0
- package/runtime/lib/lynx/lazy-bundle.js +119 -0
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -0
- package/runtime/lib/lynx/performance.d.ts +29 -0
- package/runtime/lib/lynx/performance.js +100 -0
- package/runtime/lib/lynx/performance.js.map +1 -0
- package/runtime/lib/lynx/tt.d.ts +4 -0
- package/runtime/lib/lynx/tt.js +193 -0
- package/runtime/lib/lynx/tt.js.map +1 -0
- package/runtime/lib/lynx-api.d.ts +311 -0
- package/runtime/lib/lynx-api.js +116 -0
- package/runtime/lib/lynx-api.js.map +1 -0
- package/runtime/lib/lynx.d.ts +2 -0
- package/runtime/lib/lynx.js +91 -0
- package/runtime/lib/lynx.js.map +1 -0
- package/runtime/lib/opcodes.d.ts +2 -0
- package/runtime/lib/opcodes.js +59 -0
- package/runtime/lib/opcodes.js.map +1 -0
- package/runtime/lib/renderToOpcodes/constants.d.ts +17 -0
- package/runtime/lib/renderToOpcodes/constants.js +23 -0
- package/runtime/lib/renderToOpcodes/constants.js.map +1 -0
- package/runtime/lib/renderToOpcodes/index.d.ts +13 -0
- package/runtime/lib/renderToOpcodes/index.js +227 -0
- package/runtime/lib/renderToOpcodes/index.js.map +1 -0
- package/runtime/lib/root.d.ts +7 -0
- package/runtime/lib/root.js +17 -0
- package/runtime/lib/root.js.map +1 -0
- package/runtime/lib/snapshot/event.d.ts +3 -0
- package/runtime/lib/snapshot/event.js +24 -0
- package/runtime/lib/snapshot/event.js.map +1 -0
- package/runtime/lib/snapshot/gesture.d.ts +2 -0
- package/runtime/lib/snapshot/gesture.js +18 -0
- package/runtime/lib/snapshot/gesture.js.map +1 -0
- package/runtime/lib/snapshot/platformInfo.d.ts +4 -0
- package/runtime/lib/snapshot/platformInfo.js +35 -0
- package/runtime/lib/snapshot/platformInfo.js.map +1 -0
- package/runtime/lib/snapshot/ref.d.ts +10 -0
- package/runtime/lib/snapshot/ref.js +119 -0
- package/runtime/lib/snapshot/ref.js.map +1 -0
- package/runtime/lib/snapshot/spread.d.ts +5 -0
- package/runtime/lib/snapshot/spread.js +289 -0
- package/runtime/lib/snapshot/spread.js.map +1 -0
- package/runtime/lib/snapshot/workletEvent.d.ts +3 -0
- package/runtime/lib/snapshot/workletEvent.js +22 -0
- package/runtime/lib/snapshot/workletEvent.js.map +1 -0
- package/runtime/lib/snapshot/workletRef.d.ts +5 -0
- package/runtime/lib/snapshot/workletRef.js +52 -0
- package/runtime/lib/snapshot/workletRef.js.map +1 -0
- package/runtime/lib/snapshot.d.ts +81 -0
- package/runtime/lib/snapshot.js +477 -0
- package/runtime/lib/snapshot.js.map +1 -0
- package/runtime/lib/snapshotPatch.d.ts +14 -0
- package/runtime/lib/snapshotPatch.js +31 -0
- package/runtime/lib/snapshotPatch.js.map +1 -0
- package/runtime/lib/snapshotPatchApply.d.ts +2 -0
- package/runtime/lib/snapshotPatchApply.js +110 -0
- package/runtime/lib/snapshotPatchApply.js.map +1 -0
- package/runtime/lib/utils.d.ts +4 -0
- package/runtime/lib/utils.js +32 -0
- package/runtime/lib/utils.js.map +1 -0
- package/runtime/lib/worklet/ctx.d.ts +1 -0
- package/runtime/lib/worklet/ctx.js +17 -0
- package/runtime/lib/worklet/ctx.js.map +1 -0
- package/runtime/lib/worklet/execMap.d.ts +1 -0
- package/runtime/lib/worklet/execMap.js +42 -0
- package/runtime/lib/worklet/execMap.js.map +1 -0
- package/runtime/lib/worklet/functionality.d.ts +1 -0
- package/runtime/lib/worklet/functionality.js +11 -0
- package/runtime/lib/worklet/functionality.js.map +1 -0
- package/runtime/lib/worklet/hmr.d.ts +1 -0
- package/runtime/lib/worklet/hmr.js +21 -0
- package/runtime/lib/worklet/hmr.js.map +1 -0
- package/runtime/lib/worklet/indexMap.d.ts +8 -0
- package/runtime/lib/worklet/indexMap.js +17 -0
- package/runtime/lib/worklet/indexMap.js.map +1 -0
- package/runtime/lib/worklet/jsImpl.d.ts +11 -0
- package/runtime/lib/worklet/jsImpl.js +68 -0
- package/runtime/lib/worklet/jsImpl.js.map +1 -0
- package/runtime/lib/worklet/runWorklet.d.ts +14 -0
- package/runtime/lib/worklet/runWorklet.js +82 -0
- package/runtime/lib/worklet/runWorklet.js.map +1 -0
- package/runtime/lib/worklet/workletRef.d.ts +131 -0
- package/runtime/lib/worklet/workletRef.js +96 -0
- package/runtime/lib/worklet/workletRef.js.map +1 -0
- package/runtime/lib/worklet/workletRefPool.d.ts +2 -0
- package/runtime/lib/worklet/workletRefPool.js +22 -0
- package/runtime/lib/worklet/workletRefPool.js.map +1 -0
- package/runtime/src/backgroundSnapshot.ts +452 -0
- package/runtime/src/compat/componentIs.ts +30 -0
- package/runtime/src/compat/initData.ts +140 -0
- package/runtime/src/compat/lynxComponent.ts +80 -0
- package/runtime/src/debug/debug.ts +9 -0
- package/runtime/src/debug/printSnapshot.ts +28 -0
- package/runtime/src/debug/profile.ts +54 -0
- package/runtime/src/document.ts +53 -0
- package/runtime/src/gesture/processGesture.ts +77 -0
- package/runtime/src/gesture/processGestureBagkround.ts +15 -0
- package/runtime/src/gesture/types.ts +39 -0
- package/runtime/src/hooks/react.ts +62 -0
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +59 -0
- package/runtime/src/hydrate.ts +364 -0
- package/runtime/src/index.ts +89 -0
- package/runtime/src/internal.ts +60 -0
- package/runtime/src/legacy-react-runtime/index.ts +40 -0
- package/runtime/src/lifecycle/delayUnmount.ts +77 -0
- package/runtime/src/lifecycle/destroy.ts +26 -0
- package/runtime/src/lifecycle/pass.ts +14 -0
- package/runtime/src/lifecycle/patchUpdate.ts +240 -0
- package/runtime/src/lifecycle/reload.ts +79 -0
- package/runtime/src/lifecycle/render.ts +46 -0
- package/runtime/src/lifecycleConstant.ts +16 -0
- package/runtime/src/list.ts +375 -0
- package/runtime/src/lynx/calledByNative.ts +132 -0
- package/runtime/src/lynx/component.ts +116 -0
- package/runtime/src/lynx/dynamic-js.ts +33 -0
- package/runtime/src/lynx/env.ts +110 -0
- package/runtime/src/lynx/injectLepusMethods.ts +53 -0
- package/runtime/src/lynx/lazy-bundle.ts +126 -0
- package/runtime/src/lynx/performance.ts +117 -0
- package/runtime/src/lynx/tt.ts +212 -0
- package/runtime/src/lynx-api.ts +374 -0
- package/runtime/src/lynx.ts +105 -0
- package/runtime/src/opcodes.ts +64 -0
- package/runtime/src/renderToOpcodes/constants.ts +24 -0
- package/runtime/src/renderToOpcodes/index.ts +301 -0
- package/runtime/src/root.ts +19 -0
- package/runtime/src/snapshot/event.ts +33 -0
- package/runtime/src/snapshot/gesture.ts +25 -0
- package/runtime/src/snapshot/platformInfo.ts +48 -0
- package/runtime/src/snapshot/ref.ts +151 -0
- package/runtime/src/snapshot/spread.ts +287 -0
- package/runtime/src/snapshot/workletEvent.ts +33 -0
- package/runtime/src/snapshot/workletRef.ts +63 -0
- package/runtime/src/snapshot.ts +576 -0
- package/runtime/src/snapshotPatch.ts +56 -0
- package/runtime/src/snapshotPatchApply.ts +117 -0
- package/runtime/src/utils.ts +35 -0
- package/runtime/src/worklet/ctx.ts +22 -0
- package/runtime/src/worklet/execMap.ts +50 -0
- package/runtime/src/worklet/functionality.ts +12 -0
- package/runtime/src/worklet/hmr.ts +26 -0
- package/runtime/src/worklet/indexMap.ts +20 -0
- package/runtime/src/worklet/jsImpl.ts +86 -0
- package/runtime/src/worklet/runWorklet.ts +88 -0
- package/runtime/src/worklet/workletRef.ts +229 -0
- package/runtime/src/worklet/workletRefPool.ts +25 -0
- package/transform/cjs/main.cjs +6 -0
- package/transform/cjs/main.d.cts +3 -0
- package/transform/cjs/package.json +3 -0
- package/transform/dist/wasm.cjs +8478 -0
- package/transform/index.d.ts +187 -0
- package/transform/main.js +15 -0
- package/types/react.d.ts +147 -0
- package/types/react.docs.d.ts +74 -0
- package/worklet-runtime/dist/dev.js +414 -0
- package/worklet-runtime/dist/dev.js.map +8 -0
- package/worklet-runtime/dist/main.js +414 -0
- package/worklet-runtime/dist/main.js.map +8 -0
- package/worklet-runtime/lib/api/element.d.ts +14 -0
- package/worklet-runtime/lib/api/element.js +71 -0
- package/worklet-runtime/lib/api/element.js.map +1 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.d.ts +3 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js +23 -0
- package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -0
- package/worklet-runtime/lib/api/lynxApi.d.ts +2 -0
- package/worklet-runtime/lib/api/lynxApi.js +35 -0
- package/worklet-runtime/lib/api/lynxApi.js.map +1 -0
- package/worklet-runtime/lib/bindings/bindings.d.ts +14 -0
- package/worklet-runtime/lib/bindings/bindings.js +61 -0
- package/worklet-runtime/lib/bindings/bindings.js.map +1 -0
- package/worklet-runtime/lib/bindings/events.d.ts +7 -0
- package/worklet-runtime/lib/bindings/events.js +9 -0
- package/worklet-runtime/lib/bindings/events.js.map +1 -0
- package/worklet-runtime/lib/bindings/index.d.ts +4 -0
- package/worklet-runtime/lib/bindings/index.js +7 -0
- package/worklet-runtime/lib/bindings/index.js.map +1 -0
- package/worklet-runtime/lib/bindings/loadRuntime.d.ts +8 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js +25 -0
- package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -0
- package/worklet-runtime/lib/bindings/types.d.ts +35 -0
- package/worklet-runtime/lib/bindings/types.js +2 -0
- package/worklet-runtime/lib/bindings/types.js.map +1 -0
- package/worklet-runtime/lib/delayWorkletEvent.d.ts +11 -0
- package/worklet-runtime/lib/delayWorkletEvent.js +49 -0
- package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -0
- package/worklet-runtime/lib/global.d.ts +15 -0
- package/worklet-runtime/lib/global.js +2 -0
- package/worklet-runtime/lib/global.js.map +1 -0
- package/worklet-runtime/lib/index.d.ts +1 -0
- package/worklet-runtime/lib/index.js +12 -0
- package/worklet-runtime/lib/index.js.map +1 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.d.ts +18 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js +55 -0
- package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -0
- package/worklet-runtime/lib/listeners.d.ts +2 -0
- package/worklet-runtime/lib/listeners.js +17 -0
- package/worklet-runtime/lib/listeners.js.map +1 -0
- package/worklet-runtime/lib/utils/profile.d.ts +1 -0
- package/worklet-runtime/lib/utils/profile.js +20 -0
- package/worklet-runtime/lib/utils/profile.js.map +1 -0
- package/worklet-runtime/lib/utils/version.d.ts +1 -0
- package/worklet-runtime/lib/utils/version.js +10 -0
- package/worklet-runtime/lib/utils/version.js.map +1 -0
- package/worklet-runtime/lib/workletRef.d.ts +12 -0
- package/worklet-runtime/lib/workletRef.js +50 -0
- package/worklet-runtime/lib/workletRef.js.map +1 -0
- package/worklet-runtime/lib/workletRuntime.d.ts +2 -0
- package/worklet-runtime/lib/workletRuntime.js +128 -0
- package/worklet-runtime/lib/workletRuntime.js.map +1 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { options } from 'preact';
|
|
5
|
+
import type { VNode } from 'preact';
|
|
6
|
+
import type { Component } from 'preact/compat';
|
|
7
|
+
|
|
8
|
+
import { clearDelayedWorklets, updateWorkletRefInitValueChanges } from '@lynx-js/react/worklet-runtime/bindings';
|
|
9
|
+
|
|
10
|
+
import { LifecycleConstant } from '../lifecycleConstant.js';
|
|
11
|
+
import { __pendingListUpdates } from '../list.js';
|
|
12
|
+
import { runDelayedUnmounts, takeDelayedUnmounts } from './delayUnmount.js';
|
|
13
|
+
import { getReloadVersion } from './pass.js';
|
|
14
|
+
import {
|
|
15
|
+
PerformanceTimingKeys,
|
|
16
|
+
globalPipelineOptions,
|
|
17
|
+
markTiming,
|
|
18
|
+
markTimingLegacy,
|
|
19
|
+
setPipeline,
|
|
20
|
+
} from '../lynx/performance.js';
|
|
21
|
+
import { CATCH_ERROR, COMMIT, RENDER_CALLBACKS, VNODE } from '../renderToOpcodes/constants.js';
|
|
22
|
+
import { takeGlobalRefPatchMap, updateBackgroundRefs } from '../snapshot/ref.js';
|
|
23
|
+
import { __page, backgroundSnapshotInstanceManager } from '../snapshot.js';
|
|
24
|
+
import { takeGlobalSnapshotPatch } from '../snapshotPatch.js';
|
|
25
|
+
import type { SnapshotPatch } from '../snapshotPatch.js';
|
|
26
|
+
import { snapshotPatchApply } from '../snapshotPatchApply.js';
|
|
27
|
+
import { isEmptyObject } from '../utils.js';
|
|
28
|
+
import { takeWorkletRefInitValuePatch } from '../worklet/workletRefPool.js';
|
|
29
|
+
|
|
30
|
+
let globalFlushOptions: FlushOptions = {};
|
|
31
|
+
|
|
32
|
+
const globalCommitTaskMap: Map<number, () => void> = /*@__PURE__*/ new Map();
|
|
33
|
+
let nextCommitTaskId = 1;
|
|
34
|
+
|
|
35
|
+
let globalBackgroundSnapshotInstancesToRemove: number[] = [];
|
|
36
|
+
|
|
37
|
+
interface Patch {
|
|
38
|
+
snapshotPatch?: SnapshotPatch;
|
|
39
|
+
workletRefInitValuePatch?: [id: number, value: unknown][];
|
|
40
|
+
flushOptions?: FlushOptions;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface PatchOptions {
|
|
44
|
+
commitTaskId: number;
|
|
45
|
+
pipelineOptions?: PipelineOptions;
|
|
46
|
+
reloadVersion?: number;
|
|
47
|
+
isHydration?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function injectUpdatePatch(): void {
|
|
51
|
+
function updatePatch(
|
|
52
|
+
{ data, patchOptions }: {
|
|
53
|
+
data: string;
|
|
54
|
+
patchOptions: PatchOptions;
|
|
55
|
+
},
|
|
56
|
+
): void {
|
|
57
|
+
if ((patchOptions.reloadVersion ?? 0) < getReloadVersion()) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
setPipeline(patchOptions.pipelineOptions);
|
|
62
|
+
markTiming(PerformanceTimingKeys.parse_changes_start);
|
|
63
|
+
let { snapshotPatch, workletRefInitValuePatch, flushOptions } = JSON.parse(data) as Patch;
|
|
64
|
+
markTiming(PerformanceTimingKeys.parse_changes_end);
|
|
65
|
+
|
|
66
|
+
markTiming(PerformanceTimingKeys.patch_changes_start);
|
|
67
|
+
updateWorkletRefInitValueChanges(workletRefInitValuePatch);
|
|
68
|
+
__pendingListUpdates.clear();
|
|
69
|
+
if (snapshotPatch) {
|
|
70
|
+
snapshotPatchApply(snapshotPatch);
|
|
71
|
+
}
|
|
72
|
+
__pendingListUpdates.flush();
|
|
73
|
+
// console.debug('********** Lepus updatePatch:');
|
|
74
|
+
// printSnapshotInstance(snapshotInstanceManager.values.get(-1)!);
|
|
75
|
+
|
|
76
|
+
commitMainThreadPatchUpdate(patchOptions.commitTaskId);
|
|
77
|
+
if (patchOptions.isHydration) {
|
|
78
|
+
clearDelayedWorklets();
|
|
79
|
+
}
|
|
80
|
+
markTiming(PerformanceTimingKeys.patch_changes_end);
|
|
81
|
+
flushOptions ||= {};
|
|
82
|
+
if (patchOptions.pipelineOptions) {
|
|
83
|
+
flushOptions.pipelineOptions = patchOptions.pipelineOptions;
|
|
84
|
+
}
|
|
85
|
+
// TODO: triggerDataUpdated?
|
|
86
|
+
__FlushElementTree(__page, flushOptions);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Object.assign(globalThis, { [LifecycleConstant.patchUpdate]: updatePatch });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function replaceCommitHook(): void {
|
|
93
|
+
const oldCommit = options[COMMIT];
|
|
94
|
+
options[COMMIT] = async (vnode: VNode, commitQueue: any[]) => {
|
|
95
|
+
if (__LEPUS__) {
|
|
96
|
+
// for testing only
|
|
97
|
+
commitQueue.length = 0;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
markTimingLegacy(PerformanceTimingKeys.update_diff_vdom_end);
|
|
102
|
+
markTiming(PerformanceTimingKeys.diff_vdom_end);
|
|
103
|
+
markTiming(PerformanceTimingKeys.pack_changes_start);
|
|
104
|
+
if (__PROFILE__) {
|
|
105
|
+
console.profile('commitChanges');
|
|
106
|
+
}
|
|
107
|
+
const renderCallbacks = commitQueue.map(component => {
|
|
108
|
+
const ret = {
|
|
109
|
+
component,
|
|
110
|
+
[RENDER_CALLBACKS]: component[RENDER_CALLBACKS],
|
|
111
|
+
[VNODE]: component[VNODE],
|
|
112
|
+
};
|
|
113
|
+
component[RENDER_CALLBACKS] = [];
|
|
114
|
+
return ret;
|
|
115
|
+
});
|
|
116
|
+
commitQueue.length = 0;
|
|
117
|
+
const delayedUnmounts = takeDelayedUnmounts();
|
|
118
|
+
|
|
119
|
+
const backgroundSnapshotInstancesToRemove = globalBackgroundSnapshotInstancesToRemove;
|
|
120
|
+
globalBackgroundSnapshotInstancesToRemove = [];
|
|
121
|
+
|
|
122
|
+
const commitTaskId = genCommitTaskId();
|
|
123
|
+
globalCommitTaskMap.set(commitTaskId, () => {
|
|
124
|
+
updateBackgroundRefs(commitTaskId);
|
|
125
|
+
runDelayedUnmounts(delayedUnmounts);
|
|
126
|
+
oldCommit?.(vnode, renderCallbacks);
|
|
127
|
+
renderCallbacks.some(wrapper => {
|
|
128
|
+
try {
|
|
129
|
+
wrapper[RENDER_CALLBACKS].some((cb: (this: Component) => void) => {
|
|
130
|
+
cb.call(wrapper.component);
|
|
131
|
+
});
|
|
132
|
+
} catch (e) {
|
|
133
|
+
options[CATCH_ERROR](e, wrapper[VNODE]);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (backgroundSnapshotInstancesToRemove.length) {
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
backgroundSnapshotInstancesToRemove.forEach(id => {
|
|
139
|
+
backgroundSnapshotInstanceManager.values.delete(id);
|
|
140
|
+
});
|
|
141
|
+
}, 10000);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const snapshotPatch = takeGlobalSnapshotPatch();
|
|
146
|
+
const flushOptions = globalFlushOptions;
|
|
147
|
+
const workletRefInitValuePatch = takeWorkletRefInitValuePatch();
|
|
148
|
+
globalFlushOptions = {};
|
|
149
|
+
if (!snapshotPatch && workletRefInitValuePatch.length === 0) {
|
|
150
|
+
// before hydration, skip patch
|
|
151
|
+
if (__PROFILE__) {
|
|
152
|
+
console.profileEnd();
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const patch: Patch = {};
|
|
158
|
+
// TODO: check all fields in `flushOptions` from runtime3
|
|
159
|
+
if (snapshotPatch?.length) {
|
|
160
|
+
patch.snapshotPatch = snapshotPatch;
|
|
161
|
+
}
|
|
162
|
+
if (!isEmptyObject(flushOptions)) {
|
|
163
|
+
patch.flushOptions = flushOptions;
|
|
164
|
+
}
|
|
165
|
+
if (workletRefInitValuePatch.length) {
|
|
166
|
+
patch.workletRefInitValuePatch = workletRefInitValuePatch;
|
|
167
|
+
}
|
|
168
|
+
await commitPatchUpdate(patch, { commitTaskId });
|
|
169
|
+
|
|
170
|
+
const commitTask = globalCommitTaskMap.get(commitTaskId);
|
|
171
|
+
if (commitTask) {
|
|
172
|
+
commitTask();
|
|
173
|
+
globalCommitTaskMap.delete(commitTaskId);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function commitPatchUpdate(data: Patch, patchOptions: PatchOptions): Promise<void> {
|
|
179
|
+
return new Promise(resolve => {
|
|
180
|
+
// console.debug('********** JS update:');
|
|
181
|
+
// printSnapshotInstance(
|
|
182
|
+
// (backgroundSnapshotInstanceManager.values.get(1) || backgroundSnapshotInstanceManager.values.get(-1))!,
|
|
183
|
+
// );
|
|
184
|
+
// console.debug('commitPatchUpdate: ', JSON.stringify(data));
|
|
185
|
+
const obj: {
|
|
186
|
+
data: string;
|
|
187
|
+
patchOptions: PatchOptions;
|
|
188
|
+
} = {
|
|
189
|
+
data: JSON.stringify(data),
|
|
190
|
+
patchOptions: {
|
|
191
|
+
...patchOptions,
|
|
192
|
+
reloadVersion: getReloadVersion(),
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
markTiming(PerformanceTimingKeys.pack_changes_end);
|
|
196
|
+
if (globalPipelineOptions) {
|
|
197
|
+
obj.patchOptions.pipelineOptions = globalPipelineOptions;
|
|
198
|
+
setPipeline(undefined);
|
|
199
|
+
}
|
|
200
|
+
if (__PROFILE__) {
|
|
201
|
+
console.profileEnd();
|
|
202
|
+
}
|
|
203
|
+
lynx.getNativeApp().callLepusMethod(LifecycleConstant.patchUpdate, obj, resolve);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function commitMainThreadPatchUpdate(commitTaskId?: number): void {
|
|
208
|
+
const refPatch = takeGlobalRefPatchMap();
|
|
209
|
+
if (!isEmptyObject(refPatch)) {
|
|
210
|
+
__OnLifecycleEvent([LifecycleConstant.ref, { commitTaskId, refPatch: JSON.stringify(refPatch) }]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function genCommitTaskId(): number {
|
|
215
|
+
return nextCommitTaskId++;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function replaceRequestAnimationFrame(): void {
|
|
219
|
+
// to make afterPaintEffects run faster
|
|
220
|
+
const resolvedPromise = Promise.resolve();
|
|
221
|
+
options.requestAnimationFrame = (cb: () => void) => {
|
|
222
|
+
resolvedPromise.then(cb);
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @internal
|
|
228
|
+
*/
|
|
229
|
+
export {
|
|
230
|
+
injectUpdatePatch,
|
|
231
|
+
commitPatchUpdate,
|
|
232
|
+
replaceCommitHook,
|
|
233
|
+
genCommitTaskId,
|
|
234
|
+
commitMainThreadPatchUpdate,
|
|
235
|
+
replaceRequestAnimationFrame,
|
|
236
|
+
globalFlushOptions,
|
|
237
|
+
globalCommitTaskMap,
|
|
238
|
+
globalBackgroundSnapshotInstancesToRemove,
|
|
239
|
+
nextCommitTaskId,
|
|
240
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { render } from 'preact';
|
|
5
|
+
|
|
6
|
+
import { __root, setRoot } from '../root.js';
|
|
7
|
+
import { SnapshotInstance, __page, snapshotInstanceManager } from '../snapshot.js';
|
|
8
|
+
import { isEmptyObject } from '../utils.js';
|
|
9
|
+
import { destroyBackground } from './destroy.js';
|
|
10
|
+
import { increaseReloadVersion } from './pass.js';
|
|
11
|
+
import { renderMainThread } from './render.js';
|
|
12
|
+
import { hydrate } from '../hydrate.js';
|
|
13
|
+
import { LifecycleConstant } from '../lifecycleConstant.js';
|
|
14
|
+
import { __pendingListUpdates } from '../list.js';
|
|
15
|
+
import { takeGlobalRefPatchMap } from '../snapshot/ref.js';
|
|
16
|
+
import { deinitGlobalSnapshotPatch } from '../snapshotPatch.js';
|
|
17
|
+
|
|
18
|
+
function reloadMainThread(data: any, options: UpdatePageOption): void {
|
|
19
|
+
if (__PROFILE__) {
|
|
20
|
+
console.profile('reloadTemplate');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
increaseReloadVersion();
|
|
24
|
+
|
|
25
|
+
if (typeof data == 'object' && !isEmptyObject(data)) {
|
|
26
|
+
Object.assign(lynx.__initData, data);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
snapshotInstanceManager.clear();
|
|
30
|
+
__pendingListUpdates.clear();
|
|
31
|
+
|
|
32
|
+
const oldRoot = __root;
|
|
33
|
+
setRoot(new SnapshotInstance('root'));
|
|
34
|
+
__root.__jsx = oldRoot.__jsx;
|
|
35
|
+
renderMainThread();
|
|
36
|
+
hydrate(oldRoot as SnapshotInstance, __root as SnapshotInstance, {
|
|
37
|
+
skipUnRef: true,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// always call this before `__FlushElementTree`
|
|
41
|
+
__pendingListUpdates.flush();
|
|
42
|
+
__FlushElementTree(__page, options);
|
|
43
|
+
|
|
44
|
+
__OnLifecycleEvent([
|
|
45
|
+
LifecycleConstant.firstScreen, /* FIRST_SCREEN */
|
|
46
|
+
{
|
|
47
|
+
root: JSON.stringify(__root),
|
|
48
|
+
refPatch: JSON.stringify(takeGlobalRefPatchMap()),
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
if (__PROFILE__) {
|
|
53
|
+
console.profileEnd();
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function reloadBackground(updateData: Record<string, any>): void {
|
|
59
|
+
if (__PROFILE__) {
|
|
60
|
+
console.profile('reload');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
deinitGlobalSnapshotPatch();
|
|
64
|
+
|
|
65
|
+
destroyBackground();
|
|
66
|
+
|
|
67
|
+
increaseReloadVersion();
|
|
68
|
+
|
|
69
|
+
// COW when modify `lynx.__initData` to make sure Provider & Consumer works
|
|
70
|
+
lynx.__initData = Object.assign({}, lynx.__initData, updateData);
|
|
71
|
+
|
|
72
|
+
render(__root.__jsx, __root as any);
|
|
73
|
+
|
|
74
|
+
if (__PROFILE__) {
|
|
75
|
+
console.profileEnd();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { reloadMainThread, reloadBackground };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { render } from 'preact';
|
|
5
|
+
|
|
6
|
+
import { renderOpcodesInto } from '../opcodes.js';
|
|
7
|
+
import { render as renderToString } from '../renderToOpcodes/index.js';
|
|
8
|
+
import { __root } from '../root.js';
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
|
|
11
|
+
function renderMainThread(): void {
|
|
12
|
+
/* v8 ignore start */
|
|
13
|
+
if (
|
|
14
|
+
process.env['NODE_ENV'] === 'test' && typeof __TESTING_FORCE_RENDER_TO_OPCODE__ !== 'undefined'
|
|
15
|
+
&& !__TESTING_FORCE_RENDER_TO_OPCODE__
|
|
16
|
+
) {
|
|
17
|
+
render(__root.__jsx, __root as any);
|
|
18
|
+
} else {
|
|
19
|
+
let opcodes;
|
|
20
|
+
try {
|
|
21
|
+
if (__PROFILE__) {
|
|
22
|
+
console.profile('renderToString');
|
|
23
|
+
}
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
opcodes = renderToString(__root.__jsx);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
lynx.reportError(e);
|
|
28
|
+
opcodes = [];
|
|
29
|
+
} finally {
|
|
30
|
+
if (__PROFILE__) {
|
|
31
|
+
console.profileEnd();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (__PROFILE__) {
|
|
36
|
+
console.profile('renderOpcodesInto');
|
|
37
|
+
}
|
|
38
|
+
renderOpcodesInto(opcodes, __root as any);
|
|
39
|
+
if (__PROFILE__) {
|
|
40
|
+
console.profileEnd();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/* v8 ignore stop */
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { renderMainThread };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
export class LifecycleConstant {
|
|
5
|
+
public static readonly firstScreen = 'rLynxFirstScreen';
|
|
6
|
+
public static readonly updateFromRoot = 'updateFromRoot';
|
|
7
|
+
public static readonly globalEventFromLepus = 'globalEventFromLepus';
|
|
8
|
+
public static readonly ref = 'rLynxRef';
|
|
9
|
+
public static readonly jsReady = 'rLynxJSReady';
|
|
10
|
+
public static readonly patchUpdate = 'rLynxChange';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const enum NativeUpdateDataType {
|
|
14
|
+
UPDATE = 0,
|
|
15
|
+
RESET = 1,
|
|
16
|
+
}
|