Repository navigation
effect-atom-svelte@0.3.0
Minor Changes
- 4208ce3: Re-export Effect's
Reactivitymodule besideAtom,AtomRegistryand the othereffect/reactivitymodules, so the reactivity keys mutations refresh can be used fromeffect-atom-sveltetoo. - 4f0d922:
useAtomRefanduseAtomRefPropValuereturn acurrentyou can assign for a writableAtomRef, which sets the ref or the property, sobind:value={name.current}works as it does withuseAtom. A read-only ref, such as one frommap, still returns a read-onlycurrent.
Patch Changes
-
72bc355: Fix several edge cases in server rendering and hydration:
- On the server,
useAtomResultanduseAtomSuspenserender a value fromuseAtomInitialValueswithout running the atom, asuseAtomValuealready did, so a browser-only read or a request the value was there to save no longer runs on the server. - With
suspendOnWaiting, the result sent to the browser is the settled one the server rendered, not one still waiting, which the browser would run again. This holds when another component reading the same atom withoutsuspendOnWaitingrendered first. - On the server,
HydrationBoundaryignores a value dehydrated as a promise that lands after the render, so it can no longer reach a later request through a registry the caller passes in. One that lands during the render is still what the server renders. - Destroying a
HydrationBoundarykeeps the values another boundary given the same state queued, as a layout and its page might be. - A seeded
useAtomSuspenseread in the script, outside any reaction, lets go of its atom once the getter moves on. - A hook after a top-level
awaitno longer warns in development about a missed seed for an atom whose result the server didn't send, such as a defect.
- On the server,
-
73101b0: The devtools no longer carry a mapped atom's value across a hot reload:
Atom.make(1).pipe(Atom.map(...))wrote its mapped value back into its source, so set to 5 it read 10, then 20 after the reload. Only pipes that leave an atom holding what is written to it (keepAlive,autoDispose,setIdleTTL,setLazy,withEquality,withLabel,serializable,withServerValue,withServerValueInitial) keep their value.Atoms declared in a SvelteKit route group, such as
src/routes/(app)/+page.svelte, now show and open their real file, including those labelled withAtom.withLabel. The panel follows ashortcutprop the app changes after it has saved its settings, including settings saved by earlier versions, and keeps a shortcut chosen in the settings even when it is the default. A comment that mentions<svelte:head>before a component's script no longer stops its atoms being labelled.atomLabels()no longer warns that components aren't labelled when it comes after vite-plugin-svelte 7, which labels them.The inspector no longer reports a computation as
Refreshedwhen an earlier refresh changed nothing and a parent changed since. -
85be511: Error messages now end with a link to their entry on the troubleshooting page. "This atom value is read-only" also names the hooks that only read and the ones to write with instead, and "Two different atoms share the serialization key" says why the server can't render it and what to change.
-
7e2bc5c: A server render that fails while a serializable atom's result is still being prepared for the browser no longer reports an unhandled rejection ("registry is disposed"). The provider disposes of its registry when the failed render ends, and the pending result now stops there instead of reading from it.
-
63f9cfb: Fix atoms given a value by
useAtomInitialValuesbeing dropped while another component still held them: when one of two components seeding the same atom unmounted, the atom lost its value, and on the server a request sharing the registry could run the atom's browser-only read. On the server, requests rendering at the same time on a shared registry now keep the value the first one applied until the last of them ends.provideRegistrynow disposes of the registry it created when its component is destroyed while its script is still awaiting. A reader whose getter switched to an atom that threw while subscribing now follows that atom once it recovers.handleClientErroruses SvelteKit 2's message for an error whose own message is empty, such as aData.TaggedError. -
22a7551: Fix three cases where server-rendered state reached the browser wrongly:
- Remounting a component that makes its own serializable atom, such as a
ScopedAtomprovider under{#key}with its input in the serialization key, no longer throwsTwo different atoms share the serialization key. Svelte sets up the new copy before it destroys the old one, so for a moment both hold the key. In the browser, the server's value now belongs to the key, not to the atom that first claimed it, so the new copy shares it, as both already share the registry's value. The server render still throws. - The browser's first render inside a
HydrationBoundarynow matches the server's markup when the atom already exists, as with a value fromRegistryProvider'sinitialValuesor an atom also read above the boundary. While the page hydrates, the boundary updates those atoms before its children render, as the server does. This needs Svelte'sexperimental.async; without it they are updated after the first render, as before. Each server-rendered page with aHydrationBoundarycarries one more smallhydratableentry for this. - In the browser, a value dehydrated as a promise that lands after its
HydrationBoundaryis destroyed, including one destroyed while its children were still loading, is ignored, so it no longer reaches whoever reads the atom later. A reader that already held the atom when the boundary was destroyed, such as a layout's reader above it, still gets the value.
- Remounting a component that makes its own serializable atom, such as a
-
c64799e: Fix
useAtomSuspensewithincludeFailureresolving, after it waited, with a copy of the atom's result rather than the result itself. The copy lost aFailure'spreviousSuccess, soAsyncResult.getOrElseandAsyncResult.valueno longer fell back to the last value. It showed in a promise awaited in the script or an event handler. -
5d0a215: Make the inspector report more accurately, which the devtools show:
- An inspector scope's snapshot and
ScopeChangedfollow an atom in the scope that switches what it reads, also when it mounts, subscribes to or writes another atom while computing, and also while nothing listens to the scope. Interrupted(a cross in the devtools) is reported only for the effect atom whose fiber was interrupted, not also for a wrapper passing its result on, such asAtom.debounce,makeRefreshOnSignalorrefreshOnWindowFocus, and not for anAtom.runtimereleased while its layer builds, which carries on.idleTTLgivesundefinedfor an atom with an idle TTL of 0, which is removed as soon as nothing reads it.
- An inspector scope's snapshot and
-
f6f0c9c: Fix several things
effect-atom-svelte/inspectorreported wrongly. A lazy atom no longer names a parent as the cause of its next computation when that parent changed while the atom was computing, before the atom read it. A node with an initial value (initialValues) that hasn't computed yet reports its first computation as a first read. A node removed after its idle TTL reports its interruption and finalizers before its removal, as other removals do.registry.resetreports the readers it drops. In a scope, a component reading a serializable atom whose node another atom object with the same key made (as after a hot reload) points at that node. The docs now say a refresh signal (refreshOnWindowFocus,makeRefreshOnSignal,swr) is reported asRefreshed, as it always was.Fix the devtools labelling a component with a
genericsattribute holding>wrongly, and taking a<script>inside<svelte:head>for the component's script: an inline head script got animportthat broke the page, and a JSON-LD script stopped the component's atoms being labelled. A shortcut recorded with a key whose code has several words (ArrowUp,PageDown,BracketLeft) now opens the panel once saved, and is shown as such rather than asArrowup. The graph puts both sides of a diamond to the right of its source whichever atom a scope lists first. -
456cf7c: Fix pending
useAtomSetcalls and initial values in edge cases:- A
"promise"or"promiseExit"call no longer hangs when theRegistryProviderthat created its registry is destroyed mid-call: the call is interrupted and the promise settles as interrupted. A registry you pass in yourself is still yours to dispose of. - A
"promise"or"promiseExit"call pending when another setter writesAtom.Resetsettles as interrupted, instead of hanging, or resolving with theinitialValueof anAtom.fnthat has one.Atom.Interruptremains the way to cancel a call. useAtomInitialValueslets go of the entries it applied when a later entry throws, so on the server a registry shared between requests no longer renders the failed request's value in the next one.- A finalizer that throws while a
RegistryProvider(orprovideRegistrywithout aregistry) disposes of its registry in the browser is reported as an uncaught error after teardown, instead of being thrown into Svelte's teardown, where it left every$derivedon the page running again on every read until reload.
- A
-
5c740ad: A reader whose atom is built for the first time by its own read, after the component has mounted, no longer updates a second time with the value it just read.
useAtomValue(() => family(id), transform)ran the transform twice whenidswitched to an atom not built yet, returning a new object for an unchanged value; an$effectthat first read an atom ran twice; and code after awaitinguseAtomSuspenseof an atom that resolves at once, in an$effect, ran twice. -
67d468b: Fix the first refresh of an atom with a value from
initialValuesoruseAtomInitialValuesbeing lost after the server's result or aHydrationBoundaryvalue replaced that value: the atom ran again, but kept showing the old value, andrevalidateOnHydratedid nothing for it. This includes an atom wrapped byAtom.withRefreshor similar, whose initial value goes to the atom it wraps. Effect's registry kept the initial value through the next computation even though the atom had a value of its own by then. -
876bdd1: Fix two more ways a server render could keep atoms after a
<svelte:boundary>with afailedsnippet caught an error thrown while its children set up:- A dropped component whose script awaits before calling its hooks now lets go of its atoms on a registry the caller keeps across requests. Its script resumed after the render had ended, so its atoms stayed held and the next request rendered this one's initial value.
- A
RegistryProviderwithout aregistryprop inside such a boundary now disposes its registry on the server, so itskeepAliveatoms, and whatever they run, no longer outlive the request.
A
useAtomValuereader kept past the render no longer keeps the atom its getter switches to mounted on a registry the caller keeps. -
dfd7db3: Fix two cases where the server ran an atom that had a value from
useAtomInitialValues, which renders that value instead so that a browser-only read or a request the value was there to save doesn't run:- An atom wrapped by
Atom.withRefresh,Atom.withReactivity,Atom.swr,Atom.debounceorAtom.makeRefreshOnSignal, or anAtomRpcorAtomHttpApiquery withreactivityKeys. The value goes to the wrapped atom, and every hook now renders it from there. - A serializable atom read with
useAtomSuspenseand awaited in the markup straight away.
- An atom wrapped by
-
473c6e1: Fix server renders leaving atoms held on a registry the caller keeps across requests when a
<svelte:boundary>with afailedsnippet caught an error thrown while its children set up. Svelte drops those children'sonDestroycallbacks, so their mounts, holds anduseAtomInitialValuesvalues stayed, and the next request rendered the earlier request's initial value. The hooks andHydrationBoundarynow also let go when the render ends. -
e0d92a1:
useAtomSubscribewith a getter now subscribes again only when the getter returns a different atom. A getter that ran again and returned the same atom, as() => profileAtom(user.id)does for a newuserwith the same id, calledfagain with an unchanged value underimmediate, and could drop a change still waiting to be delivered.A seed the browser can't decode with the atom's schema, as after a deploy between the server render and hydration, is now dropped and the browser computes the atom, as for a result the server couldn't encode. It made
useAtomSuspenseanduseAtomResultreject for good, with unhandled rejections. Development builds warn. -
c64799e: Fix two ways
useAtomSuspensekept an atom loading after its component was destroyed, on a registry that outlives the component:- Its promise read through a
$derivedthat only the script or an event handler reads, as inconst todos = $derived(list.current)awaited in a click handler. Svelte never aborts such a derived's signal, so the wait it held was never let go of. Each read now also lets go when the component is destroyed. - Its promise read after the component was destroyed, as in
onDestroyor a handler that resumes later. A result the component had already settled is still returned; one it would have to wait for now rejects with the abort reason, without starting the atom.
- Its promise read through a
-
c01da28:
handleClientErrorandhandleServerErrornow type-check as SvelteKit 2'sHandleClientErrorandHandleServerError, whoseApp.Errorrequires a message: given SvelteKit 2's input, which has nokind, they are typed to return one, as they always set one there.handleClientErroralso uses SvelteKit 2's message for an error whose own message is empty, such as aData.TaggedError.The docs now say that SvelteKit 2 runs errors in a boundary through
handleErroronly withkit.experimental.handleRenderingErrors, and use SvelteKit 3's#libin their imports. -
85be511: In development, the server now warns once per serialization key when
useAtomValueoruseAtomreads a serializable async atom that is still running. OnlyuseAtomResultanduseAtomSuspensesend an atom's result to the browser, so that atom runs again there, which the page showed only as a second request. A key the page sends anyway, through one of those hooks in the same render or aHydrationBoundary, doesn't warn, nor does a result nothing is computing, such as a mutation nobody has called.