Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Should I be using a$derived or an$effect here?#16177

Answeredby7nik
peterreeves asked this question inQ&A
Discussion options

I'm working on a SvelteKit project that streams a big array of items in chunks to the browser using an AsyncGenerator. I'm trying to make this array in such a way so that it:

  1. Can be SSR'd.
  2. Is reactive so as more data streams in the UI updates.

Here is part of the core of my setup:
https://svelte.dev/playground/867fe279c37946d2818245b76ebb8812?version=5.34.3
Updating thestart number causes the numbers array to recalculate (Imagine that thestart parameter is page data from a SvelteKit load function, and the sleep calls are the array waiting for the next piece from the server side AsyncGenerator).

I've had success by putting$state inside a$derived.by ages ago, but it seems some recent updates have broken that for me. I started gettingstate_unsafe_mutation errors.

Turns out by wrapping the state update inuntrack helps, though I don't completely understand why. It seems something to do with this discussion?https://svelte.dev/playground/867fe279c37946d2818245b76ebb8812?version=5.34.3

After poking around on the docs foruntrack andstate_unsafe_mutation I noticed that the latter says "If side effects are unavoidable, use and$effect instead":https://svelte.dev/docs/svelte/runtime-errors#Client-errors-state_unsafe_mutation

Is what I'm trying to do here considered a "side effect"? Should I be using an$effect to update my array instead of trying to use$derived.by?

You must be logged in to vote
Answered by 7nikJun 17, 2025

state_unsafe_mutation error is a bug#16164, though the fix is not released yet.

Replies: 1 comment 1 reply

Comment options

7nik
Jun 17, 2025
Collaborator

state_unsafe_mutation error is a bug#16164, though the fix is not released yet.

You must be logged in to vote
1 reply
@peterreeves
Comment options

Thank you!

Answer selected bypeterreeves
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@peterreeves@7nik

[8]ページ先頭

©2009-2025 Movatter.jp