Skip to content

Commit

Permalink
fix store serialization and resource tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Aug 19, 2024
1 parent 19be81b commit 3260bd7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/qwik/src/core/use/use-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ function getResourceValueAsPromise<T>(props: ResourceProps<T>): Promise<JSXOutpu
const resource = props.value as ResourceReturnInternal<T> | Promise<T> | Signal<T>;
if (isResourceReturn(resource)) {
const isBrowser = !isServerPlatform();
// create a subscription for the resource._state changes
const state = resource._state;
if (isBrowser) {
// create a subscription for the resource._state changes
const state = resource._state;
DEBUG && debugLog(`RESOURCE_CMP.${state}`, 'VALUE: ' + untrack(() => resource._resolved));

if (state === 'pending' && props.onPending) {
Expand Down
6 changes: 3 additions & 3 deletions packages/qwik/src/core/v2/shared/shared-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,7 @@ export const createSerializationContext = (
// For root objects we pretend we have not seen them to force scan.
const id = $wasSeen$(obj);
const unwrapObj = unwrapStore2(obj);
if (unwrapObj !== obj) {
discoveredValues.push(unwrapObj);
} else if (id === undefined || isRoot) {
if (id === undefined || isRoot) {
// Object has not been seen yet, must scan content
// But not for root.
!isRoot && $seen$(obj);
Expand All @@ -724,6 +722,8 @@ export const createSerializationContext = (
// skip as these are primitives
} else if (fastSkipSerialize(obj as object)) {
// Ignore the no serialize objects
} else if (unwrapObj !== obj) {
discoveredValues.push(unwrapObj);
} else if (obj instanceof Set) {
const contents = Array.from(obj.values());
setSerializableDataRootId($addRoot$, obj, contents);
Expand Down
47 changes: 47 additions & 0 deletions packages/qwik/src/core/v2/tests/use-resource.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,51 @@ describe.each([
</Component>
);
});

it('should render component on resolved', async () => {
const MyButton = component$(() => {
return <div></div>;
});

const Cmp = component$(() => {
const text = useSignal('');

const textResource = useResource$(async (ctx) => {
return ctx.track(() => text.value);
});

return (
<>
<Resource
value={textResource}
onResolved={() => (
<>
<MyButton />
</>
)}
/>
</>
);
});

const { vNode } = await render(<Cmp />, { debug });

expect(vNode).toMatchVDOM(
<Component>
<Fragment>
<InlineComponent>
<Fragment>
<Awaited>
<Fragment>
<Component>
<div></div>
</Component>
</Fragment>
</Awaited>
</Fragment>
</InlineComponent>
</Fragment>
</Component>
);
});
});

0 comments on commit 3260bd7

Please sign in to comment.