Skip to content

Commit e5c2058

Browse files
committed
update
1 parent c9c49a5 commit e5c2058

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

src/routes/reference/basic-reactivity/create-effect.mdx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@ This function will re-run whenever any of its dependencies change.
2222

2323
## Execution Timing
2424

25-
- The initial execution of effects is scheduled to occur **after the current rendering phase completes**.
26-
It runs after all synchronous code in a component has executed and the DOM elements have been created, but **before the browser renders them on the screen**.
25+
### Initial Run
2726

28-
As a result, [refs](/concepts/refs) **are set** before the effect runs for the first time, even though the DOM nodes may **not be attached to the main document tree**.
29-
This is particularly relevant when using the [`children`](/reference/component-apis/children) function.
27+
- The initial run of effects is **scheduled to occur after the current rendering phase completes**.
28+
- It runs after all synchronous code in a component has finished and DOM elements have been created, but **before the browser paints them on the screen**.
29+
- **[Refs](/concepts/refs) are set** before the first run, even though DOM nodes may not yet be attached to the main document tree.
30+
This is relevant when using the [`children`](/reference/component-apis/children) helper.
3031

31-
- After the initial execution, effects will re-run whenever any of their dependencies change.
32+
### Subsequent Runs
3233

33-
When multiple dependencies are updated within the same batch, the effect will only run once.
34+
- After the initial run, the effect **re-runs whenever any tracked dependency changes**.
35+
- When multiple dependencies change within the same batch, the effect **runs once per batch**.
36+
- The **order of runs** among multiple effects is **not guaranteed**.
37+
- Effects always run **after** all pure computations (such as [memos](/concepts/derived-values/memos)) within the same update cycle.
3438

35-
- The order in which effects run is **not guaranteed**.
36-
- Effects always run **after** any pure computations (such as [memos](/concepts/derived-values/memos)) within the same update cycle.
37-
- Effects **are not executed** during Server-Side Rendering (SSR) or during the initial client hydration.
39+
### Server-Side Rendering
40+
41+
- Effects **never run during SSR**.
42+
- Effects also **do not run during the initial client hydration**.
3843

3944
## Import
4045

@@ -67,16 +72,17 @@ function createEffect<Next, Init>(
6772
- **Type:** `EffectFunction<undefined | NoInfer<Next> | EffectFunction<Init | Next, Next>`
6873
- **Required:** Yes
6974

70-
The function to execute as the effect.
71-
It receives the value returned from the previous execution, or the initial `value` during its first run.
72-
The value returned by this function will be passed to the next execution.
75+
A function to be executed as the effect.
76+
77+
It receives the value returned from the previous run, or the initial `value` during the first run.
78+
The value returned by `fn` is passed to the next run.
7379

7480
### `value`
7581

7682
- **Type:** `Init`
7783
- **Required:** No
7884

79-
The initial value that is passed to `fn` during its first execution.
85+
The initial value passed to `fn` during its first run.
8086

8187
### `options`
8288

src/routes/reference/secondary-primitives/create-render-effect.mdx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,25 @@ This function re-runs whenever any of its dependencies change.
2121

2222
## Execution Timing
2323

24-
- The initial execution of render effects occurs **during the current rendering phase**.
25-
It runs synchronously while DOM elements are being created and updated, but **before they are mounted**.
24+
### Initial Run
2625

27-
As a result, refs are **not set** before the render effect runs for the first time.
26+
- A render effect runs **synchronously during the current rendering phase**, while DOM elements are being created or updated.
27+
- It **runs before elements are mounted** to the DOM.
28+
- **[Refs](/concepts/refs) are not set** during this initial run.
2829

29-
- After the initial execution, render effects will re-run whenever any of their dependencies change.
30+
### Subsequent Runs
3031

31-
Render effects always re-run **after** any pure computations (such as [memos](/concepts/derived-values/memos)) are executed within the same update cycle.
32+
- After the initial render, the render effect **re-runs whenever any of its tracked dependencies change**.
33+
- Re-runs occur **after** all pure computations (such as [memos](/concepts/derived-values/memos)) have completed within the same update cycle.
34+
- When multiple dependencies change within the same batch, the render effect **runs once per batch**.
35+
- The **order of re-runs** among multiple render effects is **not guaranteed**.
3236

33-
When multiple dependencies are updated within the same batch, the render effect will only run once.
37+
### Server-Side Rendering
3438

35-
The order in which render effects re-run is **not guaranteed**.
39+
- During SSR, render effects **run once on the server**, since they are part of the synchronous rendering phase.
40+
- On the client, an initial run still occurs during the client rendering phase to initialize the reactive system;
41+
that client initial run is separate from the server run.
42+
- After hydration, subsequent runs occur on the client when dependencies change.
3643

3744
## Import
3845

@@ -65,16 +72,17 @@ function createRenderEffect<Next, Init>(
6572
- **Type:** `EffectFunction<undefined | NoInfer<Next> | EffectFunction<Init | Next, Next>`
6673
- **Required:** Yes
6774

68-
The function to execute as the render effect.
69-
It receives the value returned from the previous execution, or the initial `value` during its the first run.
70-
The value returned by this function will be passed to the next execution.
75+
A function to be executed as the render effect.
76+
77+
It receives the value returned from the previous run, or the initial `value` during the first run.
78+
The value returned by `fn` is passed to the next run.
7179

7280
### `value`
7381

7482
- **Type:** `Init`
7583
- **Required:** No
7684

77-
The initial value that is passed to `fn` during its first execution.
85+
The initial value passed to `fn` during its first run.
7886

7987
### `options`
8088

0 commit comments

Comments
 (0)