solid-js 2.0.0-beta.1 → 2.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHEATSHEET.md +640 -0
  2. package/README.md +42 -188
  3. package/dist/dev.cjs +446 -291
  4. package/dist/dev.js +426 -293
  5. package/dist/server.cjs +941 -345
  6. package/dist/server.js +897 -299
  7. package/dist/solid.cjs +438 -261
  8. package/dist/solid.js +418 -263
  9. package/package.json +67 -39
  10. package/types/client/component.d.ts +64 -19
  11. package/types/client/core.d.ts +110 -34
  12. package/types/client/flow.d.ts +176 -42
  13. package/types/client/hydration.d.ts +513 -37
  14. package/types/index.d.ts +8 -13
  15. package/types/server/component.d.ts +11 -11
  16. package/types/server/core.d.ts +19 -21
  17. package/types/server/flow.d.ts +76 -21
  18. package/types/server/hydration.d.ts +34 -9
  19. package/types/server/index.d.ts +6 -8
  20. package/types/server/shared.d.ts +10 -2
  21. package/types/server/signals.d.ts +80 -19
  22. package/types/types.d.ts +15 -0
  23. package/types-cjs/client/component.d.cts +120 -0
  24. package/types-cjs/client/core.d.cts +141 -0
  25. package/types-cjs/client/flow.d.cts +234 -0
  26. package/types-cjs/client/hydration.d.cts +568 -0
  27. package/types-cjs/index.d.cts +15 -0
  28. package/types-cjs/package.json +3 -0
  29. package/types-cjs/server/component.d.cts +67 -0
  30. package/types-cjs/server/core.d.cts +42 -0
  31. package/types-cjs/server/flow.d.cts +115 -0
  32. package/types-cjs/server/hydration.d.cts +63 -0
  33. package/types-cjs/server/index.d.cts +10 -0
  34. package/types-cjs/server/shared.d.cts +54 -0
  35. package/types-cjs/server/signals.d.cts +123 -0
  36. package/types-cjs/types.d.cts +15 -0
  37. package/jsx-runtime.d.ts +0 -1
  38. package/types/jsx.d.ts +0 -4129
package/README.md CHANGED
@@ -2,222 +2,76 @@
2
2
  <img src="https://assets.solidjs.com/banner?project=Library&type=core" alt="SolidJS" />
3
3
  </p>
4
4
 
