Skip to content

Commit 4ece820

Browse files
authored
fix(runtime): use block instead of stale b_block in reconcile_by_key Map path (#790)
1 parent d630bc8 commit 4ece820

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/ripple/src/runtime/internal/client/for.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ function reconcile_by_key(anchor, block, b, render_fn, is_controlled, is_indexed
450450
if (is_indexed) {
451451
update_index(block, j);
452452
}
453-
update_value(b_block, b_val);
453+
update_value(block, b_val);
454454
++patched;
455455
} else if (!fast_path_removal) {
456456
destroy_block(a_blocks[i]);

packages/ripple/tests/client/for.test.ripple

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,39 @@ describe('for statements', () => {
173173
expect(container.querySelectorAll('.item').length).toBe(2);
174174
});
175175

176+
it('keyed for with 32+ items: full reversal updates values via Map path', () => {
177+
component App() {
178+
let items = track(Array.from({ length: 40 }, (_, i) => ({ id: i, text: `Item ${i}` })));
179+
180+
<div>
181+
for (let item of @items; index idx; key item.id) {
182+
<span class="item">{idx + ':' + item.text}</span>
183+
}
184+
</div>
185+
186+
<button
187+
onClick={() => {
188+
@items = @items.toReversed();
189+
}}
190+
>
191+
{'Reverse'}
192+
</button>
193+
}
194+
195+
render(App);
196+
197+
const getTexts = () => Array.from(container.querySelectorAll('.item')).map(
198+
(el) => el.textContent,
199+
);
200+
201+
expect(getTexts()).toEqual(Array.from({ length: 40 }, (_, i) => `${i}:Item ${i}`));
202+
203+
container.querySelector('button').click();
204+
flushSync();
205+
206+
expect(getTexts()).toEqual(Array.from({ length: 40 }, (_, i) => `${i}:Item ${39 - i}`));
207+
});
208+
176209
it('handles updating with new objects with same key', () => {
177210
component App() {
178211
let items = track([

0 commit comments

Comments
 (0)