修复builderNode在状态管理V2场景下的更新异常

Signed-off-by: wangchensu <wangchensu@huawei.com>
Change-Id: Ic58736bfffdeebbe39fc130dc0696b197141e396
This commit is contained in:
wangchensu 2024-08-10 19:14:12 +08:00
parent a2988e9674
commit e39aa06923
3 changed files with 33 additions and 0 deletions

View File

@ -272,6 +272,14 @@ class JSBuilderNode extends BaseNode {
const updateFunc = (elmtId: number, isFirstRender: boolean): void => {
__JSScopeUtil__.syncInstanceId(this.instanceId_);
ViewStackProcessor.StartGetAccessRecordingFor(elmtId);
// if V2 @Observed/@Track used anywhere in the app (there is no more fine grained criteria),
// enable V2 object deep observation
// FIXME: A @Component should only use PU or V2 state, but ReactNative dynamic viewer uses both.
if (ConfigureStateMgmt.instance.needsV2Observe()) {
// FIXME: like in V2 setting bindId_ in ObserveV2 does not work with 'stacked'
// update + initial render calls, like in if and ForEach case, convert to stack as well
ObserveV2.getObserve().startRecordDependencies(this, elmtId, true);
}
if (this._supportNestingBuilder) {
compilerAssignedUpdateFunc(elmtId, isFirstRender);
} else {
@ -280,6 +288,9 @@ class JSBuilderNode extends BaseNode {
if (!isFirstRender) {
_popFunc();
}
if (ConfigureStateMgmt.instance.needsV2Observe()) {
ObserveV2.getObserve().stopRecordDependencies();
}
ViewStackProcessor.StopGetAccessRecording();
__JSScopeUtil__.restoreInstanceId();
};

View File

@ -30,6 +30,17 @@ interface UpdateFuncRecord {
node?: object;
}
declare class ObserveV2 {
static getObserve(): ObserveV2;
public stopRecordDependencies(): void;
public startRecordDependencies(cmp: BaseNode, id: number, doClearBinding: boolean): void;
}
declare class ConfigureStateMgmt {
public static get instance(): ConfigureStateMgmt;
public needsV2Observe(): boolean;
}
declare function wrapBuilder<Args extends Object[]>(
builder: (...args: Args) => void
): WrappedBuilder<Args>;

View File

@ -291,6 +291,14 @@ class JSBuilderNode extends BaseNode {
const updateFunc = (elmtId, isFirstRender) => {
__JSScopeUtil__.syncInstanceId(this.instanceId_);
ViewStackProcessor.StartGetAccessRecordingFor(elmtId);
// if V2 @Observed/@Track used anywhere in the app (there is no more fine grained criteria),
// enable V2 object deep observation
// FIXME: A @Component should only use PU or V2 state, but ReactNative dynamic viewer uses both.
if (ConfigureStateMgmt.instance.needsV2Observe()) {
// FIXME: like in V2 setting bindId_ in ObserveV2 does not work with 'stacked'
// update + initial render calls, like in if and ForEach case, convert to stack as well
ObserveV2.getObserve().startRecordDependencies(this, elmtId, true);
}
if (this._supportNestingBuilder) {
compilerAssignedUpdateFunc(elmtId, isFirstRender);
}
@ -300,6 +308,9 @@ class JSBuilderNode extends BaseNode {
if (!isFirstRender) {
_popFunc();
}
if (ConfigureStateMgmt.instance.needsV2Observe()) {
ObserveV2.getObserve().stopRecordDependencies();
}
ViewStackProcessor.StopGetAccessRecording();
__JSScopeUtil__.restoreInstanceId();
};