experimental: Solid 2.0 migration powered by AI#1437
experimental: Solid 2.0 migration powered by AI#1437davedbase wants to merge 17 commits intosolidjs:mainfrom
Conversation
|
|
✅ Deploy Preview for solid-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| ## Mutations: `action` + `refresh` | ||
|
|
||
| Reading async data is handled by computations and boundaries. | ||
| **Writing** data — mutations — uses a different tool: [`action()`](/reference/reactive-utilities/action). | ||
|
|
||
| An action wraps a generator function that can perform optimistic writes, async work, and refresh coordination in a structured way: | ||
|
|
||
| ```ts | ||
| import { action, refresh } from "solid-js" | ||
| import { createStore } from "solid-js/store" | ||
|
|
||
| const [todos] = createStore(() => api.getTodos(), { list: [] }) | ||
|
|
||
| const addTodo = action(function* (todo) { | ||
| yield api.addTodo(todo) // async work | ||
| refresh(todos) // re-fetch the source data | ||
| }) | ||
| ``` | ||
|
|
||
| Actions run inside a transition. When the action completes and `refresh()` fires, the derived data recomputes and the UI updates. | ||
| See the [Fetching Data](/guides/fetching-data) guide for the full mutation and optimistic update patterns. |
There was a problem hiding this comment.
actions are only needed to tie optimistic updates with async updates/refresh. This section should be combined with Optimistic updates below - no need to use actions if you are not setting optimistic data inside them.
| ## Optimistic updates | ||
|
|
||
| For instant UI feedback during mutations, Solid 2.0 provides two optimistic primitives: | ||
|
|
||
| - [`createOptimistic`](/reference/reactive-utilities/create-optimistic) — a signal whose writes revert when the transition completes | ||
| - [`createOptimisticStore`](/reference/reactive-utilities/create-optimistic-store) — the store equivalent | ||
|
|
||
| Optimistic values overlay on top of a source during a transition and automatically roll back when the transition settles (on both success and failure): |
There was a problem hiding this comment.
Replace transition with action, and in general i think we want to avoid talking about transitions if possible
| const [todos] = createStore(() => api.getTodos(), { list: [] }) | ||
| const [optimisticTodos, setOptimisticTodos] = createOptimisticStore( | ||
| () => snapshot(todos), | ||
| { list: [] } | ||
| ) |
There was a problem hiding this comment.
| const [todos] = createStore(() => api.getTodos(), { list: [] }) | |
| const [optimisticTodos, setOptimisticTodos] = createOptimisticStore( | |
| () => snapshot(todos), | |
| { list: [] } | |
| ) | |
| const [todos, setOptimisticTodos] = createOptimisticStore( | |
| () => api.getTodos(), | |
| { list: [] } | |
| ) |
| ## Error handling | ||
|
|
||
| Errors in async computations are caught by [`<Errored>`](/reference/components/error-boundary) boundaries, just like synchronous errors: | ||
|
|
||
| ```tsx | ||
| <Errored fallback={(err) => <p>Something went wrong: {err.message}</p>}> | ||
| <Loading fallback={<Spinner />}> | ||
| <UserProfile /> | ||
| </Loading> | ||
| </Errored> | ||
| ``` | ||
|
|
||
| If a fetch rejects or a computation throws, the nearest `<Errored>` boundary renders its fallback. |
There was a problem hiding this comment.
Might be worth adding an example with the retry method as well
| ## When to use `<For>` vs `<Repeat>` | ||
|
|
||
| - Use `<For>` when rendering from a **data array** where items have identity and may change, reorder, or be filtered. | ||
| - Use `<Repeat>` when rendering a **fixed count** of items (skeletons, ranges, grids) where no list diffing is needed. |
There was a problem hiding this comment.
Not sure the point about Repeat is accurate - it's not for fixed count of items, but for arrays where things don't move around much (chats, logs, etc). Probably gonna need some workshopping.
| <For each={tasks()}> | ||
| {(task) => { | ||
| const { id, text } = task | ||
| const { id, text } = task() |
There was a problem hiding this comment.
reading a signal top level bad
|
|
||
| - `err`: The caught error object. | ||
| - `reset`: A function that forces the `<ErrorBoundary>` to re-render its children and clear the error state. | ||
| - `reset`: A function that forces `<Errored>` to re-render its children and clear the error state. |
There was a problem hiding this comment.
reset doesn't force rerender of the children, it forces a rerun of the errored computations and nothing else
| function Repeat(props: { | ||
| count: number | ||
| from?: number | ||
| children: (index: () => number) => JSX.Element |
There was a problem hiding this comment.
| children: (index: () => number) => JSX.Element | |
| children: (index: number) => JSX.Element |
Index isn't an accessor since it can't change
| Use `<Repeat>` when: | ||
| - You need to render a fixed number of elements (e.g., star ratings, pagination dots, grid cells) | ||
| - The content doesn't come from a data array | ||
| - You don't need list diffing or keying | ||
|
|
||
| Use `<For>` when: | ||
| - You're rendering items from a data array | ||
| - Items have identity and may be reordered, added, or removed |
There was a problem hiding this comment.
Definitely gonna need more workshopping
| description: >- | ||
| Run code after component rendering is complete with onSettled. Replaces | ||
| onMount with added cleanup support and clearer semantics. | ||
| --- | ||
|
|
||
| ```ts | ||
| import { onSettled } from "solid-js" | ||
|
|
||
| function onSettled(fn: () => void | (() => void)): void | ||
| ``` | ||
|
|
||
| `onSettled` registers a callback that runs once after the component's initial render is complete and the DOM is ready. It replaces `onMount` from Solid 1.x. | ||
|
|
||
| ## Key differences from `onMount` | ||
|
|
||
| - **Can return a cleanup function** — the returned function runs when the component is disposed | ||
| - **Cannot create nested reactive primitives** — don't call `createSignal`, `createEffect`, etc. inside the callback | ||
|
|
There was a problem hiding this comment.
Also gonna need workshopping
The key change is the onSettled can be called from event handlers as well, where it will queue the callback to run after any updates made in the event are settled/flushed
This is an implementation of the docs generated from RFCs for Solid 2.0. Claude was prompted to use the PLAN.md and a cloned copy of the RFCs in the
new-docsfolder. It was tasked to outline what the 2.0 docs would look like. Note that this is an experiment to evaluate how close it got with little effort or guidance. This PR will either be deleted or evolved into additional docs for the 2.0 beta release.