Skip to content

Commit fcd2903

Browse files
Merge branch 'main' into feat/how-it-works
2 parents 55eca12 + 586a866 commit fcd2903

File tree

26 files changed

+256
-199
lines changed

26 files changed

+256
-199
lines changed

src/middleware/legacy-routes-redirect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const LEGACY_ROUTES = {
5959
"/references/api-reference/secondary-primitives/createSelector": "/reference/secondary-primitives/create-selector",
6060
"/references/api-reference/special-jsx-attributes/attr_": "/reference/jsx-attributes/attr",
6161
"/references/api-reference/special-jsx-attributes/classList": "/reference/jsx-attributes/classlist",
62-
"/references/api-reference/special-jsx-attributes/innerHTML-or-textContent": "/reference/jsx-attributes/innerhtml-or-textcontent",
62+
"/references/api-reference/special-jsx-attributes/innerHTML-or-textContent": "/reference/jsx-attributes/innerhtml",
6363
"/references/api-reference/special-jsx-attributes/on_": "/reference/jsx-attributes/on_",
6464
"/references/api-reference/special-jsx-attributes/on_-and-oncapture_": "/reference/jsx-attributes/on",
6565

src/routes/concepts/control-flow/error-boundary.mdx

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,39 @@ title: "Error boundary"
33
order: 5
44
---
55

6-
`<ErrorBoundary>` is a component that can be used to catch errors thrown by child components.
7-
When encountering an error, this component will render a fallback UI instead of the problematic child component(s).
6+
By default, if part of an application throws an error during rendering, the entire application can crash, resulting in Solid removing its UI from the screen.
7+
Error boundaries provide a way to catch these errors and prevent the entire app from crashing.
88

9-
```jsx
10-
import { ErrorBoundary } from "solid-js";
11-
12-
<ErrorBoundary fallback={(err) => <div>Error: {err.message}</div>}>
13-
<ProblematicComponent />
14-
</ErrorBoundary>
15-
```
9+
The [`<ErrorBoundary>`](/reference/components/error-boundary) component is used to create an error boundary.
10+
It catches any error that occurs during the rendering or updating of its children.
11+
However, an important note is that errors occurring outside the rendering process, such as in event handlers or after a `setTimeout`, are _not_ caught by error boundaries.
1612

17-
`<ErrorBoundary>` accepts a `fallback` prop that can be used to render a custom error message, or to provide a friendly notification to the user.
18-
This prop accepts a function that receives the caught error as an argument, providing a flexible way to handle different error scenarios.
13+
The `fallback` prop can be used to display a user-friendly error message or notification when an error occurs.
14+
If a function is passed to `fallback`, it will receive the error object as well as a `reset` function.
15+
The `reset` function forces the `<ErrorBoundary>` to re-render its children and reset the error state, providing users with a way to recover from the error.
1916

20-
<EraserLink
21-
href="https://app.eraser.io/workspace/maDvFw5OryuPJOwSLyK9?elements=aSw5yYrSY22mI_YqoZlpGQ"
22-
preview="https://app.eraser.io/workspace/maDvFw5OryuPJOwSLyK9/preview?elements=aSw5yYrSY22mI_YqoZlpGQ&type=embed"
23-
/>
17+
```tsx
18+
import { ErrorBoundary } from "solid-js";
19+
import { Header, ErrorProne } from "./components";
2420

25-
By wrapping parts of your application in `<ErrorBoundary>`, you can prevent the entire application from crashing when an error occurs due to a single component.
21+
function App() {
22+
return (
23+
<div>
24+
<Header />
25+
<ErrorBoundary
26+
fallback={(error, reset) => (
27+
<div>
28+
<p>Something went wrong: {error.message}</p>
29+
<button onClick={reset}>Try Again</button>
30+
</div>
31+
)}
32+
>
33+
<ErrorProne />
34+
</ErrorBoundary>
35+
</div>
36+
);
37+
}
38+
```
2639

27-
When an error is encountered, the `<ErrorBoundary>` component will catch the error and render the fallback UI instead of the problematic component(s).
28-
This way, even when a component fails, the user has a controlled UI response instead of a broken interface.
40+
In this example, when the `ErrorProne` component throws an error, the `<ErrorBoundary>` catches it, preventing it from affecting the rest of the application.
41+
Instead, it displays the error message passed to the fallback prop.

src/routes/configuration/environment-variables.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function MyComponent() {
5959
6060
## Private Environment Variables
6161
62-
These variables should only be accessed in your backend code, so it's best not to use the `VITE_` prefix for them. Instead, use `process.env` to access them. Depending on the [Nitro preset](https://nitro.unjs.io/deploy) chosen, they'll be made available automatically or they will require an external dependency such as [dotenv](https://www.npmjs.com/package/dotenv).
62+
These variables should only be accessed in your backend code, so it's best not to use the `VITE_` prefix for them. Instead, use `process.env` to access them. Depending on the [Nitro preset](https://nitro.build/deploy) chosen, they'll be made available automatically or they will require an external dependency such as [dotenv](https://www.npmjs.com/package/dotenv).
6363
6464
```jsx
6565
DB_HOST="somedb://192.110.0"

src/routes/guides/fetching-data.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ The `Switch/Match` construct provides one way to manage these conditions.
7474
When the fetch succeeds and user data is retrieved, the `user()` condition becomes active, and its related block executes.
7575
However, if there's an error while fetching, the `user.error` block becomes `true`, leading to its corresponding `Match` block being shown.
7676

77+
:::tip
78+
79+
If you anticipate errors, you may want to wrap `createResource` in an [ErrorBoundary](/reference/components/error-boundary).
80+
81+
:::
82+
7783
In addition to the `error` property, the `loading` property offers a way to display a loading state to the user during the fetch operation.
7884

7985

src/routes/reference/components/error-boundary.mdx

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,52 @@ title: <ErrorBoundary>
33
order: 5
44
---
55

6-
Catches uncaught errors and renders fallback content.
6+
The `<ErrorBoundary>` component catches errors that occur during the rendering or updating of its children and shows a fallback UI instead.
7+
This includes:
78

8-
```tsx
9-
import { ErrorBoundary } from "solid-js"
10-
import type { JSX } from "solid-js"
9+
- Errors that occur while rendering JSX.
10+
- Errors that occur within `createEffect`, `createMemo`, and other state management primitives.
11+
- Errors that occur within `createResource` and other asynchronous state management or data-fetching primitives.
1112

12-
function ErrorBoundary(props: {
13-
fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element)
14-
children: JSX.Element
15-
}): () => JSX.Element
16-
```
13+
However, errors occurring outside the rendering process are **not** captured by error boundaries.
14+
For instance:
1715

18-
Here's an example of how to use it:
16+
- Errors that occur inside event handlers.
17+
- Errors that occur after a `setTimeout`.
1918

20-
```tsx
21-
<ErrorBoundary fallback={<div>Something went terribly wrong</div>}>
22-
<MyComp />
23-
</ErrorBoundary>
24-
```
19+
## Props
2520

26-
If you want to customize the error message, you can pass a function as the `fallback` prop. The function will be called with the error and a `reset` function. The `reset` function will reset the error boundary and re-render the children.
21+
### `fallback`
2722

28-
```tsx
29-
<ErrorBoundary
30-
fallback={(err, reset) => <div onClick={reset}>Error: {err.toString()}</div>}
31-
>
32-
<MyComp />
33-
</ErrorBoundary>
34-
```
23+
**Type**: `JSX.Element | ((err: any, reset: () => void) => JSX.Element)`
3524

36-
## Props
25+
`fallback` provides content to display when an error occurs.
26+
If a function is passed, it receives two parameters:
27+
28+
- `err`: The caught error object.
29+
- `reset`: A function that forces the `<ErrorBoundary>` to re-render its children and clear the error state.
30+
31+
If there's an error within the `fallback` itself, however, it is not caught by the same `<ErrorBoundary>`.
32+
Instead, it will bubble up to any parent error boundaries.
3733

38-
| Name | Type | Description |
39-
| :--------- | :-------------------------------------------------------------- | :------------------------------------------------------ |
40-
| `fallback` | `JSX.Element \| ((err: any, reset: () => void) => JSX.Element)` | The fallback content to render when an error is caught. |
34+
## Example
35+
36+
```tsx
37+
import { ErrorBoundary } from "solid-js";
38+
import { ErrorProne } from "./components";
39+
40+
function Example() {
41+
return (
42+
<ErrorBoundary
43+
fallback={(error, reset) => (
44+
<div>
45+
<p>{error.message}</p>
46+
<button onClick={reset}>Try Again</button>
47+
</div>
48+
)}
49+
>
50+
<ErrorProne />
51+
</ErrorBoundary>
52+
);
53+
}
54+
```

src/routes/reference/jsx-attributes/data.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"attr.mdx",
55
"classlist.mdx",
66
"bool.mdx",
7-
"innerhtml-or-textcontent.mdx",
7+
"innerhtml.mdx",
8+
"textcontent.mdx",
89
"on_.mdx",
910
"on.mdx",
1011
"once.mdx",

src/routes/reference/jsx-attributes/innerhtml-or-textcontent.mdx

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: innerHTML
3+
---
4+
5+
The `innerHTML` attribute is equivalent to the [`innerHTML` DOM property](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML).
6+
This attribute replaces all existing nodes of the element with new nodes generated by parsing the provided string as HTML.
7+
8+
:::caution
9+
10+
Using `innerHTML` with unsanitized user-supplied data can introduce security vulnerabilities.
11+
12+
:::
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: textContent
3+
---
4+
5+
The `textContent` attribute is equivalent to the [`textContent` DOM property](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent).
6+
This attribute replaces all existing child nodes of the element with a single text node containing the provided string.
7+
8+
Using `textContent` can improve performance when the element's children are known to be exclusively text, as it bypasses the generic diffing process.

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

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ function batch<T>(fn: () => T): T
99
```
1010

1111
`batch` is a low-level API that batches updates together.
12-
More precisely, `batch(fn)` holds the execution of downstream computations
13-
during the `fn` block, executing them all together once the block `fn` returns.
14-
Thus, instead of a downstream computation executing after every dependency
15-
update, it will update just once at the end of the batch.
12+
More precisely, `batch(fn)` holds the execution of downstream computations during the `fn` block, executing them all together once the block `fn` returns.
13+
Thus, instead of a downstream computation executing after every dependency update, it will update just once at the end of the batch.
1614

1715
Batching improves performance by avoiding unnecessary recalculation.
18-
Suppose you have a downstream memo `down` that depends on
19-
multiple upstream signals `up1`, `up2`, and `up3`:
16+
Suppose you have a downstream memo `down` that depends on multiple upstream signals `up1`, `up2`, and `up3`:
2017

2118
```ts
2219
import { createSignal, createMemo, createEffect } from "solid-js"
@@ -28,17 +25,15 @@ const down = createMemo(() => up1() + up2() + up3())
2825
createEffect(() => console.log(down())) // outputs 6
2926
```
3027

31-
If you directly update all of the upstream signals outside of batch mode,
32-
then `down` will recompute every time.
28+
If you directly update all of the upstream signals outside of batch mode, then `down` will recompute every time.
3329

3430
```ts
3531
setUp1(4) // recomputes down, outputs 9
3632
setUp2(5) // recomputes down, outputs 12
3733
setUp3(6) // recomputes down, outputs 15
3834
```
3935

40-
If instead you update the upstream signals within a `batch`, then `down`
41-
will update only once at the end:
36+
If instead you update the upstream signals within a `batch`, then `down` will update only once at the end:
4237

4338
```ts
4439
batch(() => {
@@ -48,33 +43,21 @@ batch(() => {
4843
}) // recomputes down, outputs 30
4944
```
5045

51-
The impact is even more dramatic if you have *m* downstream computations
52-
(memos, effects, etc.) that each depend on *n* upstream signals.
53-
Without batching, modifying all *n* upstream signals
54-
would cause *m n* updates to the downstream computations.
55-
With batching, modifying all *n* upstream signals
56-
would cause *m* updates to the downstream computations.
57-
Given that each update takes at least *n* time
58-
(just to read the upstream signals), this cost savings can be significant.
59-
Batching is also especially helpful when the downstream effects include
60-
DOM updates, which can be expensive.
46+
The impact is even more dramatic if you have *m* downstream computations (memos, effects, etc.) that each depends on *n* upstream signals.
47+
Without batching, modifying all *n* upstream signals would cause *m n* updates to the downstream computations.
48+
With batching, modifying all *n* upstream signals would cause *m* updates to the downstream computations.
49+
Given that each update takes at least *n* time (just to read the upstream signals), this cost savings can be significant.
50+
Batching is also especially helpful when the downstream effects include DOM updates, which can be expensive.
6151

62-
Solid uses `batch` internally to automatically batch updates for you
63-
in a few cases:
52+
Solid uses `batch` internally to automatically batch updates for you in a few cases:
6453

65-
* Within [`createEffect`](/reference/basic-reactivity/create-effect)
66-
and [`onMount`](/reference/lifecycle/on-mount)
67-
(unless they are outside a [root](/reference/reactive-utilities/create-root))
68-
* Within the [setter of a store](/reference/store-utilities/create-store#setter)
69-
(which can update several properties at once)
70-
* Within array methods (e.g. `Array.prototype.splice`) of a
71-
[mutable store](/reference/store-utilities/create-mutable)
72-
(which can update several elements at once)
54+
* Within [`createEffect`](/reference/basic-reactivity/create-effect) and [`onMount`](/reference/lifecycle/on-mount) (unless they are outside a [root](/reference/reactive-utilities/create-root))
55+
* Within the [setter of a store](/reference/store-utilities/create-store#setter) (which can update several properties at once)
56+
* Within array methods (e.g. `Array.prototype.splice`) of a [mutable store](/reference/store-utilities/create-mutable) (which can update several elements at once)
7357

7458
These save you from having to use `batch` yourself in many cases.
75-
For the most part, automatic batching should be transparent to you,
76-
because accessing a signal or memo will cause it to update if it is out of date
77-
(as of Solid 1.4). For example:
59+
For the most part, automatic batching should be transparent to you, because accessing a signal or memo will cause it to update if it is out of date (as of Solid 1.4).
60+
For example:
7861

7962
```ts
8063
batch(() => {
@@ -88,9 +71,6 @@ batch(() => {
8871
}) // recomputes down, outputs 36
8972
```
9073

91-
You can think of `batch(fn)` as setting a global "batch mode" variable,
92-
calling the function `fn`, and then restoring the global variable to its
93-
previous value.
74+
You can think of `batch(fn)` as setting a global "batch mode" variable, calling the function `fn`, and then restoring the global variable to its previous value.
9475
This means that you can nest `batch` calls, and they will form one big batch.
95-
It also means that, if `fn` is asynchronous,
96-
only the updates before the first `await` will be batched.
76+
It also means that, if `fn` is asynchronous, only the updates before the first `await` will be batched.

0 commit comments

Comments
 (0)