Skip to content

invalidateAll doesn't reload data from +layout.server.ts #10819

Answered by caidanw
DePasqualeOrg asked this question in Q&A
Discussion options

You must be logged in to vote

Solution

I think I was able to figure it out, my component looked kinda like this:

<script>
  export let data;
  const {item} = data;
</script>

<button on:click={() => invalidateAll())>Reload</button>
<p>{item}</p>

From svelte docs:

Note that rerunning a load function will update the data prop inside the corresponding +layout.svelte or +page.svelte; it does not cause the component to be recreated. As a result, internal state is preserved.

The issue that I was facing is that when you destructure an object from data you don't get the reactivity that's needed to use invalidate. So what was happening is that data was being updated, but since the component is not being recreated the item va…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@caidanw
Comment options

Answer selected by DePasqualeOrg
@DePasqualeOrg
Comment options

@caidanw
Comment options

@xerosanyam
Comment options

@kingraphaii
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants