Skip to content

Commit

Permalink
fix: find correct context after rendering empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Jan 9, 2025
1 parent d6c274e commit 0922571
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/purple-melons-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qwik.dev/core': patch
---

fix: find correct context after rendering empty array
53 changes: 53 additions & 0 deletions packages/qwik/src/core/tests/use-context.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,59 @@ describe.each([
);
});

it('should add slot information for empty array', async () => {
const qErrorSpy = vi.spyOn(qError, 'qError');
const contextId = createContextId('contextId');

const ContextProducer = component$(() => {
const context = {
disabled: false,
};
useContextProvider(contextId, context);
return <Slot />;
});

const ProducerParent = component$(() => {
return (
<ContextProducer>
<Slot />
</ContextProducer>
);
});

const ContextConsumer = component$(() => {
useContext(contextId);
return <Slot />;
});

const Parent = component$(() => {
const array = useSignal<string[]>([]);
return (
<>
<ProducerParent>
{array.value.map((_, index) => (
<ContextConsumer key={index} />
))}
</ProducerParent>
<button onClick$={() => (array.value = ['test'])}></button>
</>
);
});

try {
const { document } = await render(
<ErrorProvider>
<Parent />
</ErrorProvider>,
{ debug }
);
await trigger(document.body, 'button', 'click');
expect(qErrorSpy).not.toHaveBeenCalled();
} catch (e) {
expect(qErrorSpy).not.toHaveBeenCalled();
}
});

it('should find context parent from Slot inside Slot', async () => {
const qErrorSpy = vi.spyOn(qError, 'qError');
const contextId = createContextId('contextId');
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/server/ssr-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class SsrComponentFrame implements ISsrComponentFrame {
defaultSlot.push(child);
}
}
defaultSlot.length && mapArray_set(this.slots, QDefaultSlot, defaultSlot, 0);
mapArray_set(this.slots, QDefaultSlot, defaultSlot, 0);
} else {
mapArray_set(this.slots, QDefaultSlot, children, 0);
}
Expand Down

0 comments on commit 0922571

Please sign in to comment.