5
- [![Build Status](https://img.shields.io/github/actions/workflow/status/solidjs/solid/main-ci.yml?branch=main&logo=github&style=for-the-badge)](https://github.com/solidjs/solid/actions/workflows/main-ci.yml)
6
- [![Coverage Status](https://img.shields.io/coveralls/github/solidjs/solid.svg?style=for-the-badge)](https://coveralls.io/github/solidjs/solid?branch=main)
7
-
8
5
  [![NPM Version](https://img.shields.io/npm/v/solid-js.svg?style=for-the-badge)](https://www.npmjs.com/package/solid-js)
9
6
  [![](https://img.shields.io/npm/dm/solid-js.svg?style=for-the-badge)](https://www.npmjs.com/package/solid-js)
10
7
  [![Discord](https://img.shields.io/discord/722131463138705510?style=for-the-badge)](https://discord.com/invite/solidjs)
11
- [![Subreddit subscribers](https://img.shields.io/reddit/subreddit-subscribers/solidjs?style=for-the-badge)](https://www.reddit.com/r/solidjs/)
12
8
 
13
- **[Website](https://www.solidjs.com/) • [API Docs](https://docs.solidjs.com/) • [Features Tutorial](https://www.solidjs.com/tutorial/introduction_basics) • [Playground](https://playground.solidjs.com/?version=1.3.13#NobwRAdghgtgpmAXGGUCWEwBowBcCeADgsrgM4Ae2YZA9gK4BOAxiWGjIbY7gAQi9GcCABM4jXgF9eAM0a0YvADo1aAGzQiAtACsyAegDucAEYqA3EogcuPfr2ZCouOAGU0Ac2hqps+YpU6DW09CysrGXoIZlw0WgheAGEGCBdGAAoASn4rXgd4sj5gZhTcLF4yOFxkqNwAXV4AXgcnF3cvKDV0gAZMywT8iELeDEc4eFSm3iymgD4KqprU9JLamYBqXgBGPvCBoVwmBPTcvN4AHhN6XFx43gJiRpUrm-iVXnjEjWYAa0aQUZCCa4SSzU5nfirZaZSTgi76F63CBgga7CCwiBWISicTpGaNebnJZpXj6WblES0Zj0YEAOg8VQAompxsJcAAhfAASREJzAUEIhBUmTRYEkdSAA) • [Discord](https://discord.com/invite/solidjs)**
9
+ **[Website](https://www.solidjs.com/) • [API Docs](https://docs.solidjs.com/) • [Tutorial](https://www.solidjs.com/tutorial/introduction_basics) • [GitHub](https://github.com/solidjs/solid) • [Discord](https://discord.com/invite/solidjs)**
14
10
 
15
- Solid is a declarative JavaScript library for creating user interfaces. Instead of using a Virtual DOM, it compiles its templates to real DOM nodes and updates them with fine-grained reactions. Declare your state and use it throughout your app, and when a piece of state changes, only the code that depends on it will rerun. Check out our [intro video](https://www.youtube.com/watch?v=cELFZQAMdhQ) or read on!
11
+ > **You are looking at Solid 2.0 (experimental beta).**
12
+ > Public surface differs from 1.x — split-phase `createEffect`, microtask batching, `Loading`/`Errored` boundaries, draft-first store setters, async-in-computations, removed `solid-js/web` and `solid-js/store` subpaths, and more.
13
+ >
14
+ > - **Migrating from 1.x?** Read [MIGRATION.md](https://github.com/solidjs/solid/blob/next/documentation/solid-2.0/MIGRATION.md) (full guide).
15
+ > - **Need a quick API reference?** See [CHEATSHEET.md](./CHEATSHEET.md) (one page, every public export — ships with this package).
16
+ > - **Looking for stable Solid 1.x?** Use the default [`main` branch](https://github.com/solidjs/solid).
16
17
 
17
- ## Key Features
18
+ Solid is a declarative JavaScript library for building user interfaces. Instead of a Virtual DOM, it compiles templates to real DOM nodes and updates them with fine-grained reactivity. Declare your state and use it throughout your app — when a piece of state changes, only the code that depends on it re-runs.
18
19
 
19
- - Fine-grained updates to the real DOM
20
- - Declarative data: model your state as a system with reactive primitives
21
- - Render-once mental model: your components are regular JavaScript functions that run once to set up your view
22
- - Automatic dependency tracking: accessing your reactive state subscribes to it
23
- - [Small](https://dev.to/this-is-learning/javascript-framework-todomvc-size-comparison-504f) and [fast](https://krausest.github.io/js-framework-benchmark/current.html)
24
- - Simple: learn a few powerful concepts that can be reused, combined, and built on top of
25
- - Provides modern framework features like JSX, fragments, Context, Portals, Suspense, streaming SSR, progressive hydration, Error Boundaries and concurrent rendering.
26
- - Naturally debuggable: A `<div>` is a real div, so you can use your browser's devtools to inspect the rendering
27
- - [Web component friendly](https://github.com/solidjs/solid/tree/main/packages/solid-element#readme) and can author custom elements
28
- - Isomorphic: render your components on the client and the server
29
- - Universal: write [custom renderers](https://github.com/solidjs/solid/releases/tag/v1.2.0) to use Solid anywhere
30
- - A growing community and ecosystem with active core team support
20
+ ## At a glance (Solid 2.0)
31
21
 
32
- <details>
22
+ ```tsx
23
+ import { createSignal } from "solid-js";
24
+ import { render } from "@solidjs/web";
33
25
 
34
- <summary>Quick Start</summary>
26
+ function Counter() {
27
+ const [count, setCount] = createSignal(0);
28
+ const doubled = () => count() * 2;
35
29
 
36
- You can get started with a simple app by running the following in your terminal:
30
+ return <button onClick={() => setCount(c => c + 1)}>{doubled()}</button>;
31
+ }
37
32
 
38
- ```sh
39
- > npx degit solidjs/templates/js my-app
40
- > cd my-app
41
- > npm i # or yarn or pnpm
42
- > npm run dev # or yarn or pnpm
33
+ render(() => <Counter />, document.getElementById("app")!);
43
34
  ```
44
35
 
45
- Or for TypeScript:
46
-
47
- ```sh
48
- > npx degit solidjs/templates/ts my-app
49
- > cd my-app
50
- > npm i # or yarn or pnpm
51
- > npm run dev # or yarn or pnpm
52
- ```
36
+ Try it in our [Playground](https://playground.solidjs.com/). _(The hosted Playground currently runs Solid 1.x — a 2.0 build is on the way.)_
53
37
 
54
- This will create a minimal, client-rendered application powered by [Vite](https://vitejs.dev/).
38
+ The component body runs **once**. The `{doubled()}` expression is the only thing that re-renders when `count` changes — Solid compiles JSX to real DOM nodes and tracks the `count()` read at that one DOM position.
55
39
 
56
- Or you can install the dependencies in your own setup. To use Solid with JSX (_recommended_), run:
40
+ ## Install
57
41
 
58
42
  ```sh
59
- > npm i -D babel-preset-solid
60
- > npm i solid-js
61
- ```
62
-
63
- The easiest way to get set up is to add `babel-preset-solid` to your `.babelrc`, babel config for webpack, or rollup configuration:
64
-
65
- ```js
66
- "presets": ["solid"]
43
+ npm i solid-js @solidjs/web
44
+ npm i -D babel-preset-solid
67
45
  ```
68
46
 
69
- For TypeScript to work, remember to set your `.tsconfig` to handle Solid's JSX:
47
+ Add `babel-preset-solid` to your Babel config (or use Vite's Solid plugin), and set `tsconfig.json`:
70
48
 
71
- ```js
72
- "compilerOptions": {
73
- "jsx": "preserve",
74
- "jsxImportSource": "solid-js",
49
+ ```json
50
+ {
51
+ "compilerOptions": {
52
+ "jsx": "preserve",
53
+ "jsxImportSource": "@solidjs/web"
54
+ }
75
55
  }
76
56
  ```
77
57
 
78
- </details>
79
-
80
- ## Why Solid?
81
-
82
- ### Performant
83
-
84
- Meticulously engineered for performance and with half a decade of research behind it, Solid's performance is almost indistinguishable from optimized vanilla JavaScript (See Solid on the [JS Framework Benchmark](https://krausest.github.io/js-framework-benchmark/current.html)). Solid is [small](https://bundlephobia.com/package/solid-js@1.3.15) and completely tree-shakable, and [fast](https://levelup.gitconnected.com/how-we-wrote-the-fastest-javascript-ui-framework-again-db097ddd99b6) when rendering on the server, too. Whether you're writing a fully client-rendered SPA or a server-rendered app, your users see it faster than ever. ([Read more about Solid's performance](https://dev.to/ryansolid/thinking-granular-how-is-solidjs-so-performant-4g37) from the library's creator.)
85
-
86
- ### Powerful
87
-
88
- Solid is fully-featured with everything you can expect from a modern framework. Performant state management is built-in with Context and Stores: you don't have to reach for a third party library to manage global state (if you don't want to). With Resources, you can use data loaded from the server like any other piece of state and build a responsive UI for it thanks to Suspense and concurrent rendering. And when you're ready to move to the server, Solid has full SSR and serverless support, with streaming and progressive hydration to get to interactive as quickly as possible. (Check out our full [interactive features walkthrough](https://www.solidjs.com/tutorial/introduction_basics).)
89
-
90
- ### Pragmatic
91
-
92
- Do more with less: use simple, composable primitives without hidden rules and gotchas. In Solid, components are just functions - rendering is determined purely by how your state is used - so you're free to organize your code how you like and you don't have to learn a new rendering system. Solid encourages patterns like declarative code and read-write segregation that help keep your project maintainable, but isn't opinionated enough to get in your way.
93
-
94
- ### Productive
95
-
96
- Solid is built on established tools like JSX and TypeScript and integrates with the Vite ecosystem. Solid's bare-metal, minimal abstractions give you direct access to the DOM, making it easy to use your favorite native JavaScript libraries like D3. And the Solid ecosystem is growing fast, with [custom primitives](https://github.com/solidjs-community/solid-primitives), [component libraries](https://github.com/hope-ui/hope-ui), and build-time utilities that let you [write Solid code in new ways](https://github.com/LXSMNSYC/solid-labels).
97
-
98
- <details>
99
- <summary>Show Me!</summary>
100
-
101
- ```jsx
102
- import { render } from "solid-js/web";
103
- import { createSignal } from "solid-js";
104
-
105
- // A component is just a function that (optionally) accepts properties and returns a DOM node
106
- const Counter = props => {
107
- // Create a piece of reactive state, giving us a accessor, count(), and a setter, setCount()
108
- const [count, setCount] = createSignal(props.startingCount || 1);
109
-
110
- // The increment function calls the setter
111
- const increment = () => setCount(count() + 1);
112
-
113
- console.log(
114
- "The body of the function runs once, like you'd expect from calling any other function, so you only ever see this console log once."
115
- );
116
-
117
- // JSX allows us to write HTML within our JavaScript function and include dynamic expressions using the { } syntax
118
- // The only part of this that will ever rerender is the count() text.
119
- return (
120
- <button type="button" onClick={increment}>
121
- Increment {count()}
122
- </button>
123
- );
124
- };
125
-
126
- // The render function mounts a component onto your page
127
- render(() => <Counter startingCount={2} />, document.getElementById("app"));
128
- ```
129
-
130
- See it in action in our interactive [Playground](https://playground.solidjs.com/?hash=-894962706&version=1.3.13)!
131
-
132
- Solid compiles our JSX down to efficient real DOM expressions updates, still using the same reactive primitives (`createSignal`) at runtime but making sure there's as little rerendering as possible. Here's what that looks like in this example:
133
-
134
- ```js
135
- import { render, createComponent, delegateEvents, insert, template } from "solid-js/web";
136
- import { createSignal } from "solid-js";
137
-
138
- const _tmpl$ = /*#__PURE__*/ template(`<button type="button">Increment </button>`, 2);
139
-
140
- const Counter = props => {
141
- const [count, setCount] = createSignal(props.startingCount || 1);
142
- const increment = () => setCount(count() + 1);
143
-
144
- console.log("The body of the function runs once . . .");
145
-
146
- return (() => {
147
- //_el$ is a real DOM node!
148
- const _el$ = _tmpl$.cloneNode(true);
149
- _el$.firstChild;
150
-
151
- _el$.$$click = increment;
152
-
153
- //This inserts the count as a child of the button in a way that allows count to update without rerendering the whole button
154
- insert(_el$, count, null);
155
-
156
- return _el$;
157
- })();
158
- };
159
-
160
- render(
161
- () =>
162
- createComponent(Counter, {
163
- startingCount: 2
164
- }),
165
- document.getElementById("app")
166
- );
167
-
168
- delegateEvents(["click"]);
169
- ```
170
-
171
- </details>
172
-
173
- ## More
174
-
175
- Check out our official [documentation](https://www.solidjs.com/guide) or browse some [examples](https://github.com/solidjs/solid/blob/main/documentation/resources/examples.md)
176
-
177
- ## Browser Support
178
-
179
- SolidJS Core is committed to supporting the last 2 years of modern browsers including Firefox, Safari, Chrome and Edge (for desktop and mobile devices). We do not support IE or similar sunset browsers. For server environments, we support Node LTS and the latest Deno and Cloudflare Worker runtimes.
180
-
181
- <img src="https://saucelabs.github.io/images/opensauce/powered-by-saucelabs-badge-gray.svg?sanitize=true" alt="Testing Powered By SauceLabs" width="300"/>
182
-
183
- ## Community
184
-
185
- Come chat with us on [Discord](https://discord.com/invite/solidjs)! Solid's creator and the rest of the core team are active there, and we're always looking for contributions.
58
+ For web projects, `jsxImportSource` points at `@solidjs/web`. In 2.0, `solid-js` owns renderer-neutral component types, while renderer packages such as `@solidjs/web` and `@solidjs/h` own their JSX namespaces and `jsx-runtime` type entries.
186
59
 
187
- ### Contributors
60
+ Existing 1.x starter templates target 1.x — 2.0 starter templates are tracked at [solidjs/templates](https://github.com/solidjs/templates).
188
61
 
189
- <a href="https://github.com/solidjs/solid/graphs/contributors"><img src="https://opencollective.com/solid/contributors.svg?width=890&amp;button=false" style="max-width:100%;"></a>
62
+ ## For LLMs / AI assistants
190
63
 
191
- ### Open Collective
64
+ If you're an AI tool or model generating Solid 2.0 code: the public API differs from any Solid examples that predate 2.0. Read [`CHEATSHEET.md`](./CHEATSHEET.md) before generating — it lives inside this package (`node_modules/solid-js/CHEATSHEET.md`) for that reason. The bottom of the cheatsheet enumerates the specific patterns that changed from 1.x.
192
65
 
193
- Support us with a donation and help us continue our activities. [[Contribute](https://opencollective.com/solid)]
66
+ The full migration guide is [`MIGRATION.md`](https://github.com/solidjs/solid/blob/next/documentation/solid-2.0/MIGRATION.md). The 2.0 RFCs covering each subsystem live alongside it under [`documentation/solid-2.0/`](https://github.com/solidjs/solid/tree/next/documentation/solid-2.0).
194
67
 
195
- <a href="https://opencollective.com/solid/backer/0/website" target="_blank"><img src="https://opencollective.com/solid/backer/0/avatar.svg"></a>
196
- <a href="https://opencollective.com/solid/backer/1/website" target="_blank"><img src="https://opencollective.com/solid/backer/1/avatar.svg"></a>
197
- <a href="https://opencollective.com/solid/backer/2/website" target="_blank"><img src="https://opencollective.com/solid/backer/2/avatar.svg"></a>
198
- <a href="https://opencollective.com/solid/backer/3/website" target="_blank"><img src="https://opencollective.com/solid/backer/3/avatar.svg"></a>
199
- <a href="https://opencollective.com/solid/backer/4/website" target="_blank"><img src="https://opencollective.com/solid/backer/4/avatar.svg"></a>
200
- <a href="https://opencollective.com/solid/backer/5/website" target="_blank"><img src="https://opencollective.com/solid/backer/5/avatar.svg"></a>
201
- <a href="https://opencollective.com/solid/backer/6/website" target="_blank"><img src="https://opencollective.com/solid/backer/6/avatar.svg"></a>
202
- <a href="https://opencollective.com/solid/backer/7/website" target="_blank"><img src="https://opencollective.com/solid/backer/7/avatar.svg"></a>
203
- <a href="https://opencollective.com/solid/backer/8/website" target="_blank"><img src="https://opencollective.com/solid/backer/8/avatar.svg"></a>
204
- <a href="https://opencollective.com/solid/backer/9/website" target="_blank"><img src="https://opencollective.com/solid/backer/9/avatar.svg"></a>
205
- <a href="https://opencollective.com/solid/backer/10/website" target="_blank"><img src="https://opencollective.com/solid/backer/10/avatar.svg"></a>
68
+ ## Learn more
206
69
 
207
- ### Sponsors
70
+ - **Why Solid, key features, browser support, community, sponsors** — see the [repository README](https://github.com/solidjs/solid#readme).
71
+ - **Full documentation** — [docs.solidjs.com](https://docs.solidjs.com).
72
+ - **Examples** — [documentation/resources/examples.md](https://github.com/solidjs/solid/blob/next/documentation/resources/examples.md).
73
+ - **Discord** — [discord.com/invite/solidjs](https://discord.com/invite/solidjs).
208
74
 
209
- Become a sponsor and get your logo on our README on GitHub with a link to your site. [[Become a sponsor](https://opencollective.com/solid#sponsor)]
75
+ ---
210
76
 
211
- <a href="https://opencollective.com/solid/sponsor/0/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/0/avatar.svg"></a>
212
- <a href="https://opencollective.com/solid/sponsor/1/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/1/avatar.svg"></a>
213
- <a href="https://opencollective.com/solid/sponsor/2/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/2/avatar.svg"></a>
214
- <a href="https://opencollective.com/solid/sponsor/3/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/3/avatar.svg"></a>
215
- <a href="https://opencollective.com/solid/sponsor/4/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/4/avatar.svg"></a>
216
- <a href="https://opencollective.com/solid/sponsor/5/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/5/avatar.svg"></a>
217
- <a href="https://opencollective.com/solid/sponsor/6/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/6/avatar.svg"></a>
218
- <a href="https://opencollective.com/solid/sponsor/7/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/7/avatar.svg"></a>
219
- <a href="https://opencollective.com/solid/sponsor/8/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/8/avatar.svg"></a>
220
- <a href="https://opencollective.com/solid/sponsor/9/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/9/avatar.svg"></a>
221
- <a href="https://opencollective.com/solid/sponsor/10/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/10/avatar.svg"></a>
222
- <a href="https://opencollective.com/solid/sponsor/11/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/11/avatar.svg"></a>
223
- <a href="https://opencollective.com/solid/sponsor/12/website" target="_blank"><img src="https://opencollective.com/solid/sponsor/12/avatar.svg"></a>
77
+ _This is the npm package README for `solid-js`. The full repository README — including the monorepo layout, contributors, and sponsors — lives at [github.com/solidjs/solid](https://github.com/solidjs/solid#readme)._