-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
[Svelte] Svelte 5 support #2288
base: 2.x
Are you sure you want to change the base?
Changes from all commits
592ca91
eb4fcd2
77f4a15
bbfda3a
c964130
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,18 +30,18 @@ | |
}, | ||
"importmap": { | ||
"@hotwired/stimulus": "^3.0.0", | ||
"svelte/internal": "^3.0", | ||
"svelte": "^3.0 || ^4.0 || ^5.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kocal How to make it work if we need different packages/versions between peerDependencies and symfony.importmap ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, here we maybe broke Svelte 3 support by depending on Maybe we will remove support of Svelte 3, but it requires UX 3 to be released. |
||
"@symfony/ux-svelte": "path:%PACKAGE%/dist/loader.js" | ||
} | ||
}, | ||
"peerDependencies": { | ||
"@hotwired/stimulus": "^3.0.0", | ||
"svelte": "^3.0 || ^4.0" | ||
"svelte": "^3.0 || ^4.0 || ^5.0" | ||
}, | ||
"devDependencies": { | ||
"@hotwired/stimulus": "^3.0.0", | ||
"@sveltejs/vite-plugin-svelte": "^2.4.6", | ||
"@sveltejs/vite-plugin-svelte": "^3.1.2", | ||
"@types/webpack-env": "^1.16", | ||
"svelte": "^3.0 || ^4.0" | ||
"svelte": "^3.0 || ^4.0 || ^5.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<script> | ||
<script> | ||
import { fade } from 'svelte/transition'; | ||
export let name = 'without props'; | ||
</script> | ||
<div transition:fade|global={{ duration: 100 }}> | ||
<div>Hello {name}</div> | ||
</script> | ||
|
||
<div transition:fade|global={{ duration: 100 }}> | ||
<div>Hello {name}</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
let { name = 'without props' } = $props(); | ||
</script> | ||
|
||
<div> | ||
<div>Hello {name}</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { Application } from '@hotwired/stimulus'; | ||
import { clearDOM, mountDOM } from '@symfony/stimulus-testing'; | ||
import { getByTestId, waitFor } from '@testing-library/dom'; | ||
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'; | ||
import SvelteController from '../src/render_controller'; | ||
import MyComponentSvelte5 from './fixtures/MyComponentSvelte5.svelte'; | ||
|
||
const startStimulus = () => { | ||
const application = Application.start(); | ||
application.register('svelte', SvelteController); | ||
|
||
return application; | ||
}; | ||
|
||
(window as any).resolveSvelteComponent = () => { | ||
return MyComponentSvelte5; | ||
}; | ||
|
||
describe.skipIf(SVELTE_VERSION < '5')('Svelte5Controller', () => { | ||
let application: Application; | ||
|
||
afterEach(() => { | ||
clearDOM(); | ||
application.stop(); | ||
}); | ||
|
||
it('connect with props', async () => { | ||
const container = mountDOM(` | ||
<div data-testid="component" | ||
data-controller="check svelte 5" | ||
data-svelte-component-value="Svelte5Component" | ||
data-svelte-props-value="{"name": "Svelte 5 !"}" /> | ||
`); | ||
|
||
const component = getByTestId(container, 'component'); | ||
|
||
application = startStimulus(); | ||
|
||
await waitFor(() => expect(component.innerHTML).toContain('<div><div>Hello Svelte 5 !</div></div>')); | ||
}); | ||
|
||
it('connect without props', async () => { | ||
const container = mountDOM(` | ||
<div data-testid="component" id="container" | ||
data-controller="check svelte 5" | ||
data-svelte-component-value="Svelte5Component" /> | ||
`); | ||
|
||
const component = getByTestId(container, 'component'); | ||
|
||
application = startStimulus(); | ||
|
||
await waitFor(() => expect(component.innerHTML).toContain('<div><div>Hello without props</div></div>')); | ||
}); | ||
}); |
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 will not work with AssetMapper right ? In which cas we need to find a solution because this would be a giant BC break :)
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.
That was my first thought but it worked when I tried it in ux.symfony.com !
I also tried to have
import { mount } from 'svelte'
at the top of the file but it doesn't work with AssetMapper with Svelte 4, an error was thrown becausemount
only exists in v5I can't explain why but with a dynamic import there is no error, mount is just
undefined
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'll test this next week, thanks for the explanations :)
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.
Nice! FYI with AssetMapper it works with Svelte 4, but with Svelte 5 I'm stuck with the issue described here
I made a REPL with only html/js that reproduce the error