Skip to content

Commit b1f6014

Browse files
committed
Use original properties passed to the widget when creating the instruction for an invalidation
1 parent 5a9e35e commit b1f6014

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/widget-core/WidgetBase.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> implement
118118
this.destroy();
119119
},
120120
nodeHandler: this._nodeHandler,
121-
rendering: false
121+
rendering: false,
122+
inputProperties: {}
122123
});
123124

124125
this.own({
@@ -167,6 +168,8 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> implement
167168
}
168169

169170
public __setProperties__(originalProperties: this['properties'], bind?: WidgetBaseInterface): void {
171+
const instanceData = widgetInstanceMap.get(this)!;
172+
instanceData.inputProperties = originalProperties;
170173
const properties = this._runBeforeProperties(originalProperties);
171174
const registeredDiffPropertyNames = this.getDecorator('registeredDiffProperty');
172175
const changedPropertyKeys: string[] = [];

src/widget-core/vdom.ts

+23-16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface WidgetData {
2626
nodeHandler: NodeHandler;
2727
invalidate?: Function;
2828
rendering: boolean;
29+
inputProperties: any;
2930
}
3031

3132
export interface BaseNodeWrapper {
@@ -752,7 +753,7 @@ export class Renderer {
752753
let item: InvalidationQueueItem | undefined;
753754
while ((item = invalidationQueue.pop())) {
754755
let { current, next } = item;
755-
if (previouslyRendered.indexOf(next.instance) === -1) {
756+
if (previouslyRendered.indexOf(next.instance) === -1 && this._instanceToWrapperMap.has(next.instance!)) {
756757
previouslyRendered.push(next.instance);
757758
const sibling = this._wrapperSiblingMap.get(current);
758759
sibling && this._wrapperSiblingMap.set(next, sibling);
@@ -854,21 +855,24 @@ export class Renderer {
854855
}
855856

856857
private _queueInvalidation(instance: WidgetBase): void {
857-
const current = this._instanceToWrapperMap.get(instance)!;
858-
const next = {
859-
node: {
860-
type: WNODE,
861-
widgetConstructor: instance.constructor as WidgetBaseConstructor,
862-
properties: instance.properties,
863-
children: instance.children
864-
},
865-
instance,
866-
depth: current.depth
867-
};
858+
const current = this._instanceToWrapperMap.get(instance);
859+
if (current) {
860+
const instanceData = widgetInstanceMap.get(instance)!;
861+
const next = {
862+
node: {
863+
type: WNODE,
864+
widgetConstructor: instance.constructor as WidgetBaseConstructor,
865+
properties: instanceData.inputProperties,
866+
children: instance.children
867+
},
868+
instance,
869+
depth: current.depth
870+
};
868871

869-
const parent = this._parentWrapperMap.get(current)!;
870-
this._parentWrapperMap.set(next, parent);
871-
this._invalidationQueue.push({ current, next });
872+
const parent = this._parentWrapperMap.get(current)!;
873+
this._parentWrapperMap.set(next, parent);
874+
this._invalidationQueue.push({ current, next });
875+
}
872876
}
873877

874878
private _queueInRender(item: RenderQueueItem) {
@@ -1032,7 +1036,10 @@ export class Renderer {
10321036

10331037
private _updateWidget({ current, next }: UpdateWidgetInstruction): ProcessResult {
10341038
const { instance, domNode, hasAnimations } = current;
1035-
const instanceData = widgetInstanceMap.get(instance!)!;
1039+
if (!instance) {
1040+
return [] as ProcessResult;
1041+
}
1042+
const instanceData = widgetInstanceMap.get(instance)!;
10361043
next.instance = instance;
10371044
next.domNode = domNode;
10381045
next.hasAnimations = hasAnimations;

0 commit comments

Comments
 (0)