-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Rerender just an item in list, not all the list items. #19
Comments
@frederikhors I'm trying to understand the same thing. Wondering if you learned anything since? |
Sorry, no experience here. Don't use Apollo/GraphQL at all |
@sergelerner not much. Can you answer today? |
I just had a similar issue. I figured it is because of the #await block. Just before updating the store the promise is 'reset'. This results in the entire each loop being rerendered. I am not sure if this is intended behaviour. I fixed it by awaiting the promise in between the script tags like so:
I don't think this is an elegant solution, but it works for me. |
@timhall Is this something we can fix? |
If you add this in onDestroy(() => {
console.log("destroyed", player.id);
}); or this in {#await $players}
{console.log('LOADING..')}
Loading players...
{:then result} it does seem to show that I had similar issue when having a list of items that depended on an I made this component to address this issue: <!-- Loader.svelte -->
<script>
import { query as apolloQuery } from 'svelte-apollo'
import { client } from '../utils/apollo'
export let query
export let variables = undefined
export let initial = null
let data = initial
$: q = apolloQuery(client, { query, variables })
$: (async () => {
let result = await $q
setData(result.data)
})()
function setData(d) {
data = d
}
</script>
{#await $q}
<slot {data} loading={true} />
{:then q}
<slot {data} loading={false} />
{/await} Used in this way: {#if $propertyId}
<Loader
let:data
let:loading
query={DASHBOARD}
variables={{
propertyId: Number($propertyId),
limit,
offset: limit * page,
filter: $filter$ ? `%${$filter$}%` : null }}>
{#if data}
<table>
....
<!-- Pagination updates data in way not shown here, but notice "loading"
used here sort of like a simplistic useTransition(..) from React to show
intermediate loading state next to pagination buttons before data items update -->
<Pagination
colspan={cols}
count={data.units_aggregate.aggregate.count}
{loading}
bind:limit
bind:page
on:prev={() => (expandedRow = null)}
on:next={() => (expandedRow = null)} />
</table> |
This can be worked around by using a derived state like so: const results = derived(
standardsQuery,
async ($query, set) => set(await $query),
cache.data
); This version does not use |
I have a big list of items.
Everything works good. But.
Everytime I update an item the big list re-render itself.
REPRODUCTION:
<svelte:options immutable/>
inButton.svelte
Maybe this is related to this example in Svelte tutorial https://svelte.dev/tutorial/svelte-options?
Have you already had this problem? @timhall @jacwright @lukeed
The text was updated successfully, but these errors were encountered: