Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the useOn hook not working with Slot #7250

Merged
merged 24 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/qwik/src/core/client/vnode-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type Props,
} from '../shared/jsx/jsx-runtime';
import { Slot } from '../shared/jsx/slot.public';
import type { JSXNodeInternal, JSXOutput } from '../shared/jsx/types/jsx-node';
import type { JSXNode, JSXNodeInternal, JSXOutput } from '../shared/jsx/types/jsx-node';
import type { JSXChildren } from '../shared/jsx/types/jsx-qwik-attributes';
import { SSRComment, SSRRaw, SkipRender } from '../shared/jsx/utils.public';
import { trackSignalAndAssignHost } from '../use/use-core';
Expand Down Expand Up @@ -228,6 +228,9 @@ export const vnode_diff = (
// nothing to project, so try to render the Slot default content.
descend(jsxValue.children, true);
}
if ((jsxValue.children as JSXNode)?.type === 'script') {
descend(jsxValue.children, true);
}
} else if (type === Projection) {
expectProjection();
descend(jsxValue.children, true);
Expand Down Expand Up @@ -500,6 +503,7 @@ export const vnode_diff = (
(vNewNode = vnode_newVirtual()),
vCurrent && getInsertBefore()
);

vnode_setProp(vNewNode, QSlot, slotNameKey);
vHost && vnode_setProp(vHost, slotNameKey, vNewNode);
isDev && vnode_setProp(vNewNode, DEBUG_TYPE, VirtualType.Projection);
Expand Down
9 changes: 7 additions & 2 deletions packages/qwik/src/core/ssr/ssr-render-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,18 @@ function processJSXNode(
const node = ssr.getLastNode();
const slotName = getSlotName(host, jsx, ssr);
projectionAttrs.push(QSlot, slotName);

enqueue(new ParentComponentData(options.styleScoped, options.parentComponentFrame));
enqueue(ssr.closeProjection);
const slotDefaultChildren: JSXChildren | null = jsx.children || null;
const slotChildren =
componentFrame.consumeChildrenForSlot(node, slotName) || slotDefaultChildren;
if (slotDefaultChildren && slotChildren !== slotDefaultChildren) {
if ((slotDefaultChildren as JSXNodeInternal)?.type === 'script') {
enqueue(slotDefaultChildren as JSXOutput);
} else if (slotDefaultChildren && slotChildren !== slotDefaultChildren) {
ssr.addUnclaimedProjection(componentFrame, QDefaultSlot, slotDefaultChildren);
}
// enqueue(slotDefaultChildren as JSXOutput);
enqueue(slotChildren as JSXOutput);
enqueue(
new ParentComponentData(
Expand Down Expand Up @@ -300,7 +304,8 @@ function processJSXNode(
options.styleScoped,
options.parentComponentFrame
);
const jsxOutput = applyQwikComponentBody(ssr, jsx, type);

const jsxOutput: any = applyQwikComponentBody(ssr, jsx, type);
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
const compStyleComponentId = addComponentStylePrefix(host.getProp(QScopedStyle));
enqueue(new ParentComponentData(options.styleScoped, options.parentComponentFrame));
enqueue(ssr.closeComponent);
Expand Down
21 changes: 21 additions & 0 deletions packages/qwik/src/core/tests/use-on.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
component$,
Fragment,
Fragment as Signal,
Slot,
useOn,
useOnDocument,
useOnWindow,
Expand Down Expand Up @@ -647,4 +648,24 @@ describe.each([
await trigger(document.body, 'div', 'click');
await expect(document.querySelector('div')).toMatchDOM(<div>1</div>);
});
it('useOnDocument1111', async () => {
const BreakpointProvider = component$(() => {
useOnDocument(
'click',
$(async () => {})
);

return <Slot />;
});

const Layout = component$(() => {
return (
<BreakpointProvider>
<div>test</div>
</BreakpointProvider>
);
});
const { document } = await render(<Layout />, { debug });
await expect(document.querySelector('script')).toBeTruthy();
});
});
Loading