Skip to content
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

fix Svelte 5 on-mount #206

Merged
merged 1 commit into from
Mar 3, 2024
Merged

fix Svelte 5 on-mount #206

merged 1 commit into from
Mar 3, 2024

Conversation

7nik
Copy link
Contributor

@7nik 7nik commented Nov 20, 2023

$effect() runs after the component gets mounted and rendered, but pageTitle isn't reactive. Thus, the page won't re-render with the new value. For this logic, it's better to use $effert.pre() - it runs before mounting and the first rendering. But as the example concerns the on-mount event, it makes more sense to make pageTitle reactive.

You can try both solutions on the Svelte 5 playground.

`$effect` runs after the component gets mounted and rendered, but `pageTitle` isn't reactive. Thus, the page won't re-render with the new value.
For this logic, it's better to use `$effert.pre` - it runs before mounting and the first rendering. But as the example concerns the on-mount event, it's better to make `pageTitle` reactive.
@matschik matschik merged commit 89b0b18 into matschik:main Mar 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants