-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Prevent needless prop updates causing rerenders (#5671)
* [fix] Prevent needless prop updates causing rerenders Fixes #5247 by not adding unchanged layout or page props to the root props * enhance test * spaces -> tabs, and add explanatory comment so we dont later delete it Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com> Co-authored-by: Rich Harris <hello@rich-harris.dev>
- Loading branch information
1 parent
2315d7e
commit 66d17af
Showing
6 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
Prevent needless prop updates causing rerenders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/kit/test/apps/basics/src/routes/load/layout-props/__layout.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script context="module"> | ||
/** @type {import('@sveltejs/kit').Load} */ | ||
export async function load({ session }) { | ||
session; // not necessary, but prevents the argument from being marked as unused | ||
return { | ||
props: { | ||
// Needs to be an object, else Svelte will do by-value-comparison and skip rerender | ||
obj: {} | ||
} | ||
}; | ||
} | ||
</script> | ||
|
||
<script> | ||
import { session } from '$app/stores'; | ||
/** @type {any} */ | ||
export let obj; | ||
let count = 0; | ||
$: obj && count++; | ||
</script> | ||
|
||
<h1>{count}</h1> | ||
<button on:click={() => ($session.calls = 123)}>Rerun Layout Load Function</button> | ||
<slot /> |
2 changes: 2 additions & 0 deletions
2
packages/kit/test/apps/basics/src/routes/load/layout-props/a.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h2>On a</h2> | ||
<a href="/load/layout-props/b">to b</a> |
2 changes: 2 additions & 0 deletions
2
packages/kit/test/apps/basics/src/routes/load/layout-props/b.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h2>On b</h2> | ||
<a href="/load/layout-props/a">to a</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters