-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
__layout props update on every route change #5247
Comments
NOTE: the I can get it to give the expected behavior by checking for the reference change myself. i.e. return dataraw from the load function and check for it differing from a local variable: export let dataraw
let data
$: if (data !== dataraw) data = dataraw |
I appreciate that the load function runs every time queryparams change. This is important as it gives a lot of flexibility for pages where one might want to show multiple panels side by side based on queryparams. For example: |
I agree to a point - if the __layout was making use of queryparams (ideally the specific ones that had changed) then I'd expect it to re-run, but when the load function is purely dependent on a route param that hasn't changed it appears to behave differently to the load function in a page. |
I believe this issue I've run into is related to this discussion, and I do believe it to be an issue. I've discovered that when altering the state of props that are import from a load function in a layout, those state changes are not retained when navigating. The load function does not re-run at all, nor do any function that may be responsible for altering said state. The props simply are reverted back to their initial state on first load for no apparent reason. This is irregardless of any load input that may or may not be used. Please refer to this example site I've created for a clearer picture. Here's the repo. While @CaptainCodeman calls it a mere 'annoyance', I feel this could be particularly detrimental in some scenarios, especially if/when layout endpoints are finally introduced. |
Fixes #5247 by not adding unchanged layout or page props to the root props
* [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 <[email protected]> Co-authored-by: Rich Harris <[email protected]>
Describe the bug
Not sure if this is a bug or should just be a discussion, but it was a surprise. When loading some data once in a parent __layout I expected that data to then remain static. But the props appear to be re-assigned on every navigation, even for querystring parameter changes. This plays havoc with any
use:actions
which think things have been updated when they haven't (which may contain image gallery layout code, canvas setup etc... that I only want to re-run when the data actually changes)Reproduction
Simplified example to show the behavior:
https://github.com/CaptainCodeman/sveltekit-layout-props-example
Run the project and navigate around. Note the prop changes and action update console logs, even though the
load
function has only executed once:I wouldn't expect the
data
prop to keep changing or for theuse:action
to keep being updated, but they are in both the __layout and an imported component.Logs
No response
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: