Skip to content

Commit dc18d85

Browse files
committed
Fix VDOM Lifecycle and Update Collision Logic #7711
1 parent 80863fe commit dc18d85

4 files changed

Lines changed: 26 additions & 24 deletions

File tree

src/mixin/VdomLifecycle.mjs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class VdomLifecycle extends Base {
146146
* @protected
147147
*/
148148
afterSetVnode(value, oldValue) {
149-
oldValue !== undefined && this.syncVnodeTree()
149+
value && this.syncVnodeTree()
150150
}
151151

152152
/**
@@ -156,9 +156,7 @@ class VdomLifecycle extends Base {
156156
* @protected
157157
*/
158158
afterSetVnodeInitialized(value, oldValue) {
159-
if (value === true) {
160-
this.fire('vnodeInitialized', this.id)
161-
}
159+
value && this.fire('vnodeInitialized', this.id)
162160
}
163161

164162
/**
@@ -324,7 +322,7 @@ class VdomLifecycle extends Base {
324322
* @returns {Boolean}
325323
*/
326324
hasUpdateCollision(updateDepth, distance) {
327-
return updateDepth === -1 ? true : distance <= updateDepth
325+
return updateDepth === -1 ? true : distance < updateDepth
328326
}
329327

330328
/**
@@ -625,7 +623,7 @@ class VdomLifecycle extends Base {
625623
let me = this,
626624
{mounted, parentId, vnode} = me;
627625

628-
if (me.isVdomUpdating || me.silentVdomUpdate) {
626+
if (me.isVdomUpdating || !me.vnodeInitialized || me.silentVdomUpdate) {
629627
resolve && VDomUpdate.addPromiseCallback(me.id, resolve);
630628
me.needsVdomUpdate = true
631629
} else {
@@ -675,6 +673,4 @@ class VdomLifecycle extends Base {
675673
}
676674
}
677675

678-
Neo.setupClass(VdomLifecycle);
679-
680-
export default VdomLifecycle;
676+
export default Neo.setupClass(VdomLifecycle);

test/playwright/component/component/Base.spec.mjs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ test.describe('Neo.component.Base', () => {
6767
expect(containerId).toBe('neo-container-1');
6868

6969
await page.waitForSelector('.neo-container');
70-
// t.diag('Container got rendered.');
70+
71+
const initialContainerBgColor = await page.locator(`#${containerId}`).evaluate(el => el.style.backgroundColor);
72+
73+
expect(initialContainerBgColor).toBe('red');
7174

7275
const componentResult = await page.evaluate(async (containerId) => {
7376
return Neo.worker.App.createNeoInstance({
@@ -86,15 +89,16 @@ test.describe('Neo.component.Base', () => {
8689
componentId = componentResult.id;
8790

8891
expect(componentId).toBe('neo-component-1');
89-
// t.diag('Component got rendered.');
92+
93+
const initialComponentBgColor = await page.locator(`#${componentId}`).evaluate(el => el.style.backgroundColor);
94+
95+
expect(initialComponentBgColor).toBe('blue');
9096

9197
// t.diag('Child update before parent update');
92-
await page.evaluate(async (id) => {
93-
await Neo.worker.App.setConfigs({id, style: {backgroundColor: 'green'}});
94-
}, componentId);
95-
await page.evaluate(async (id) => {
96-
await Neo.worker.App.setConfigs({id, style: {backgroundColor: 'orange'}});
97-
}, containerId);
98+
await page.evaluate(async ({componentId, containerId}) => {
99+
Neo.worker.App.setConfigs({id: componentId, style: {backgroundColor: 'green'}});
100+
Neo.worker.App.setConfigs({id: containerId, style: {backgroundColor: 'orange'}});
101+
}, {componentId, containerId});
98102

99103
await page.waitForTimeout(100);
100104

test/playwright/component/component/Image.spec.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ test.describe('Neo.component.Image', () => {
4747
test('should update src and alt attributes on config change', async ({page}) => {
4848
const image = page.locator(`#${componentId}`);
4949

50+
await expect(image).toHaveAttribute('src', SRC);
51+
await expect(image).toHaveAttribute('alt', ALT);
52+
5053
const NEW_SRC = '../../../../../resources/images/logo/neo_logo_favicon.svg',
5154
NEW_ALT = 'neo.mjs favicon';
5255

test/playwright/unit/vdom/AsymmetricUpdates.spec.mjs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ test.describe('Neo.vdom.VdomAsymmetricUpdates', () => {
195195
});
196196

197197
test('Should not detect a collision if updateDepth is insufficient', () => {
198-
const grandchildVdom = { id: 'grandchild-1', text: 'grandchild' };
199-
const childVdom = { id: 'child-1', cn: [{ componentId: 'grandchild-1' }] };
200-
const parentVdom = { id: 'parent-1', cn: [{ componentId: 'child-1' }] };
198+
const grandchildVdom = {id: 'grandchild-1', text: 'grandchild'};
199+
const childVdom = {id: 'child-1', cn: [{componentId: 'grandchild-1'}]};
200+
const parentVdom = {id: 'parent-1', cn: [{componentId: 'child-1'}]};
201201

202202
let grandchild = createMockComponent('grandchild-1', 'child-1', grandchildVdom);
203203
createMockComponent('child-1', 'parent-1', childVdom);
@@ -260,10 +260,9 @@ test.describe('Neo.vdom.VdomAsymmetricUpdates', () => {
260260
expect(deltas.length).toBe(2);
261261

262262
const gcSpanVnode = oldAsymmetricVnode.childNodes[0].childNodes[0].childNodes[0];
263-
const c3Vnode = oldAsymmetricVnode.childNodes[2];
264-
265-
const delta1 = deltas.find(d => d.id === gcSpanVnode.id);
266-
const delta2 = deltas.find(d => d.id === c3Vnode.id);
263+
const c3Vnode = oldAsymmetricVnode.childNodes[2];
264+
const delta1 = deltas.find(d => d.id === gcSpanVnode.id);
265+
const delta2 = deltas.find(d => d.id === c3Vnode.id);
267266

268267
expect(delta1).toBeTruthy();
269268
expect(delta1.textContent).toBe('Updated GC');

0 commit comments

Comments
 (0)