-
Notifications
You must be signed in to change notification settings - Fork 39
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
[0.5.x] Add svelte 5 #104
base: main
Are you sure you want to change the base?
[0.5.x] Add svelte 5 #104
Conversation
Thanks for your work on this! We may need someone with more Svelte experience to review 😅 cc @pedroborges - do you have anytime to give this a look? |
Hey @renatomoor, just giving some thoughts here. Let me know if they make sense or if I'm misunderstanding anything. I think the goal would likely trying to get it closer in resemblance to the React or Vue versions. The biggest difference I can see is how you aren't using the Additionally, I think the This one might be nitpicky, but I don't think the getters for the end of the form function are needed, no? The Lastly, I think the Something like: const hasErrors = $derived(Object.keys(errors).length > 0) Let me know if that all makes sense! |
Hello @joshcirre, Thanks for the feedback! Great catch on resolveName and submit. I've fixed those. Regarding the getters, they’re part of the new approach in Svelte 5 for getting reactive values from outside Svelte components, as the Svelte team explained here: https://svelte.dev/blog/runes#beyond-components. I initially started using <script>
let form = useForm('post', 'register', {
name: '',
email: '',
password: '',
password_confirmation: '',
})
</script>
<span>Validating: {form.validating}</span> <!-- Here we are getting the reactive value defined outside the component with $state through the getter -->
<span>Processing: {form.processing}</span>
<span>hasErrors: {form.hasErrors}</span>
<Form.Input
bind:value={form.data.name}
error="{form.errors.name}"
label="Name"
name="name"
on:change={() => form.validate('name')}
placeholder="Name"
required
type="text"
/>
<!-- ... -->
<Button on:click={() => form.submit()} type="submit">Register</Button> As for That said, this is actually my first time working with Svelte 4 or 5, so please let me know if there’s anything else to check! I’ve been testing it in SvelteKit, and it’s working fine, though I’m sure there could be further improvements. I considered using |
Hey @renatomoor, makes perfect sense! I like the changes, and I agree that while it might make sense from a Svelte-ish syntax to use $derived, I do agree that keeping it as similar to the React/Vue implementations is best, and I think these changes fall in line with that. I just tried it out in a SvelteKit project and it works great! (I also like the |
Hey @taylorotwell, I can test this out and provide a full review over the weekend. Started at a new job this week and have been pretty busy 😃 @renatomoor and @joshcirre, I have a proof of concept for the Inertia.js Svelte adapter using Svelte 5 that I'm not ready to share just yet. This PR aligns with my direction by utilizing one let form = useForm('post', {
name: '',
email: '',
password: '',
password_confirmation: '',
})
console.log(form.name)
console.log(form.email)
console.log(form.password)
console.log(form.password_confirmation) This approach keeps consistency with the current Svelte adapter. If want to give it a shot: const form = {
data() {
return $state.snapshot(data) as TForm
},
// ...
}
// Define "data" getters and setters on "form"
(Object.keys(data) as Array<keyof TForm>).forEach((key) => {
Object.defineProperty(form, key, {
get() {
return data[key]
},
set(value: TForm[keyof TForm]) {
data[key] = value
},
})
})
return form I agree with @joshcirre on using |
I just noticed Inertia.js isn’t included in this PR. @renatomoor are you familiar with Inertia.js and able to add the adapter as well? If not, no worries. I can take care of it after your PR is merged. Thanks again for your awesome work! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work so far, @renatomoor! 🎉
Please take a look at my comments and questions below. I’m here to help or answer any questions you might have.
I haven’t had a chance to run the code yet since I don’t have any project using Precognition. If you have a demo project you can share, I’d love to test it out!
@pedroborges thanks for the comments! |
hey! @pedroborges @joshcirre. I just did the repo to test laravel precognition with svelte kit: https://github.com/renatomoor/sveltekit-precognition Later today I'll implement the changes that you both requested. |
@pedroborges I’ve made the corrections for the Svelte package. You can check them again! I’ll continue with the Inertia package tomorrow or the day after. WDYT? |
I'd like to see the Inertia version here before we look at merging this. The API decisions made here should be based the Inertia Svelte adapter. If we implement this version first and then find out there are inconsistencies in the Inertia version, that is gonna be annoying to maintain. |
Would anyone be kind enough and have time to spin up a bare bones svelte project with a basic form for me to test this out in? Even if it is just the front-end component. I can handle the Laravel side of things if that helps. |
Hello @timacdonald! I did that already here #104 (comment). I'll see if I can do tomorrow or the day after the inertia part. 😉 |
You rock ❤️ |
@timacdonald or @pedroborges, Is there a repo with inertia and svelte 5 ? I've worked with inertia and vue + precognition in the past but never with svelte, so if you can guide me a little bit here would be nice! |
Thanks @pedroborges, I saw your package a few days ago, but I have not had the time yet to develop the inertia part this week. |
Add |
Add support for svelte 5