-
-
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
TypeError when using a value from PageLoad when navigating #13276
Comments
This bug is bad, it makes it tedious for us to save changed inputs when the user navigates with the back/forward buttons in their browser after having typed something, and we have no understanding of how we are triggering this. |
This happens because the page props (such as page.data) are updated when we trigger a re-render. However, the blur event only occurs after the re-render. kit/packages/kit/src/runtime/client/client.js Lines 1490 to 1500 in 80a9e83
I'm not sure what the fix is here. Re-rendering before updating the page props to cause the blur event to trigger first? Not sure what unintended side effects this could have. const { activeElement } = document;
if (started) {
// unmount current components to trigger blur event with old data
root.$set({ constructors: [] });
await tick();
// render new page with new data
root.$set(navigation_result.props);
update(navigation_result.props.page);
has_navigated = true;
}
// need to render the DOM before we can scroll to the rendered elements and do focus management
await tick(); |
Describe the bug
When having a dependency to some data that originates from the PageLoad function that is used when the user navigates a TypeError is thrown due to the data being undefined at the moment of access. It seems that the data from the load-function is set to undefined before the navigation completes, causing the components below to use the undefined value. This problem only happens when the value comes from the page load (+page.ts), and does not occur if the value is defined in the +page.svelte file.
Reproduction
Code for repro can be found here: https://github.com/AndersRobstad/svelte-navigation-bug
Given this folder structure:
Where the +page.svelte and +page.ts inside the
textarea
route looks like this:Reproduction of the bug:
The following error will be thrown
Uncaught TypeError: Cannot read properties of undefined (reading 'id')
This stops occurring if the
dataDependencyFromLoad
is defined in the+page.svelte
file instead.Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: