Skip to content

Commit 44fe189

Browse files
committed
update docs for accuracy
1 parent b7a9c9d commit 44fe189

File tree

8 files changed

+125
-67
lines changed

8 files changed

+125
-67
lines changed

src/routes/reference/reactive-utilities/from.mdx

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,55 @@ Returns an accessor backed by the external source.
6161

6262
## Behavior
6363

64+
- `from` subscribes to the producer immediately when it runs.
6465
- A producer function receives a Solid setter and returns a cleanup function.
6566
- A subscribable source must expose `subscribe()`, and that subscription may return either a cleanup function or an object with `unsubscribe()`.
6667
- Emitted values are not deduplicated by equality.
67-
- Returned subscriptions are cleaned up with the current Solid owner when one exists.
68+
- Cleanup is registered on the current Solid owner when one exists.
69+
- When `from` runs without an owner, the subscription still starts but is not cleaned up automatically.
6870
- When `initialValue` is omitted, the accessor can return `undefined`.
6971

7072
## Examples
7173

7274
### Create an accessor from a subscribable source
7375

74-
```ts
76+
```tsx
7577
import { from } from "solid-js";
7678

77-
const counter = from({
78-
subscribe(next) {
79-
const interval = setInterval(() => next(Date.now()), 1000);
80-
return () => clearInterval(interval);
81-
},
82-
});
79+
function Clock() {
80+
const time = from(
81+
{
82+
subscribe(next) {
83+
const interval = setInterval(
84+
() => next(new Date().toLocaleTimeString()),
85+
1000
86+
);
87+
return () => clearInterval(interval);
88+
},
89+
},
90+
""
91+
);
92+
93+
return <div>{time()}</div>;
94+
}
8395
```
8496

8597
### Create an accessor from a producer function
8698

87-
```ts
99+
```tsx
88100
import { from } from "solid-js";
89101

90-
const clock = from((set) => {
91-
const interval = setInterval(() => {
92-
set((value) => value + 1);
93-
}, 1000);
102+
function Counter() {
103+
const count = from((set) => {
104+
const interval = setInterval(() => {
105+
set((value = 0) => value + 1);
106+
}, 1000);
107+
108+
return () => clearInterval(interval);
109+
}, 0);
94110

95-
return () => clearInterval(interval);
96-
}, 0);
111+
return <div>{count()}</div>;
112+
}
97113
```
98114

99115
## Related

src/routes/reference/reactive-utilities/get-owner.mdx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Owner = unknown;
3030
function getOwner(): Owner | null;
3131
```
3232

33-
The concrete owner shape is internal and is primarily useful with [`runWithOwner`](/reference/reactive-utilities/run-with-owner).
33+
The `Owner` interface is public, but its concrete shape is mostly useful for advanced interop such as [`runWithOwner`](/reference/reactive-utilities/run-with-owner).
3434

3535
## Parameters
3636

@@ -47,25 +47,29 @@ Returns the current owner or `null` when no owner is active.
4747
- `getOwner` returns the current owner and does not create or modify ownership.
4848
- Owners determine cleanup and context lookup for descendant computations.
4949
- A computation created inside the current scope becomes part of the current owner tree unless ownership is overridden.
50-
- Components are not computations and do not create owner nodes themselves.
50+
- Component functions run under an owner created for that subtree.
5151
- Calling `getOwner` inside component code returns the owner responsible for rendering and disposing that component subtree.
5252
- Turning off tracking with [`untrack`](/reference/reactive-utilities/untrack) does not create a new owner.
5353

5454
## Examples
5555

5656
### Capture an owner for later use
5757

58-
```ts
58+
```tsx
5959
import { getOwner, runWithOwner } from "solid-js";
6060

61-
const owner = getOwner();
61+
function Example() {
62+
const owner = getOwner();
6263

63-
if (owner) {
6464
queueMicrotask(() => {
65-
runWithOwner(owner, () => {
66-
console.log("owner restored");
67-
});
65+
if (owner) {
66+
runWithOwner(owner, () => {
67+
console.log("owner restored");
68+
});
69+
}
6870
});
71+
72+
return null;
6973
}
7074
```
7175

src/routes/reference/reactive-utilities/merge-props.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Returns a merged object with lazy reactive property resolution across the provid
4545

4646
## Behavior
4747

