[2.x] Refactor createInertiaApp
in Svelte adapter
#2036
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While investigating issue #2012 with @saml-dev, I identified the need for more predictable updates to the
$page
store. This PR ensures that the$page
store updates are more predictable to prevent reactivity issues, aligns the Svelte adapter with the other adapters, and simplifies the SSR (Server-Side Rendering) configuration.Data resolution for the
<App />
component has been moved from thecreateInertiaApp
function into the component itself. The internal$store
has been removed, and the state it managed is now local within the<App />
component. This change ensures that re-renders and$page
store updates occur in a more predictable manner.Additionally, I've simplified the SSR setup by allowing it to be managed by the user, consistent with the other adapters. This reduces the complexity within the adapter and provides more flexibility for custom server-side rendering configurations. I'll update the docs with instructions on how to add the
setup
callback to theresources/js/ssr.js
file.I have tested these changes on both playgrounds, including in SSR mode, as well as in two other projects, one using Svelte 4 and another using Svelte 5.
@joetannenbaum I welcome any feedback on how I have set up the Svelte-specific test. While the current test is functional, I know that it can be improved and plan to refactor it when I have the opportunity.