-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(svelte): add support for svelte5 #34715
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There's a lot of diff here because of auto-formatting. Please remove these changes. |
@@ -18,6 +18,6 @@ | |||
"vite": "^5.2.8" | |||
}, | |||
"dependencies": { | |||
"svelte": "^4.2.8" | |||
"svelte": "^5.19.9" |
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.
I think we actually want to introduce ct-svelte4-vite to keep testing for vite4, wdyt @agg23
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.
Agreed
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.
Sure, I'll will try to do that today. Thanks for the input.
bc06d07
to
0d076a0
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
No rush, but you still have a bunch of formatting changes and stuff that doesn't pass the linter. |
7942ab7
to
ee03658
Compare
Ugh, some issues after a rebase. I will fix those issues tomorrow, both linting and npm issue as I don't have much time after my 9-5 job. I also don't think I can fully make it backward compatible as there is no option to attach slots to svelte4 components like there was in the previous version of the library. |
I think bumping |
Will try to rebase tomorrow if there is a fix for that. |
f051d3c
to
bbd4642
Compare
I don't think I can fix the pipeline without someone bumping dependencies for react
|
I think you should be able to update |
I can, was not sure if I should do it in this PR. Gonna try it today. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think you may have messed up |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Test results for "tests 1"8 flaky38671 passed, 793 skipped Merge workflow run. |
props?: ComponentProps<Component>; | ||
export interface MountOptions< | ||
HooksConfig, | ||
Component extends (new (...args: any[]) => V4Component) | V5Component |
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.
Can we remove any
here?
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.
Please abstract this into a shared type so we don't have to keep typing it.
Component extends (new (...args: any[]) => V4Component) | V5Component
@@ -18,12 +18,13 @@ | |||
|
|||
// This file is injected into the registry as text, no dependencies are allowed. | |||
|
|||
import { detach as __pwDetach, insert as __pwInsert, noop as __pwNoop } from 'svelte/internal'; | |||
import { asClassComponent } from 'svelte/legacy'; |
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.
Add a comment to remove when removing v4 support.
.createContextualFragment(slots[slotName]); | ||
svelteSlots[slotName] = [createSlotFn(template)]; | ||
} | ||
/** @type {( component: ObjectComponent ) => Record<string, any>} */ |
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.
Does this do anything?
|
||
class App extends componentCtor { | ||
constructor(options = {}) { | ||
if (!isObjectComponent(component)) | ||
throw new Error('JSX mount notation is not supported'); |
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.
Before this change we were unable to use JSX?
} | ||
return svelteSlots; | ||
slots = Object.fromEntries( | ||
Object.entries(slots ?? {}).map(([key, snippet]) => { |
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.
Probably add some comments for what is happening in this method. You're rewriting the old props and slots to match the new form? Is on
only used in v4, so you don't have to worry about rewriting v5 onclick
or whatever?
let svelteComponent; | ||
for (const hook of window.__pw_hooks_before_mount || []) | ||
for (const hook of window.__pw_hooks_before_mount || []) { |
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.
This is fake diff due to formatting changes. Please revert.
for (const hook of window.__pw_hooks_after_mount || []) | ||
await hook({ hooksConfig, svelteComponent }); | ||
|
||
for (const [key, listener] of Object.entries(component.on || {})) |
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.
Why did this move? Makes sense to me that we would register all listeners before firing after hooks.
update(); | ||
</script> | ||
|
||
<button on:click={() => dispatch('submit', 'hello')}> | ||
<button onclick={() => onsubmit?.('hello')}> |
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.
onsubmit
isn't optional.
update(); | ||
</script> | ||
|
||
<button on:click={() => dispatch('submit', 'hello')}> | ||
<button onclick={() => onsubmit?.('hello')}> |
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.
Optional again.
Adding support for svelte5.
This change works for us but I need some additional eyes and hands to verify if this is what you might need to upgrade to svelte5. Keep in mind this PR is using somewhat legacy api that is there just to help migration and should be rewritten to "native" before they ditch it (somewhere around svelte6)
Closes #30278