48+
- `mergeProps` is shallow.
4849
- The last source with a non-`undefined` value for a property wins.
4950
- Function sources are wrapped so property reads stay reactive.
5051
- When reactive proxies are involved, the merged result uses proxy-backed property resolution.
@@ -54,17 +55,18 @@ Returns a merged object with lazy reactive property resolution across the provid
5455

5556
### Basic usage
5657

57-
```ts
58+
```tsx
5859
import { mergeProps } from "solid-js";
5960

60-
// default props
61-
props = mergeProps({ name: "Smith" }, props);
62-
63-
// clone props
64-
newProps = mergeProps(props);
61+
function Greeting(props) {
62+
const merged = mergeProps({ greeting: "Hello", name: "Smith" }, props);
6563

66-
// merge props
67-
props = mergeProps(props, otherProps);
64+
return (
65+
<div>
66+
{merged.greeting} {merged.name}
67+
</div>
68+
);
69+
}
6870
```
6971

7072
## Related

src/routes/reference/reactive-utilities/run-with-owner.mdx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,32 +58,33 @@ Returns the value produced by `fn`, or `undefined` when an error is routed throu
5858

5959
- During the synchronous execution of `fn`, `runWithOwner` restores the provided owner for cleanup, context lookup, and descendant computations created inside `fn`.
6060
- `runWithOwner` does not restore dependency tracking because the current tracking listener is cleared while `fn` runs.
61-
- Code after the first `await` in an `async` function runs without reactive dependency tracking.
61+
- Code after the first `await` in an `async` function runs without the restored owner or reactive dependency tracking.
6262

6363
## Examples
6464

6565
### Restore an owner in a callback
6666

67-
```ts
68-
import { createEffect, getOwner, runWithOwner, useContext } from "solid-js";
69-
70-
const owner = getOwner();
67+
```tsx
68+
import { createEffect, getOwner, runWithOwner } from "solid-js";
7169

72-
if (owner) {
73-
setTimeout(() => {
74-
runWithOwner(owner, () => {
75-
const value = useContext(FooContext);
70+
function Example() {
71+
const owner = getOwner();
7672

77-
createEffect(() => {
78-
console.log(value);
73+
queueMicrotask(() => {
74+
if (owner) {
75+
runWithOwner(owner, () => {
76+
createEffect(() => {
77+
console.log("effect created under the captured owner");
78+
});
7979
});
80-
});
81-
}, 1000);
80+
}
81+
});
82+
83+
return null;
8284
}
8385
```
8486

8587
## Related
8688

8789
- [`getOwner`](/reference/reactive-utilities/get-owner)
88-
- [`useContext`](/reference/component-apis/use-context)
8990
- [`onCleanup`](/reference/lifecycle/on-cleanup)

src/routes/reference/reactive-utilities/split-props.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import { splitProps } from "solid-js";
2626
## Type
2727

2828
```ts
29-
function splitProps<T extends Record<string, unknown>>(
30-
props: T,
31-
...keys: (readonly (keyof T)[])[]
32-
): SplitProps<T, typeof keys>;
29+
function splitProps<
30+
T extends Record<any, any>,
31+
K extends [readonly (keyof T)[], ...(readonly (keyof T)[])[]],
32+
>(props: T, ...keys: K): SplitProps<T, K>;
3333
```
3434

3535
## Parameters
@@ -58,6 +58,7 @@ Returns a tuple of reactive subsets followed by a reactive remainder object.
5858
- A key is assigned to the first matching group only.
5959
- The last returned object contains keys not included in the provided key arrays.
6060
- When the source props object is proxy-backed, the returned objects use proxy-backed property access.
61+
- `splitProps` separates props into groups without destructuring them into non-reactive locals.
6162

6263
## Examples
6364

src/routes/reference/reactive-utilities/start-transition.mdx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ Resolves when the transition completes.
4646

4747
## Behavior
4848

49-
- Updates scheduled inside `fn` run as a transition. Nested calls inside an active transition reuse that transition and return its existing promise, which resolves after transition work completes.
49+
- On the client, `fn` runs asynchronously in a microtask and its updates run as a transition.
50+
- Nested calls inside an active transition reuse that transition and return its existing promise, which resolves after transition work completes.
5051
- On the server, `startTransition(fn)` runs `fn()` synchronously.
5152
- `startTransition` is the transition-starting function exposed by [`useTransition`](/reference/reactive-utilities/use-transition), without the `pending` accessor.
5253

