-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Draft
ChqThomas
wants to merge
3
commits into
symfony:2.x
Choose a base branch
from
ChqThomas:svelte-5-support
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | ||
* | ||
* 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 { getByTestId, waitFor } from '@testing-library/dom'; | ||
import { clearDOM, mountDOM } from '@symfony/stimulus-testing'; | ||
import SvelteController from '../src/render_controller'; | ||
import MyComponentSvelte5 from './fixtures/MyComponentSvelte5.svelte'; | ||
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'; | ||
|
||
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>')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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