Skip to content

Commit

Permalink
fix: reorder children issue (QwikDev#3732)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored Apr 9, 2023
1 parent d243294 commit 9f0fa41
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/qwik/src/core/render/dom/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,9 @@ export const directInsertAfter = (
ref: Node | VirtualElement | null
) => {
if (isVirtualElement(child)) {
child.insertBeforeTo(parent, getRootNode(ref)?.nextSibling);
child.insertBeforeTo(parent, ref?.nextSibling ?? null);
} else {
parent.insertBefore(child, getRootNode(ref)?.nextSibling);
parent.insertBefore(child, ref?.nextSibling ?? null);
}
};

Expand Down
37 changes: 37 additions & 0 deletions starters/apps/e2e/src/components/render/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const RenderChildren = component$(() => {
<Issue3542 atom={{ code: 1 }} />
<Issue3643 />
<IssueChildrenSpread />
<Issue3731 />
</>
);
});
Expand Down Expand Up @@ -659,3 +660,39 @@ export const IssueChildrenSpread = component$(() => {
</div>
);
});

const states = [
['think', 'containers', 'hydrating', 'usestylesscoped', 'slots'],
['think', 'containers', 'cleanup', 'usevisibletask', 'hydrating'],
['cleanup', 'usevisibletask', 'think', 'containers', 'slots'],
];

export const Issue3731 = component$(() => {
const state = useSignal(0);
const signal = useSignal(states[0]);
return (
<div>
<button
id="issue-3731-button"
onClick$={() => {
state.value++;
if (state.value > states.length - 1) {
state.value = 0;
}
signal.value = states[state.value];
}}
>
Change
</button>
<ul>
{signal.value.map((item) => {
return <Issue3731Child key={item} value={item}></Issue3731Child>;
})}
</ul>
</div>
);
});

export const Issue3731Child = component$((props: any) => {
return <div class="issue-3731-result">{props.value}</div>;
});
28 changes: 28 additions & 0 deletions starters/e2e/e2e.render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,34 @@ test.describe('render', () => {
await button.click();
await expect(result).toHaveText('Changed');
});

test('issue3731', async ({ page }) => {
const button = page.locator('#issue-3731-button');
const results = page.locator('.issue-3731-result');
await expect(results).toHaveText([
'think',
'containers',
'hydrating',
'usestylesscoped',
'slots',
]);
await button.click();
await expect(results).toHaveText([
'think',
'containers',
'cleanup',
'usevisibletask',
'hydrating',
]);
await button.click();
await expect(results).toHaveText([
'cleanup',
'usevisibletask',
'think',
'containers',
'slots',
]);
});
}

tests();
Expand Down

0 comments on commit 9f0fa41

Please sign in to comment.