@@ -55,18 +56,34 @@ Resolves when the transition completes.
5556
### Basic usage
5657

5758
```tsx
58-
import { createSignal, startTransition } from "solid-js";
59+
import {
60+
Suspense,
61+
createResource,
62+
createSignal,
63+
startTransition,
64+
} from "solid-js";
5965

6066
function Example() {
61-
const [value, setValue] = createSignal("");
67+
const [userId, setUserId] = createSignal(1);
68+
const [user] = createResource(userId, async (id) => {
69+
const response = await fetch(`/api/users/${id}`);
70+
return response.json();
71+
});
6272

63-
async function update(next: string) {
73+
async function showNextUser() {
6474
await startTransition(() => {
65-
setValue(next);
75+
setUserId(2);
6676
});
6777
}
6878

69-
return <button onClick={() => update("next")}>{value()}</button>;
79+
return (
80+
<>
81+
<button onClick={showNextUser}>Load next user</button>
82+
<Suspense fallback={<p>Loading user...</p>}>
83+
<pre>{JSON.stringify(user(), null, 2)}</pre>
84+
</Suspense>
85+
</>
86+
);
7087
}
7188
```
7289

src/routes/reference/reactive-utilities/untrack.mdx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,24 @@ Returns the value produced by `fn` unchanged.
4848
## Behavior
4949

5050
- `untrack` only affects reads inside the provided function. Signals read there do not become dependencies of the surrounding computation.
51-
- On the server, `untrack` runs through the server runtime's `batch` implementation.
51+
- `untrack` does not create or restore an owner.
5252

5353
## Examples
5454

55-
### Read a prop without tracking
55+
### Read part of an effect without tracking
5656

5757
```tsx
58-
import { untrack } from "solid-js";
58+
import { createEffect, untrack } from "solid-js";
5959

6060
export function Component(props) {
61-
const value = untrack(() => props.value);
61+
createEffect(() => {
62+
console.log(
63+
props.id,
64+
untrack(() => props.label)
65+
);
66+
});
6267

63-
return <div>{value}</div>;
68+
return <div>{props.id}</div>;
6469
}
6570
```
6671

@@ -86,8 +91,7 @@ function Example() {
8691

8792
## Notes
8893

89-
Default and initial prop values can be read directly when initializing a signal.
90-
This pattern commonly appears with names such as `initialName` and `defaultName`.
94+
Default and initial prop values can be read directly when initializing a signal. This pattern commonly appears with names such as `initialName` and `defaultName`.
9195

9296
```tsx tab title="initialValue" {5}
9397
import { createSignal } from "solid-js";

src/routes/reference/reactive-utilities/use-transition.mdx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Returns a tuple containing:
4848
## Behavior
4949

5050
- `start` is the same transition-starting function exposed by [`startTransition`](/reference/reactive-utilities/start-transition).
51+
- On the client, `start` schedules its callback asynchronously in a microtask.
5152
- `pending()` reflects whether that transition is still pending.
5253
- Transition state integrates with Suspense and resource reads under Suspense boundaries.
5354
- On the server, `pending()` is `false` and transitions run synchronously.
@@ -57,22 +58,34 @@ Returns a tuple containing:
5758
### Basic usage
5859

5960
```tsx
60-
import { createSignal, useTransition } from "solid-js";
61+
import {
62+
Suspense,
63+
createResource,
64+
createSignal,
65+
useTransition,
66+
} from "solid-js";
6167

6268
function Example() {
63-
const [value, setValue] = createSignal("");
69+
const [userId, setUserId] = createSignal(1);
70+
const [user] = createResource(userId, async (id) => {
71+
const response = await fetch(`/api/users/${id}`);
72+
return response.json();
73+
});
6474
const [pending, start] = useTransition();
6575

6676
return (
6777
<>
6878
<button
6979
onClick={async () => {
70-
await start(() => setValue("next"));
80+
await start(() => setUserId(2));
7181
}}
7282
>
73-
Update
83+
Load next user
7484
</button>
75-
<div>{pending() ? "pending" : value()}</div>
85+
<div>{pending() ? "Loading transition..." : "Ready"}</div>
86+
<Suspense fallback={<p>Loading user...</p>}>
87+
<pre>{JSON.stringify(user(), null, 2)}</pre>
88+
</Suspense>
7689
</>
7790
);
7891
}

0 commit comments

Comments
 (0)