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

tick() doesn't seem to work #14461

Open
FirstProphet opened this issue Nov 28, 2024 · 0 comments
Open

tick() doesn't seem to work #14461

FirstProphet opened this issue Nov 28, 2024 · 0 comments

Comments

@FirstProphet
Copy link

FirstProphet commented Nov 28, 2024

Describe the bug

The code below is supposed to change the clientHeight of the div when the button is pressed and then console.log the original and the new height. According to the svelte documentation, you can "use tick to ensure that the UI is updated before continuing". But it doesn't work and still console.logs the original height. If you replace the tick function call in line 14 with my crude customTick function, it seems to work fine.

Reproduction

<script>
	import { tick } from 'svelte';
	const contents = ['Hello World', 'Hello<br />World'];
	let currentContent = $state(0);
	let clientHeight = $state();

	function customTick() {
		return new Promise((resolve, reject) => setTimeout(resolve, 1));
	}
	
	function changeContent() {
		console.log(`Client Height Before Change: ${clientHeight}px`);
		currentContent = (currentContent + 1) % 2;
		tick().then(() => console.log(`Client Height After Change: ${clientHeight}px`)); // Doesn't work
	}
</script>

<button onclick={changeContent}>Change Content</button>
<br /><br />
<div bind:clientHeight style="border: 1px solid red;">{@html contents[currentContent]}</div>

Svelte Playground

Logs

No response

System Info

I used the playground on svelte.dev

Severity

annoyance

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

No branches or pull requests

1 participant