Skip to content

Commit

Permalink
fix(package/solid): Prevents Suspense leaking (#2006)
Browse files Browse the repository at this point in the history
* chore(examples/solid): avoid props destructuring in solid

https://discord.com/channels/722131463138705510/1268525091759722537/1277109914354847795

* fix(package/solid): added more tests and enhanced suspense support
  • Loading branch information
vicary authored Aug 26, 2024
1 parent 3297a2d commit da614b9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-terms-collect.md.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gqty/solid': patch
---

Prevents Suspense leaking
4 changes: 2 additions & 2 deletions examples/solid/src/components/tailwindui/Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export type Props = ParentProps<{
fallback?: JSX.Element;
}>;

const Skeleton: Component<Props> = ({ children, fallback }) => {
return <>{children ?? fallback}</>;
const Skeleton: Component<Props> = (props) => {
return <>{props.children ?? props.fallback}</>;
};

export default Skeleton;
4 changes: 2 additions & 2 deletions examples/solid/src/components/tailwindui/SmallText.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Component, ParentProps } from 'solid-js';
import Skeleton from './Skeleton';

const SmallText: Component<ParentProps> = ({ children }) => (
const SmallText: Component<ParentProps> = (props) => (
<p class="text-xs text-gray-500 dark:text-gray-400">
<Skeleton
fallback={
Expand All @@ -21,7 +21,7 @@ const SmallText: Component<ParentProps> = ({ children }) => (
</span>
}
>
{children}
{props.children}
</Skeleton>
</p>
);
Expand Down
4 changes: 2 additions & 2 deletions examples/solid/src/components/tailwindui/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Component, ParentProps } from 'solid-js';
import Skeleton from './Skeleton';

const Text: Component<ParentProps> = ({ children }) => (
const Text: Component<ParentProps> = (props) => (
<Skeleton
fallback={
<span
Expand All @@ -21,7 +21,7 @@ const Text: Component<ParentProps> = ({ children }) => (
</span>
}
>
{children}
{props.children}
</Skeleton>
);

Expand Down
39 changes: 18 additions & 21 deletions packages/solid/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,29 +278,26 @@ export const createQuery = <Schema extends BaseGeneratedSchema>(
});
}

return Object.assign(
() => resource.latest?.query ?? resource()?.query ?? accessor.query,
{
$state: {
get loading() {
return resource.loading;
},
get error() {
return resource.error;
},
return Object.assign(() => resource()?.query ?? accessor.query, {
$state: {
get loading() {
return resource.loading;
},
$refetch: async (ignoreCache = true) => {
if (resolvePromise) {
return;
}
get error() {
return resource.error;
},
},
$refetch: async (ignoreCache = true) => {
if (resolvePromise) {
return;
}

// Always replace current selections with those from last successful
// fetch for user-triggered refetches.
restorePreviousSelections();
// Always replace current selections with those from last successful
// fetch for user-triggered refetches.
restorePreviousSelections();

return await $refetch({ ignoreCache });
},
}
);
return await $refetch({ ignoreCache });
},
});
};
};

0 comments on commit da614b9

Please sign in to comment.