-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Milestone
Description
Describe the bug
If I start the svelte kit in the dev mode (npm run dev) then change a *.svelte file and then refresh the http://localhost:3000 page in the browser, then onMount will be called twice (on the first load and on the $session change).
Reproduction
- Create the svelte kit app:
src/routes/index.svelte:
<script>
import {session} from '$app/stores'
import {onMount} from 'svelte'
onMount(() => {
console.log('onMount')
})
</script>
<div>{$session.counter}</div>
<button type='button' on:click={() => {
session.update(session => {
return {
counter: session.counter + 1
}
})
}}>Click me</button>
app.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%svelte.head%
</head>
<body>
<div>%svelte.body%</div>
</body>
</html>
hooks.js:
export function getSession(event) {
return {
counter: 0
}
}
package.json:
{
"name": "my-app",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"package": "svelte-kit package",
"preview": "svelte-kit preview",
"prepare": "svelte-kit sync"
},
"dependencies": {
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"svelte": "^3.48.0"
},
"type": "module"
}
svelte.config.js:
import adapter from '@sveltejs/adapter-auto'
export default {
kit: {
adapter: adapter()
}
}
- Execute
npm install - Execute
npm run dev - Open the http://localhost:3000/ page in the browser and open the browser console
- Click to the "Click me" button. As you can see,
onMountdoesn't triggered on click (this is the correct behavior). - Now change the
index.sveltefile. For example, replaceconsole.log('onMount')toconsole.log('onMount2') - Refresh the page in the browser (F5, Ctrl+R, etc.)
- Click to the "Click me" button
Expected result
onMount is triggered only on the page load and doesn't triggered on click
Actual result
onMount is triggered on the page load and on the click (i.e. on the session.update())
Logs
No response
System Info
@sveltejs/kit: 1.0.0-next.324
@sveltejs/vite-plugin-svelte: 1.0.0-next.42
svelte: 3.48.0
vite: 2.9.7
browser: Chromium 101.0.4951.41
OS: Linux Ubuntu 20.10
nodejs: v17.0.1Severity
annoyance
Additional Information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels