@preact/signals-react 1.3.7 → 2.0.0
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.
- package/CHANGELOG.md +21 -0
- package/README.md +66 -3
- package/auto/dist/auto.js +1 -0
- package/auto/dist/auto.js.map +1 -0
- package/auto/dist/auto.min.js +1 -0
- package/auto/dist/auto.min.js.map +1 -0
- package/auto/dist/auto.mjs +1 -0
- package/auto/dist/auto.mjs.map +1 -0
- package/auto/dist/auto.module.js +1 -0
- package/auto/dist/auto.module.js.map +1 -0
- package/auto/dist/index.d.ts +1 -0
- package/auto/package.json +25 -0
- package/auto/src/index.ts +2 -0
- package/dist/signals.d.ts +1 -1
- package/dist/signals.js +1 -1
- package/dist/signals.js.map +1 -1
- package/dist/signals.min.js +1 -1
- package/dist/signals.min.js.map +1 -1
- package/dist/signals.mjs +1 -1
- package/dist/signals.mjs.map +1 -1
- package/dist/signals.module.js +1 -1
- package/dist/signals.module.js.map +1 -1
- package/package.json +13 -3
- package/runtime/dist/index.d.ts +38 -3
- package/runtime/dist/runtime.js +1 -1
- package/runtime/dist/runtime.js.map +1 -1
- package/runtime/dist/runtime.min.js +1 -1
- package/runtime/dist/runtime.min.js.map +1 -1
- package/runtime/dist/runtime.mjs +1 -1
- package/runtime/dist/runtime.mjs.map +1 -1
- package/runtime/dist/runtime.module.js +1 -1
- package/runtime/dist/runtime.module.js.map +1 -1
- package/runtime/src/auto.ts +30 -13
- package/runtime/src/index.ts +192 -29
- package/src/index.ts +9 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @preact/signals-react
|
|
2
2
|
|
|
3
|
+
## 2.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#467](https://github.com/preactjs/signals/pull/467) [`d7f43ef`](https://github.com/preactjs/signals/commit/d7f43ef5c9b6516cd93a12c3f647409cfd8c62be) Thanks [@andrewiggins](https://github.com/andrewiggins)! - Remove auto tracking using React internals from signals-react package
|
|
8
|
+
|
|
9
|
+
Before this change, importing `@preact/signals-react` would invoke side effects that hook into React internals to automatically track signals. This change removes those side effects and requires consumers to update their code to continue using signals in React.
|
|
10
|
+
|
|
11
|
+
We made this breaking change because the mechanism we were using to automatically track signals was fragile and not reliable. We've had multiple issues reported where signals were not being tracked correctly. It would also lead to unexpected errors that were hard to debug.
|
|
12
|
+
|
|
13
|
+
For some consumers and apps though, the current mechanism does work. If you'd like to continue using this mechanism, simply add `import "@preact/signals/auto";` to the root of your app where you call `ReactDOM.render`. For our newly supported ways of using signals in React, check out the new Readme for `@preact/signals-react`.
|
|
14
|
+
|
|
15
|
+
## 1.3.8
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#456](https://github.com/preactjs/signals/pull/456) [`b0b2a5b`](https://github.com/preactjs/signals/commit/b0b2a5b54d0b512152171bb13c5bc4c593e7e444) Thanks [@XantreGodlike](https://github.com/XantreGodlike)! - Ensure types are resolved against built `.d.ts` rather than source `.ts`
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`990f1eb`](https://github.com/preactjs/signals/commit/990f1eb36fa4ab5e30029f79ceeccf709137d14d)]:
|
|
22
|
+
- @preact/signals-core@1.5.1
|
|
23
|
+
|
|
3
24
|
## 1.3.7
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -26,15 +26,25 @@ npm install @preact/signals-react
|
|
|
26
26
|
|
|
27
27
|
## React Integration
|
|
28
28
|
|
|
29
|
-
> Note: The React integration plugs into some React internals and may break unexpectedly in future versions of React. If you are using Signals with React and encounter errors such as "Rendered more hooks than during previous render", "Should have a queue. This is likely a bug in React." or "Cannot redefine property: createElement" please open an issue here.
|
|
30
|
-
|
|
31
29
|
The React integration can be installed via:
|
|
32
30
|
|
|
33
31
|
```sh
|
|
34
32
|
npm install @preact/signals-react
|
|
35
33
|
```
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
We have a couple of options for integrating Signals into React. The recommended approach is to use the Babel transform to automatically make your components that use signals reactive.
|
|
36
|
+
|
|
37
|
+
### Babel Transform
|
|
38
|
+
|
|
39
|
+
Install the Babel transform package (`npm i --save-dev @preact/signals-react-transform`) and add the following to your Babel config:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"plugins": [["module:@preact/signals-react-transform"]]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This will automatically transform your components to be reactive. You can then use signals directly inside your components.
|
|
38
48
|
|
|
39
49
|
```js
|
|
40
50
|
import { signal } from "@preact/signals-react";
|
|
@@ -48,6 +58,23 @@ function CounterValue() {
|
|
|
48
58
|
}
|
|
49
59
|
```
|
|
50
60
|
|
|
61
|
+
See the [Readme for the Babel plugin](../babel-plugin-signals-react/README.md) for more details about how the transform works and configuring it.
|
|
62
|
+
|
|
63
|
+
### `useSignals` hook
|
|
64
|
+
|
|
65
|
+
If you can't use the Babel transform, you can directly call the `useSignals` hook to make your components reactive.
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import { useSignals } from "@preact/signals-react";
|
|
69
|
+
|
|
70
|
+
const count = signal(0);
|
|
71
|
+
|
|
72
|
+
function CounterValue() {
|
|
73
|
+
useSignals();
|
|
74
|
+
return <p>Value: {count.value}</p>;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
51
78
|
### Hooks
|
|
52
79
|
|
|
53
80
|
If you need to instantiate new signals inside your components, you can use the `useSignal` or `useComputed` hook.
|
|
@@ -97,6 +124,42 @@ To opt into this optimization, simply pass the signal directly instead of access
|
|
|
97
124
|
> **Note**
|
|
98
125
|
> The content is wrapped in a React Fragment due to React 18's newer, more strict children types.
|
|
99
126
|
|
|
127
|
+
## Limitations
|
|
128
|
+
|
|
129
|
+
This version of React integration does not support passing signals as DOM attributes. Support for this may be added at a later date.
|
|
130
|
+
|
|
131
|
+
Using signals into render props is not recommended. In this situation, the component that reads the signal is the component that calls the render prop, which may or may not be hooked up to track signals. For example:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
const count = signal(0);
|
|
135
|
+
|
|
136
|
+
function ShowCount({ getCount }) {
|
|
137
|
+
return <div>{getCount()}</div>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function App() {
|
|
141
|
+
return <ShowCount getCount={() => count.value} />;
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Here, the `ShowCount` component is the one that accesses `count.value` at runtime since it invokes `getCount`, so it needs to be hooked up to track signals. However, since it doesn't statically access the signal, the Babel transform won't transform it by default. One fix is to set `mode: all` in the Babel plugin's config, which will transform all components. Another workaround is put the return of the render prop into it's own component and then return that from your render prop. In the following example, the `Count` component statically accesses the signal, so it will be transformed by default.
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
const count = signal(0);
|
|
149
|
+
|
|
150
|
+
function ShowCount({ getCount }) {
|
|
151
|
+
return <div>{getCount()}</div>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const Count = () => <>{count.value}</>;
|
|
155
|
+
|
|
156
|
+
function App() {
|
|
157
|
+
return <ShowCount getCount={() => <Count />} />;
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Similar issues exist with using object getters & setters. Since the it isn't easily statically analyzable that a getter or setter is backed by a signal, the Babel plugin may miss some components that use signals in this way. Similarly, setting Babel's plugin to `mode: all` will fix this issue.
|
|
162
|
+
|
|
100
163
|
## License
|
|
101
164
|
|
|
102
165
|
`MIT`, see the [LICENSE](../../LICENSE) file.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("@preact/signals-react/runtime").installAutoSignalTracking();//# sourceMappingURL=auto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto.js","sources":["../src/index.ts"],"sourcesContent":["import { installAutoSignalTracking } from \"@preact/signals-react/runtime\";\ninstallAutoSignalTracking();\n"],"names":["installAutoSignalTracking"],"mappings":"AACAA,QAAAA,iCAAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(require("@preact/signals-react/runtime")):"function"==typeof define&&define.amd?define(["@preact/signals-react/runtime"],n):n((e||self).reactSignalsRuntime)}(this,function(e){e.installAutoSignalTracking()});//# sourceMappingURL=auto.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto.min.js","sources":["../src/index.ts"],"sourcesContent":["import { installAutoSignalTracking } from \"@preact/signals-react/runtime\";\ninstallAutoSignalTracking();\n"],"names":["installAutoSignalTracking"],"mappings":"CACAA,SAAAA,EAAAA,GAAAA,iBAAAA,SAAAA,oBAAAA,OAAAA,EAAAA,QAAAA,kCAAAA,mBAAAA,QAAAA,OAAAA,IAAAA,OAAAA,CAAAA,iCAAAA,GAAAA,GAAAA,EAAAA,oBAAAA,WAAAA,WAAAA,GAAAA,MAAAA,oBAAAA,CAAAA,CAAAA,KAAAA,SAAAA,GAAAA,EAAAA,2BAA2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{installAutoSignalTracking as r}from"@preact/signals-react/runtime";r();//# sourceMappingURL=auto.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto.mjs","sources":["../src/index.ts"],"sourcesContent":["import { installAutoSignalTracking } from \"@preact/signals-react/runtime\";\ninstallAutoSignalTracking();\n"],"names":["installAutoSignalTracking"],"mappings":"oCACAA,MAAAA,gCAAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{installAutoSignalTracking as r}from"@preact/signals-react/runtime";r();//# sourceMappingURL=auto.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto.module.js","sources":["../src/index.ts"],"sourcesContent":["import { installAutoSignalTracking } from \"@preact/signals-react/runtime\";\ninstallAutoSignalTracking();\n"],"names":["installAutoSignalTracking"],"mappings":"oCACAA,MAAAA,gCAAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@preact/signals-react-auto",
|
|
3
|
+
"description": "Sub package for @preact/signals-react that patches React to automatically update when signals change",
|
|
4
|
+
"private": true,
|
|
5
|
+
"amdName": "reactSignalsAuto",
|
|
6
|
+
"main": "dist/auto.js",
|
|
7
|
+
"module": "dist/auto.module.js",
|
|
8
|
+
"unpkg": "dist/auto.min.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"mangle": "../../../mangle.json",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"browser": "./dist/auto.module.js",
|
|
15
|
+
"import": "./dist/auto.mjs",
|
|
16
|
+
"require": "./dist/auto.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@preact/signals-core": "workspace:^1.3.0",
|
|
22
|
+
"@preact/signals-react": "workspace:*",
|
|
23
|
+
"react": "^16.14.0 || 17.x || 18.x"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/dist/signals.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { signal, computed, batch, effect, Signal, type ReadonlySignal, untracked } from "@preact/signals-core";
|
|
2
2
|
import type { ReactElement } from "react";
|
|
3
|
-
import { useSignal, useComputed, useSignalEffect } from "
|
|
3
|
+
import { useSignal, useComputed, useSignalEffect } from "@preact/signals-react/runtime";
|
|
4
4
|
export { signal, computed, batch, effect, Signal, type ReadonlySignal, useSignal, useComputed, useSignalEffect, untracked, };
|
|
5
5
|
declare module "@preact/signals-core" {
|
|
6
6
|
interface Signal extends ReactElement {
|
package/dist/signals.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var r=require("@preact/signals-core"),e=require("@preact/signals-react/runtime");exports.Signal=r.Signal;exports.batch=r.batch;exports.computed=r.computed;exports.effect=r.effect;exports.signal=r.signal;exports.untracked=r.untracked;exports.useComputed=e.useComputed;exports.useSignal=e.useSignal;exports.useSignalEffect=e.useSignalEffect;//# sourceMappingURL=signals.js.map
|
package/dist/signals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.js","sources":["../runtime/src/auto.ts","../runtime/src/index.ts","../src/index.ts"],"sourcesContent":["import {\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { EffectStore, wrapJsx, _useSignalsImplementation } from \"./index\";\n\nexport interface ReactDispatcher {\n\tuseRef: typeof React.useRef;\n\tuseCallback: typeof React.useCallback;\n\tuseReducer: typeof React.useReducer;\n\tuseSyncExternalStore: typeof React.useSyncExternalStore;\n\tuseEffect: typeof React.useEffect;\n\tuseImperativeHandle: typeof React.useImperativeHandle;\n}\n\n// In order for signals to work in React, we need to observe what signals a\n// component uses while rendering. To do this, we need to know when a component\n// is rendering. To do this, we watch the transition of the\n// ReactCurrentDispatcher to know when a component is rerendering.\n//\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to an instance that doesn't warn or error\n// and contains the implementations of all hooks. Right after React finishes\n// rendering a component, the dispatcher is set to the erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a \"valid\" dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an Signal effect and manually starting the Signal effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some additional complexities to be aware of:\n// - If a component calls `setState` while rendering, React will re-render the\n// component immediately. Before triggering the re-render, React will change\n// the dispatcher to the HooksDispatcherOnRerender. When we transition to this\n// rerendering adapter, we need to re-trigger our hooks to keep the order of\n// hooks the same for every render of a component.\n//\n// - In development, useReducer, useState, and useMemo change the dispatcher to\n// a different warning dispatcher (not ContextOnlyDispatcher) before invoking\n// the reducer and resets it right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are entering or exiting\n// a component render. We ignore this change by detecting these dispatchers as\n// different from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\n//\n// - When server rendering, React does not change the dispatcher before and\n// after each component render. It sets it once for before the first render\n// and once for after the last render. This means that we will not be able to\n// detect when we are entering or exiting a component render. This is fine\n// because we don't need to detect this for server rendering. A component\n// can't trigger async rerenders in SSR so we don't need to track signals.\n//\n// If a component updates a signal value while rendering during SSR, we will\n// not rerender the component because the signal value will synchronously\n// change so all reads of the signal further down the tree will see the new\n// value.\n\n/*\nBelow is a state machine definition for transitions between the various\ndispatchers in React's prod build. (It does not include dev time warning\ndispatchers which are just always ignored).\n\nENTER and EXIT suffixes indicates whether this ReactCurrentDispatcher transition\nsignals we are entering or exiting a component render, or if it doesn't signal a\nchange in the component rendering lifecyle (NOOP).\n\n```js\n// Paste this into https://stately.ai/viz to visualize the state machine.\nimport { createMachine } from \"xstate\";\n\n// ENTER, EXIT, NOOP suffixes indicates whether this ReactCurrentDispatcher\n// transition signals we are entering or exiting a component render, or\n// if it doesn't signal a change in the component rendering lifecyle (NOOP).\n\nconst dispatcherMachinePROD = createMachine({\n\tid: \"ReactCurrentDispatcher_PROD\",\n\tinitial: \"null\",\n\tstates: {\n\t\tnull: {\n\t\t\ton: {\n\t\t\t\tpushDispatcher: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tContextOnlyDispatcher: {\n\t\t\ton: {\n\t\t\t\trenderWithHooks_Mount_ENTER: \"HooksDispatcherOnMount\",\n\t\t\t\trenderWithHooks_Update_ENTER: \"HooksDispatcherOnUpdate\",\n\t\t\t\tpushDispatcher_NOOP: \"ContextOnlyDispatcher\",\n\t\t\t\tpopDispatcher_NOOP: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnMount: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnUpdate: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tuse_ResumeSuspensedMount_NOOP: \"HooksDispatcherOnMount\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnRerender: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t},\n});\n```\n*/\n\nexport let isAutoSignalTrackingInstalled = false;\n\nlet store: EffectStore | null = null;\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\n\nfunction installCurrentDispatcherHook() {\n\tisAutoSignalTrackingInstalled = true;\n\n\tObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\t\tget() {\n\t\t\treturn currentDispatcher;\n\t\t},\n\t\tset(nextDispatcher: ReactDispatcher) {\n\t\t\tif (lock) {\n\t\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\tif (\n\t\t\t\tisEnteringComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t\t) {\n\t\t\t\tlock = true;\n\t\t\t\tstore = _useSignalsImplementation();\n\t\t\t\tlock = false;\n\t\t\t} else if (\n\t\t\t\tisExitingComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t\t) {\n\t\t\t\tstore?.f();\n\t\t\t\tstore = null;\n\t\t\t}\n\t\t},\n\t});\n}\n\ntype DispatcherType = number;\nconst ContextOnlyDispatcherType = 1 << 0;\nconst WarningDispatcherType = 1 << 1;\nconst MountDispatcherType = 1 << 2;\nconst UpdateDispatcherType = 1 << 3;\nconst RerenderDispatcherType = 1 << 4;\nconst ServerDispatcherType = 1 << 5;\nconst BrowserClientDispatcherType =\n\tMountDispatcherType | UpdateDispatcherType | RerenderDispatcherType;\n\nconst dispatcherTypeCache = new Map<ReactDispatcher, DispatcherType>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): DispatcherType {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. This dispatcher is the only\n\t// dispatcher where useReducer and useEffect will have the same\n\t// implementation.\n\tlet type: DispatcherType;\n\tconst useCallbackImpl = dispatcher.useCallback.toString();\n\tif (dispatcher.useReducer === dispatcher.useEffect) {\n\t\ttype = ContextOnlyDispatcherType;\n\n\t\t// @ts-expect-error When server rendering, useEffect and useImperativeHandle\n\t\t// are both set to noop functions and so have the same implementation.\n\t} else if (dispatcher.useEffect === dispatcher.useImperativeHandle) {\n\t\ttype = ServerDispatcherType;\n\t} else if (/Invalid/.test(useCallbackImpl)) {\n\t\t// We first check for warning dispatchers because they would also pass some\n\t\t// of the checks below.\n\t\ttype = WarningDispatcherType;\n\t} else if (\n\t\t// The development mount dispatcher invokes a function called\n\t\t// `mountCallback` whereas the development update/re-render dispatcher\n\t\t// invokes a function called `updateCallback`. Use that difference to\n\t\t// determine if we are in a mount or update-like dispatcher in development.\n\t\t// The production mount dispatcher defines an array of the form [callback,\n\t\t// deps] whereas update/re-render dispatchers read the array using array\n\t\t// indices (e.g. `[0]` and `[1]`). Use those differences to determine if we\n\t\t// are in a mount or update-like dispatcher in production.\n\t\t/updateCallback/.test(useCallbackImpl) ||\n\t\t(/\\[0\\]/.test(useCallbackImpl) && /\\[1\\]/.test(useCallbackImpl))\n\t) {\n\t\t// The update and rerender dispatchers have different implementations for\n\t\t// useReducer. We'll check it's implementation to determine if this is the\n\t\t// rerender or update dispatcher.\n\t\tlet useReducerImpl = dispatcher.useReducer.toString();\n\t\tif (\n\t\t\t// The development rerender dispatcher invokes a function called\n\t\t\t// `rerenderReducer` whereas the update dispatcher invokes a function\n\t\t\t// called `updateReducer`. The production rerender dispatcher returns an\n\t\t\t// array of the form `[state, dispatch]` whereas the update dispatcher\n\t\t\t// returns an array of `[fiber.memoizedState, dispatch]` so we check the\n\t\t\t// return statement in the implementation of useReducer to differentiate\n\t\t\t// between the two.\n\t\t\t/rerenderReducer/.test(useReducerImpl) ||\n\t\t\t/return\\s*\\[\\w+,/.test(useReducerImpl)\n\t\t) {\n\t\t\ttype = RerenderDispatcherType;\n\t\t} else {\n\t\t\ttype = UpdateDispatcherType;\n\t\t}\n\t} else {\n\t\ttype = MountDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction isEnteringComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\tif (\n\t\tcurrentDispatcherType & ContextOnlyDispatcherType &&\n\t\tnextDispatcherType & BrowserClientDispatcherType\n\t) {\n\t\t// ## Mount or update (ContextOnlyDispatcher -> ValidDispatcher (Mount or Update))\n\t\t//\n\t\t// If the current dispatcher is the ContextOnlyDispatcher and the next\n\t\t// dispatcher is a valid dispatcher, we are entering a component render.\n\t\treturn true;\n\t} else if (\n\t\tcurrentDispatcherType & WarningDispatcherType ||\n\t\tnextDispatcherType & WarningDispatcherType\n\t) {\n\t\t// ## Warning dispatcher\n\t\t//\n\t\t// If the current dispatcher or next dispatcher is an warning dispatcher,\n\t\t// we are not entering a component render. The current warning dispatchers\n\t\t// are used to warn when hooks are nested improperly and do not indicate\n\t\t// entering a new component render.\n\t\treturn false;\n\t} else if (nextDispatcherType & RerenderDispatcherType) {\n\t\t// Any transition into the rerender dispatcher is the beginning of a\n\t\t// component render, so we should invoke our hooks. Details below.\n\t\t//\n\t\t// ## In-place rerendering (e.g. Mount -> Rerender)\n\t\t//\n\t\t// If we are transitioning from the mount, update, or rerender dispatcher to\n\t\t// the rerender dispatcher (e.g. HooksDispatcherOnMount to\n\t\t// HooksDispatcherOnRerender), then this component is rerendering due to\n\t\t// calling setState inside of its function body. We are re-entering a\n\t\t// component's render method and so we should re-invoke our hooks.\n\t\treturn true;\n\t} else {\n\t\t// ## Resuming suspended mount edge case (Update -> Mount)\n\t\t//\n\t\t// If we are transitioning from the update dispatcher to the mount\n\t\t// dispatcher, then this component is using the `use` hook and is resuming\n\t\t// from a mount. We should not re-invoke our hooks in this situation since\n\t\t// we are not entering a new component render, but instead continuing a\n\t\t// previous render.\n\t\t//\n\t\t// ## Other transitions\n\t\t//\n\t\t// For example, Mount -> Mount, Update -> Update, Mount -> Update, any\n\t\t// transition in and out of invalid dispatchers.\n\t\t//\n\t\t// There is no known transition for the following transitions so we default\n\t\t// to not triggering a re-enter of the component.\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnMount\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnUpdate\n\t\t// - HooksDispatcherOnUpdate -> HooksDispatcherOnUpdate\n\t\treturn false;\n\t}\n}\n\n/**\n * We are exiting a component render if the current dispatcher is a valid\n * dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n */\nfunction isExitingComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\treturn Boolean(\n\t\tcurrentDispatcherType & BrowserClientDispatcherType &&\n\t\t\tnextDispatcherType & ContextOnlyDispatcherType\n\t);\n}\n\ninterface JsxRuntimeModule {\n\tjsx?(type: any, ...rest: any[]): unknown;\n\tjsxs?(type: any, ...rest: any[]): unknown;\n\tjsxDEV?(type: any, ...rest: any[]): unknown;\n}\n\nexport function installJSXHooks() {\n\tconst JsxPro: JsxRuntimeModule = jsxRuntime;\n\tconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n\t/**\n\t * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n\t * so we need to wrap it regardless.\n\t *\n\t * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n\t * include both, so one of them will be set with `undefined` values.\n\t */\n\tReact.createElement = wrapJsx(React.createElement);\n\tJsxDev.jsx && /* */ (JsxDev.jsx = wrapJsx(JsxDev.jsx));\n\tJsxPro.jsx && /* */ (JsxPro.jsx = wrapJsx(JsxPro.jsx));\n\tJsxDev.jsxs && /* */ (JsxDev.jsxs = wrapJsx(JsxDev.jsxs));\n\tJsxPro.jsxs && /* */ (JsxPro.jsxs = wrapJsx(JsxPro.jsxs));\n\tJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = wrapJsx(JsxDev.jsxDEV));\n\tJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = wrapJsx(JsxPro.jsxDEV));\n}\n\nexport function installAutoSignalTracking() {\n\tinstallCurrentDispatcherHook();\n\tinstallJSXHooks();\n}\n","import {\n\tsignal,\n\tcomputed,\n\teffect,\n\tSignal,\n\tReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useRef, useMemo, useEffect } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport { isAutoSignalTrackingInstalled } from \"./auto\";\n\nexport { installAutoSignalTracking } from \"./auto\";\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst noop = () => {};\n\nexport function wrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst symDispose: unique symbol =\n\t(Symbol as any).dispose || Symbol.for(\"Symbol.dispose\");\n\ninterface Effect {\n\t_sources: object | undefined;\n\t_start(): () => void;\n\t_callback(): void;\n\t_dispose(): void;\n}\n\nexport interface EffectStore {\n\teffect: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n\t/** finishEffect - stop tracking the signals used in this component */\n\tf(): void;\n\t[symDispose](): void;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentStore(store?: EffectStore) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = store && store.effect._start();\n}\n\nconst clearCurrentStore = () => setCurrentStore();\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://react.dev/reference/react/useSyncExternalStore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet effectInstance!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\teffectInstance = this;\n\t});\n\teffectInstance._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\teffect: effectInstance,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t\tf() {\n\t\t\tclearCurrentStore();\n\t\t},\n\t\t[symDispose]() {\n\t\t\tclearCurrentStore();\n\t\t},\n\t};\n}\n\nfunction createEmptyEffectStore(): EffectStore {\n\treturn {\n\t\teffect: {\n\t\t\t_sources: undefined,\n\t\t\t_callback() {},\n\t\t\t_start() {\n\t\t\t\treturn noop;\n\t\t\t},\n\t\t\t_dispose() {},\n\t\t},\n\t\tsubscribe() {\n\t\t\treturn noop;\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn 0;\n\t\t},\n\t\tf() {},\n\t\t[symDispose]() {},\n\t};\n}\n\nconst emptyEffectStore = createEmptyEffectStore();\n\nlet finalCleanup: Promise<void> | undefined;\nconst _queueMicroTask = Promise.prototype.then.bind(Promise.resolve());\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change.\n */\nexport function _useSignalsImplementation(): EffectStore {\n\tclearCurrentStore();\n\tif (!finalCleanup) {\n\t\tfinalCleanup = _queueMicroTask(() => {\n\t\t\tfinalCleanup = undefined;\n\t\t\tclearCurrentStore();\n\t\t});\n\t}\n\n\tconst storeRef = useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\tsetCurrentStore(store);\n\n\treturn store;\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node or JSX.\n */\nfunction SignalValue({ data }: { data: Signal }) {\n\tconst store = useSignals();\n\ttry {\n\t\treturn data.value;\n\t} finally {\n\t\tstore.f();\n\t}\n}\n\n// Decorate Signals so React renders them as <SignalValue> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignals(): EffectStore {\n\tif (isAutoSignalTrackingInstalled) return emptyEffectStore;\n\treturn _useSignalsImplementation();\n}\n\nexport function useSignal<T>(value: T): Signal<T> {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T): ReadonlySignal<T> {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)): void {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n","import {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n} from \"@preact/signals-core\";\nimport type { ReactElement } from \"react\";\nimport {\n\tuseSignal,\n\tuseComputed,\n\tuseSignalEffect,\n\tinstallAutoSignalTracking,\n} from \"../runtime/src/index\"; // TODO: This duplicates runtime code between main and sub runtime packages\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuseSignal,\n\tuseComputed,\n\tuseSignalEffect,\n\tuntracked,\n};\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\ninstallAutoSignalTracking();\n"],"names":["signalsCore","require","React","index_js","jsxRuntime","jsxRuntimeDev","_interopDefaultLegacy","e","default","React__default","jsxRuntime__default","jsxRuntimeDev__default","isAutoSignalTrackingInstalled","store","lock","currentDispatcher","dispatcherTypeCache","Map","getDispatcherType","dispatcher","type","cached","get","undefined","useCallbackImpl","useCallback","toString","useReducer","useEffect","useImperativeHandle","test","useReducerImpl","set","Empty","ReactElemType","Symbol","noop","wrapJsx","jsx","props","i","v","Signal","value","call","apply","concat","slice","arguments","finishUpdate","symDispose","dispose","setCurrentStore","effect","_start","_ref2","finalCleanup","clearCurrentStore","emptyEffectStore","_sources","_callback","_dispose","subscribe","getSnapshot","f","_queueMicroTask","Promise","prototype","then","bind","resolve","_useSignalsImplementation","storeRef","useRef","current","_ref","effectInstance","onChangeNotifyReact","version","unsubscribe","this","onStoreChange","createEffectStore","useSyncExternalStore","Object","defineProperties","$$typeof","configurable","_ref3","data","useSignals","ref","defineProperty","ReactInternals","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","nextDispatcher","currentDispatcherType","nextDispatcherType","MountDispatcherType","isEnteringComponentRender","isExitingComponentRender","Boolean","_store","installCurrentDispatcherHook","JsxPro","JsxDev","createElement","jsxs","jsxDEV","installJSXHooks","installAutoSignalTracking","exports","batch","computed","signal","untracked","useComputed","compute","$compute","useMemo","useSignal","useSignalEffect","cb","callback"],"mappings":"AAoJO,IAAAA,EAAAC,QAAA,wBAAAC,EAAAD,QAAA,SAAAE,EAAAF,QAAA,yCAAAG,EAAAH,QAAA,qBAAAI,EAAAJ,QAAA,yBAAA,SAAAK,EAAAC,GAAA,OAAAA,GAAA,iBAAAA,GAAA,YAAAA,EAAAA,EAAAC,QAAAD,CAAA,CAAA,IAAAE,eAAAH,EAAAJ,GAAAQ,eAAAJ,EAAAF,GAAAO,eAAAL,EAAAD,GAAIO,GAAgC,EAEvCC,EAA4B,KAC5BC,GAAO,EACPC,EAA4C,KA+C1CC,EAAsB,IAAIC,IAChC,SAASC,EAAkBC,GAE1B,IAAKA,EAAY,OAZgB,EAcjC,IAOIC,EAPEC,EAASL,EAAoBM,IAAIH,GACvC,QAAeI,IAAXF,EAAsB,OAAOA,EAOjC,IAAMG,E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AAAiH,MAAAD,QAAAE,SAAAlH,EAAAkH,SAAAF,QAAA3D,OAAArD,EAAAqD,OAAA2D,QAAAG,OAAAnH,EAAAmH,OAAAH,QAAAI,UAAApH,EAAAoH,UAAAJ,QAAAK,YD4KX,SAAeC,GAC9B,IAAMC,EAAW9C,EAAAA,OAAO6C,GACxBC,EAAS7C,QAAU4C,EACnB,OAAOE,EAAAA,QAAQ,kBAAMN,EAAAA,SAAY,WAAM,OAAAK,EAAS7C,SAAS,EAAC,EAAEzC,EAC7D,EChL2B+E,QAAAS,UDwKX,SAAa9E,GAC5B,OAAO6E,EAAAA,QAAQ,WAAA,OAAML,EAAAA,OAAUxE,EAAM,EAAEV,EACxC,EC1K2B+E,QAAAU,gBDkLX,SAAgBC,GAC/B,IAAMC,EAAWnD,EAAAA,OAAOkD,GACxBC,EAASlD,QAAUiD,EAEnB/F,YAAU,WACT,OAAOyB,SAAO,kBAAMuE,EAASlD,SAAS,EACvC,EAAGzC,EACJ"}
|
|
1
|
+
{"version":3,"file":"signals.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/signals.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@preact/signals-core"),require("@preact/signals-react/runtime")):"function"==typeof define&&define.amd?define(["exports","@preact/signals-core","@preact/signals-react/runtime"],t):t((e||self).reactSignals={},e.preactSignalsCore,e.reactSignalsRuntime)}(this,function(e,t,i){e.Signal=t.Signal;e.batch=t.batch;e.computed=t.computed;e.effect=t.effect;e.signal=t.signal;e.untracked=t.untracked;e.useComputed=i.useComputed;e.useSignal=i.useSignal;e.useSignalEffect=i.useSignalEffect});//# sourceMappingURL=signals.min.js.map
|
package/dist/signals.min.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.min.js","sources":["../runtime/src/auto.ts","../runtime/src/index.ts","../src/index.ts"],"sourcesContent":["import {\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { EffectStore, wrapJsx, _useSignalsImplementation } from \"./index\";\n\nexport interface ReactDispatcher {\n\tuseRef: typeof React.useRef;\n\tuseCallback: typeof React.useCallback;\n\tuseReducer: typeof React.useReducer;\n\tuseSyncExternalStore: typeof React.useSyncExternalStore;\n\tuseEffect: typeof React.useEffect;\n\tuseImperativeHandle: typeof React.useImperativeHandle;\n}\n\n// In order for signals to work in React, we need to observe what signals a\n// component uses while rendering. To do this, we need to know when a component\n// is rendering. To do this, we watch the transition of the\n// ReactCurrentDispatcher to know when a component is rerendering.\n//\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to an instance that doesn't warn or error\n// and contains the implementations of all hooks. Right after React finishes\n// rendering a component, the dispatcher is set to the erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a \"valid\" dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an Signal effect and manually starting the Signal effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some additional complexities to be aware of:\n// - If a component calls `setState` while rendering, React will re-render the\n// component immediately. Before triggering the re-render, React will change\n// the dispatcher to the HooksDispatcherOnRerender. When we transition to this\n// rerendering adapter, we need to re-trigger our hooks to keep the order of\n// hooks the same for every render of a component.\n//\n// - In development, useReducer, useState, and useMemo change the dispatcher to\n// a different warning dispatcher (not ContextOnlyDispatcher) before invoking\n// the reducer and resets it right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are entering or exiting\n// a component render. We ignore this change by detecting these dispatchers as\n// different from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\n//\n// - When server rendering, React does not change the dispatcher before and\n// after each component render. It sets it once for before the first render\n// and once for after the last render. This means that we will not be able to\n// detect when we are entering or exiting a component render. This is fine\n// because we don't need to detect this for server rendering. A component\n// can't trigger async rerenders in SSR so we don't need to track signals.\n//\n// If a component updates a signal value while rendering during SSR, we will\n// not rerender the component because the signal value will synchronously\n// change so all reads of the signal further down the tree will see the new\n// value.\n\n/*\nBelow is a state machine definition for transitions between the various\ndispatchers in React's prod build. (It does not include dev time warning\ndispatchers which are just always ignored).\n\nENTER and EXIT suffixes indicates whether this ReactCurrentDispatcher transition\nsignals we are entering or exiting a component render, or if it doesn't signal a\nchange in the component rendering lifecyle (NOOP).\n\n```js\n// Paste this into https://stately.ai/viz to visualize the state machine.\nimport { createMachine } from \"xstate\";\n\n// ENTER, EXIT, NOOP suffixes indicates whether this ReactCurrentDispatcher\n// transition signals we are entering or exiting a component render, or\n// if it doesn't signal a change in the component rendering lifecyle (NOOP).\n\nconst dispatcherMachinePROD = createMachine({\n\tid: \"ReactCurrentDispatcher_PROD\",\n\tinitial: \"null\",\n\tstates: {\n\t\tnull: {\n\t\t\ton: {\n\t\t\t\tpushDispatcher: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tContextOnlyDispatcher: {\n\t\t\ton: {\n\t\t\t\trenderWithHooks_Mount_ENTER: \"HooksDispatcherOnMount\",\n\t\t\t\trenderWithHooks_Update_ENTER: \"HooksDispatcherOnUpdate\",\n\t\t\t\tpushDispatcher_NOOP: \"ContextOnlyDispatcher\",\n\t\t\t\tpopDispatcher_NOOP: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnMount: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnUpdate: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tuse_ResumeSuspensedMount_NOOP: \"HooksDispatcherOnMount\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnRerender: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t},\n});\n```\n*/\n\nexport let isAutoSignalTrackingInstalled = false;\n\nlet store: EffectStore | null = null;\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\n\nfunction installCurrentDispatcherHook() {\n\tisAutoSignalTrackingInstalled = true;\n\n\tObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\t\tget() {\n\t\t\treturn currentDispatcher;\n\t\t},\n\t\tset(nextDispatcher: ReactDispatcher) {\n\t\t\tif (lock) {\n\t\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\tif (\n\t\t\t\tisEnteringComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t\t) {\n\t\t\t\tlock = true;\n\t\t\t\tstore = _useSignalsImplementation();\n\t\t\t\tlock = false;\n\t\t\t} else if (\n\t\t\t\tisExitingComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t\t) {\n\t\t\t\tstore?.f();\n\t\t\t\tstore = null;\n\t\t\t}\n\t\t},\n\t});\n}\n\ntype DispatcherType = number;\nconst ContextOnlyDispatcherType = 1 << 0;\nconst WarningDispatcherType = 1 << 1;\nconst MountDispatcherType = 1 << 2;\nconst UpdateDispatcherType = 1 << 3;\nconst RerenderDispatcherType = 1 << 4;\nconst ServerDispatcherType = 1 << 5;\nconst BrowserClientDispatcherType =\n\tMountDispatcherType | UpdateDispatcherType | RerenderDispatcherType;\n\nconst dispatcherTypeCache = new Map<ReactDispatcher, DispatcherType>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): DispatcherType {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. This dispatcher is the only\n\t// dispatcher where useReducer and useEffect will have the same\n\t// implementation.\n\tlet type: DispatcherType;\n\tconst useCallbackImpl = dispatcher.useCallback.toString();\n\tif (dispatcher.useReducer === dispatcher.useEffect) {\n\t\ttype = ContextOnlyDispatcherType;\n\n\t\t// @ts-expect-error When server rendering, useEffect and useImperativeHandle\n\t\t// are both set to noop functions and so have the same implementation.\n\t} else if (dispatcher.useEffect === dispatcher.useImperativeHandle) {\n\t\ttype = ServerDispatcherType;\n\t} else if (/Invalid/.test(useCallbackImpl)) {\n\t\t// We first check for warning dispatchers because they would also pass some\n\t\t// of the checks below.\n\t\ttype = WarningDispatcherType;\n\t} else if (\n\t\t// The development mount dispatcher invokes a function called\n\t\t// `mountCallback` whereas the development update/re-render dispatcher\n\t\t// invokes a function called `updateCallback`. Use that difference to\n\t\t// determine if we are in a mount or update-like dispatcher in development.\n\t\t// The production mount dispatcher defines an array of the form [callback,\n\t\t// deps] whereas update/re-render dispatchers read the array using array\n\t\t// indices (e.g. `[0]` and `[1]`). Use those differences to determine if we\n\t\t// are in a mount or update-like dispatcher in production.\n\t\t/updateCallback/.test(useCallbackImpl) ||\n\t\t(/\\[0\\]/.test(useCallbackImpl) && /\\[1\\]/.test(useCallbackImpl))\n\t) {\n\t\t// The update and rerender dispatchers have different implementations for\n\t\t// useReducer. We'll check it's implementation to determine if this is the\n\t\t// rerender or update dispatcher.\n\t\tlet useReducerImpl = dispatcher.useReducer.toString();\n\t\tif (\n\t\t\t// The development rerender dispatcher invokes a function called\n\t\t\t// `rerenderReducer` whereas the update dispatcher invokes a function\n\t\t\t// called `updateReducer`. The production rerender dispatcher returns an\n\t\t\t// array of the form `[state, dispatch]` whereas the update dispatcher\n\t\t\t// returns an array of `[fiber.memoizedState, dispatch]` so we check the\n\t\t\t// return statement in the implementation of useReducer to differentiate\n\t\t\t// between the two.\n\t\t\t/rerenderReducer/.test(useReducerImpl) ||\n\t\t\t/return\\s*\\[\\w+,/.test(useReducerImpl)\n\t\t) {\n\t\t\ttype = RerenderDispatcherType;\n\t\t} else {\n\t\t\ttype = UpdateDispatcherType;\n\t\t}\n\t} else {\n\t\ttype = MountDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction isEnteringComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\tif (\n\t\tcurrentDispatcherType & ContextOnlyDispatcherType &&\n\t\tnextDispatcherType & BrowserClientDispatcherType\n\t) {\n\t\t// ## Mount or update (ContextOnlyDispatcher -> ValidDispatcher (Mount or Update))\n\t\t//\n\t\t// If the current dispatcher is the ContextOnlyDispatcher and the next\n\t\t// dispatcher is a valid dispatcher, we are entering a component render.\n\t\treturn true;\n\t} else if (\n\t\tcurrentDispatcherType & WarningDispatcherType ||\n\t\tnextDispatcherType & WarningDispatcherType\n\t) {\n\t\t// ## Warning dispatcher\n\t\t//\n\t\t// If the current dispatcher or next dispatcher is an warning dispatcher,\n\t\t// we are not entering a component render. The current warning dispatchers\n\t\t// are used to warn when hooks are nested improperly and do not indicate\n\t\t// entering a new component render.\n\t\treturn false;\n\t} else if (nextDispatcherType & RerenderDispatcherType) {\n\t\t// Any transition into the rerender dispatcher is the beginning of a\n\t\t// component render, so we should invoke our hooks. Details below.\n\t\t//\n\t\t// ## In-place rerendering (e.g. Mount -> Rerender)\n\t\t//\n\t\t// If we are transitioning from the mount, update, or rerender dispatcher to\n\t\t// the rerender dispatcher (e.g. HooksDispatcherOnMount to\n\t\t// HooksDispatcherOnRerender), then this component is rerendering due to\n\t\t// calling setState inside of its function body. We are re-entering a\n\t\t// component's render method and so we should re-invoke our hooks.\n\t\treturn true;\n\t} else {\n\t\t// ## Resuming suspended mount edge case (Update -> Mount)\n\t\t//\n\t\t// If we are transitioning from the update dispatcher to the mount\n\t\t// dispatcher, then this component is using the `use` hook and is resuming\n\t\t// from a mount. We should not re-invoke our hooks in this situation since\n\t\t// we are not entering a new component render, but instead continuing a\n\t\t// previous render.\n\t\t//\n\t\t// ## Other transitions\n\t\t//\n\t\t// For example, Mount -> Mount, Update -> Update, Mount -> Update, any\n\t\t// transition in and out of invalid dispatchers.\n\t\t//\n\t\t// There is no known transition for the following transitions so we default\n\t\t// to not triggering a re-enter of the component.\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnMount\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnUpdate\n\t\t// - HooksDispatcherOnUpdate -> HooksDispatcherOnUpdate\n\t\treturn false;\n\t}\n}\n\n/**\n * We are exiting a component render if the current dispatcher is a valid\n * dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n */\nfunction isExitingComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\treturn Boolean(\n\t\tcurrentDispatcherType & BrowserClientDispatcherType &&\n\t\t\tnextDispatcherType & ContextOnlyDispatcherType\n\t);\n}\n\ninterface JsxRuntimeModule {\n\tjsx?(type: any, ...rest: any[]): unknown;\n\tjsxs?(type: any, ...rest: any[]): unknown;\n\tjsxDEV?(type: any, ...rest: any[]): unknown;\n}\n\nexport function installJSXHooks() {\n\tconst JsxPro: JsxRuntimeModule = jsxRuntime;\n\tconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n\t/**\n\t * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n\t * so we need to wrap it regardless.\n\t *\n\t * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n\t * include both, so one of them will be set with `undefined` values.\n\t */\n\tReact.createElement = wrapJsx(React.createElement);\n\tJsxDev.jsx && /* */ (JsxDev.jsx = wrapJsx(JsxDev.jsx));\n\tJsxPro.jsx && /* */ (JsxPro.jsx = wrapJsx(JsxPro.jsx));\n\tJsxDev.jsxs && /* */ (JsxDev.jsxs = wrapJsx(JsxDev.jsxs));\n\tJsxPro.jsxs && /* */ (JsxPro.jsxs = wrapJsx(JsxPro.jsxs));\n\tJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = wrapJsx(JsxDev.jsxDEV));\n\tJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = wrapJsx(JsxPro.jsxDEV));\n}\n\nexport function installAutoSignalTracking() {\n\tinstallCurrentDispatcherHook();\n\tinstallJSXHooks();\n}\n","import {\n\tsignal,\n\tcomputed,\n\teffect,\n\tSignal,\n\tReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useRef, useMemo, useEffect } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport { isAutoSignalTrackingInstalled } from \"./auto\";\n\nexport { installAutoSignalTracking } from \"./auto\";\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst noop = () => {};\n\nexport function wrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst symDispose: unique symbol =\n\t(Symbol as any).dispose || Symbol.for(\"Symbol.dispose\");\n\ninterface Effect {\n\t_sources: object | undefined;\n\t_start(): () => void;\n\t_callback(): void;\n\t_dispose(): void;\n}\n\nexport interface EffectStore {\n\teffect: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n\t/** finishEffect - stop tracking the signals used in this component */\n\tf(): void;\n\t[symDispose](): void;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentStore(store?: EffectStore) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = store && store.effect._start();\n}\n\nconst clearCurrentStore = () => setCurrentStore();\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://react.dev/reference/react/useSyncExternalStore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet effectInstance!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\teffectInstance = this;\n\t});\n\teffectInstance._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\teffect: effectInstance,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t\tf() {\n\t\t\tclearCurrentStore();\n\t\t},\n\t\t[symDispose]() {\n\t\t\tclearCurrentStore();\n\t\t},\n\t};\n}\n\nfunction createEmptyEffectStore(): EffectStore {\n\treturn {\n\t\teffect: {\n\t\t\t_sources: undefined,\n\t\t\t_callback() {},\n\t\t\t_start() {\n\t\t\t\treturn noop;\n\t\t\t},\n\t\t\t_dispose() {},\n\t\t},\n\t\tsubscribe() {\n\t\t\treturn noop;\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn 0;\n\t\t},\n\t\tf() {},\n\t\t[symDispose]() {},\n\t};\n}\n\nconst emptyEffectStore = createEmptyEffectStore();\n\nlet finalCleanup: Promise<void> | undefined;\nconst _queueMicroTask = Promise.prototype.then.bind(Promise.resolve());\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change.\n */\nexport function _useSignalsImplementation(): EffectStore {\n\tclearCurrentStore();\n\tif (!finalCleanup) {\n\t\tfinalCleanup = _queueMicroTask(() => {\n\t\t\tfinalCleanup = undefined;\n\t\t\tclearCurrentStore();\n\t\t});\n\t}\n\n\tconst storeRef = useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\tsetCurrentStore(store);\n\n\treturn store;\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node or JSX.\n */\nfunction SignalValue({ data }: { data: Signal }) {\n\tconst store = useSignals();\n\ttry {\n\t\treturn data.value;\n\t} finally {\n\t\tstore.f();\n\t}\n}\n\n// Decorate Signals so React renders them as <SignalValue> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignals(): EffectStore {\n\tif (isAutoSignalTrackingInstalled) return emptyEffectStore;\n\treturn _useSignalsImplementation();\n}\n\nexport function useSignal<T>(value: T): Signal<T> {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T): ReadonlySignal<T> {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)): void {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n","import {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n} from \"@preact/signals-core\";\nimport type { ReactElement } from \"react\";\nimport {\n\tuseSignal,\n\tuseComputed,\n\tuseSignalEffect,\n\tinstallAutoSignalTracking,\n} from \"../runtime/src/index\"; // TODO: This duplicates runtime code between main and sub runtime packages\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuseSignal,\n\tuseComputed,\n\tuseSignalEffect,\n\tuntracked,\n};\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\ninstallAutoSignalTracking();\n"],"names":["g","f","exports","module","require","define","amd","globalThis","self","reactSignals","preactSignalsCore","react","index_js","jsxRuntime","jsxRuntimeDev","this","signalsCore","React","_interopDefaultLegacy","e","default","React__default","jsxRuntime__default","jsxRuntimeDev__default","isAutoSignalTrackingInstalled","store","lock","currentDispatcher","dispatcherTypeCache","Map","getDispatcherType","dispatcher","type","cached","get","undefined","useCallbackImpl","useCallback","toString","useReducer","useEffect","useImperativeHandle","test","useReducerImpl","set","Empty","ReactElemType","Symbol","noop","wrapJsx","jsx","props","i","v","Signal","value","call","apply","concat","slice","arguments","finishUpdate","symDispose","dispose","setCurrentStore","effect","_start","_ref2","finalCleanup","clearCurrentStore","emptyEffectStore","_sources","_callback","_dispose","subscribe","getSnapshot","_queueMicroTask","Promise","prototype","then","bind","resolve","_useSignalsImplementation","storeRef","useRef","current","_ref","effectInstance","onChangeNotifyReact","version","unsubscribe","onStoreChange","createEffectStore","useSyncExternalStore","Object","defineProperties","$$typeof","configurable","_ref3","data","useSignals","ref","defineProperty","ReactInternals","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","nextDispatcher","currentDispatcherType","nextDispatcherType","MountDispatcherType","isEnteringComponentRender","isExitingComponentRender","Boolean","_store","installCurrentDispatcherHook","JsxPro","JsxDev","createElement","jsxs","jsxDEV","installJSXHooks","installAutoSignalTracking","batch","computed","signal","untracked","useComputed","compute","$compute","useMemo","useSignal","useSignalEffect","cb","callback"],"mappings":"CAoJO,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,QAAAE,QAAA,wBAAAA,QAAA,SAAAA,QAAA,yCAAAA,QAAA,qBAAAA,QAAA,0BAAA,mBAAAC,QAAAA,OAAAC,IAAAD,OAAA,CAAA,UAAA,uBAAA,QAAA,wCAAA,oBAAA,yBAAAJ,GAAAA,GAAAD,EAAA,oBAAAO,WAAAA,WAAAP,GAAAQ,MAAAC,aAAA,CAAA,EAAAT,EAAAU,kBAAAV,EAAAW,MAAAX,EAAAY,SAAAZ,EAAAa,WAAAb,EAAAc,cAAA,CAAA,CAAAC,KAAA,SAAAb,EAAAc,EAAAC,EAAAL,EAAAC,EAAAC,GAAA,SAAAI,EAAAC,GAAA,OAAAA,GAAA,iBAAAA,GAAA,YAAAA,EAAAA,EAAAC,QAAAD,CAAA,CAAA,IAAAE,eAAAH,EAAAD,GAAAK,eAAAJ,EAAAL,GAAAU,eAAAL,EAAAJ,GAAIU,GAAgC,EAEvCC,EAA4B,KAC5BC,GAAO,EACPC,EAA4C,KA+C1CC,EAAsB,IAAIC,IAChC,SAASC,EAAkBC,GAE1B,IAAKA,EAAY,OAZgB,EAcjC,IAOIC,EAPEC,EAASL,EAAoBM,IAAIH,GACvC,QAAeI,IAAXF,EAAsB,O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C,OAAApD,EAAAwH,MAAA1G,EAAA0G,MAAAxH,EAAAyH,SAAA3G,EAAA2G,SAAAzH,EAAA+D,OAAAjD,EAAAiD,OAAA/D,EAAA0H,OAAA5G,EAAA4G,OAAA1H,EAAA2H,UAAA7G,EAAA6G,UAAA3H,EAAA4H,YD4KX,SAAeC,GAC9B,IAAMC,EAAW5C,EAAAA,OAAO2C,GACxBC,EAAS3C,QAAU0C,EACnB,OAAOE,EAAAA,QAAQ,kBAAMN,EAAAA,SAAY,WAAM,OAAAK,EAAS3C,SAAS,EAAC,EAAExC,EAC7D,EChL2B3C,EAAAgI,UDwKX,SAAa3E,GAC5B,OAAO0E,EAAAA,QAAQ,WAAA,OAAML,EAAAA,OAAUrE,EAAM,EAAEV,EACxC,EC1K2B3C,EAAAiI,gBDkLX,SAAgBC,GAC/B,IAAMC,EAAWjD,EAAAA,OAAOgD,GACxBC,EAAShD,QAAU+C,EAEnB5F,YAAU,WACT,OAAOyB,SAAO,kBAAMoE,EAAShD,SAAS,EACvC,EAAGxC,EACJ,CCzL2B"}
|
|
1
|
+
{"version":3,"file":"signals.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/signals.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{Signal,batch,computed,effect,signal,untracked}from"@preact/signals-core";export{useComputed,useSignal,useSignalEffect}from"@preact/signals-react/runtime";//# sourceMappingURL=signals.mjs.map
|
package/dist/signals.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.mjs","sources":["../runtime/src/auto.ts","../runtime/src/index.ts","../src/index.ts"],"sourcesContent":["import {\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { EffectStore, wrapJsx, _useSignalsImplementation } from \"./index\";\n\nexport interface ReactDispatcher {\n\tuseRef: typeof React.useRef;\n\tuseCallback: typeof React.useCallback;\n\tuseReducer: typeof React.useReducer;\n\tuseSyncExternalStore: typeof React.useSyncExternalStore;\n\tuseEffect: typeof React.useEffect;\n\tuseImperativeHandle: typeof React.useImperativeHandle;\n}\n\n// In order for signals to work in React, we need to observe what signals a\n// component uses while rendering. To do this, we need to know when a component\n// is rendering. To do this, we watch the transition of the\n// ReactCurrentDispatcher to know when a component is rerendering.\n//\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to an instance that doesn't warn or error\n// and contains the implementations of all hooks. Right after React finishes\n// rendering a component, the dispatcher is set to the erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a \"valid\" dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an Signal effect and manually starting the Signal effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some additional complexities to be aware of:\n// - If a component calls `setState` while rendering, React will re-render the\n// component immediately. Before triggering the re-render, React will change\n// the dispatcher to the HooksDispatcherOnRerender. When we transition to this\n// rerendering adapter, we need to re-trigger our hooks to keep the order of\n// hooks the same for every render of a component.\n//\n// - In development, useReducer, useState, and useMemo change the dispatcher to\n// a different warning dispatcher (not ContextOnlyDispatcher) before invoking\n// the reducer and resets it right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are entering or exiting\n// a component render. We ignore this change by detecting these dispatchers as\n// different from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\n//\n// - When server rendering, React does not change the dispatcher before and\n// after each component render. It sets it once for before the first render\n// and once for after the last render. This means that we will not be able to\n// detect when we are entering or exiting a component render. This is fine\n// because we don't need to detect this for server rendering. A component\n// can't trigger async rerenders in SSR so we don't need to track signals.\n//\n// If a component updates a signal value while rendering during SSR, we will\n// not rerender the component because the signal value will synchronously\n// change so all reads of the signal further down the tree will see the new\n// value.\n\n/*\nBelow is a state machine definition for transitions between the various\ndispatchers in React's prod build. (It does not include dev time warning\ndispatchers which are just always ignored).\n\nENTER and EXIT suffixes indicates whether this ReactCurrentDispatcher transition\nsignals we are entering or exiting a component render, or if it doesn't signal a\nchange in the component rendering lifecyle (NOOP).\n\n```js\n// Paste this into https://stately.ai/viz to visualize the state machine.\nimport { createMachine } from \"xstate\";\n\n// ENTER, EXIT, NOOP suffixes indicates whether this ReactCurrentDispatcher\n// transition signals we are entering or exiting a component render, or\n// if it doesn't signal a change in the component rendering lifecyle (NOOP).\n\nconst dispatcherMachinePROD = createMachine({\n\tid: \"ReactCurrentDispatcher_PROD\",\n\tinitial: \"null\",\n\tstates: {\n\t\tnull: {\n\t\t\ton: {\n\t\t\t\tpushDispatcher: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tContextOnlyDispatcher: {\n\t\t\ton: {\n\t\t\t\trenderWithHooks_Mount_ENTER: \"HooksDispatcherOnMount\",\n\t\t\t\trenderWithHooks_Update_ENTER: \"HooksDispatcherOnUpdate\",\n\t\t\t\tpushDispatcher_NOOP: \"ContextOnlyDispatcher\",\n\t\t\t\tpopDispatcher_NOOP: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnMount: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnUpdate: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tuse_ResumeSuspensedMount_NOOP: \"HooksDispatcherOnMount\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnRerender: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t},\n});\n```\n*/\n\nexport let isAutoSignalTrackingInstalled = false;\n\nlet store: EffectStore | null = null;\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\n\nfunction installCurrentDispatcherHook() {\n\tisAutoSignalTrackingInstalled = true;\n\n\tObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\t\tget() {\n\t\t\treturn currentDispatcher;\n\t\t},\n\t\tset(nextDispatcher: ReactDispatcher) {\n\t\t\tif (lock) {\n\t\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\tif (\n\t\t\t\tisEnteringComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t\t) {\n\t\t\t\tlock = true;\n\t\t\t\tstore = _useSignalsImplementation();\n\t\t\t\tlock = false;\n\t\t\t} else if (\n\t\t\t\tisExitingComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t\t) {\n\t\t\t\tstore?.f();\n\t\t\t\tstore = null;\n\t\t\t}\n\t\t},\n\t});\n}\n\ntype DispatcherType = number;\nconst ContextOnlyDispatcherType = 1 << 0;\nconst WarningDispatcherType = 1 << 1;\nconst MountDispatcherType = 1 << 2;\nconst UpdateDispatcherType = 1 << 3;\nconst RerenderDispatcherType = 1 << 4;\nconst ServerDispatcherType = 1 << 5;\nconst BrowserClientDispatcherType =\n\tMountDispatcherType | UpdateDispatcherType | RerenderDispatcherType;\n\nconst dispatcherTypeCache = new Map<ReactDispatcher, DispatcherType>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): DispatcherType {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. This dispatcher is the only\n\t// dispatcher where useReducer and useEffect will have the same\n\t// implementation.\n\tlet type: DispatcherType;\n\tconst useCallbackImpl = dispatcher.useCallback.toString();\n\tif (dispatcher.useReducer === dispatcher.useEffect) {\n\t\ttype = ContextOnlyDispatcherType;\n\n\t\t// @ts-expect-error When server rendering, useEffect and useImperativeHandle\n\t\t// are both set to noop functions and so have the same implementation.\n\t} else if (dispatcher.useEffect === dispatcher.useImperativeHandle) {\n\t\ttype = ServerDispatcherType;\n\t} else if (/Invalid/.test(useCallbackImpl)) {\n\t\t// We first check for warning dispatchers because they would also pass some\n\t\t// of the checks below.\n\t\ttype = WarningDispatcherType;\n\t} else if (\n\t\t// The development mount dispatcher invokes a function called\n\t\t// `mountCallback` whereas the development update/re-render dispatcher\n\t\t// invokes a function called `updateCallback`. Use that difference to\n\t\t// determine if we are in a mount or update-like dispatcher in development.\n\t\t// The production mount dispatcher defines an array of the form [callback,\n\t\t// deps] whereas update/re-render dispatchers read the array using array\n\t\t// indices (e.g. `[0]` and `[1]`). Use those differences to determine if we\n\t\t// are in a mount or update-like dispatcher in production.\n\t\t/updateCallback/.test(useCallbackImpl) ||\n\t\t(/\\[0\\]/.test(useCallbackImpl) && /\\[1\\]/.test(useCallbackImpl))\n\t) {\n\t\t// The update and rerender dispatchers have different implementations for\n\t\t// useReducer. We'll check it's implementation to determine if this is the\n\t\t// rerender or update dispatcher.\n\t\tlet useReducerImpl = dispatcher.useReducer.toString();\n\t\tif (\n\t\t\t// The development rerender dispatcher invokes a function called\n\t\t\t// `rerenderReducer` whereas the update dispatcher invokes a function\n\t\t\t// called `updateReducer`. The production rerender dispatcher returns an\n\t\t\t// array of the form `[state, dispatch]` whereas the update dispatcher\n\t\t\t// returns an array of `[fiber.memoizedState, dispatch]` so we check the\n\t\t\t// return statement in the implementation of useReducer to differentiate\n\t\t\t// between the two.\n\t\t\t/rerenderReducer/.test(useReducerImpl) ||\n\t\t\t/return\\s*\\[\\w+,/.test(useReducerImpl)\n\t\t) {\n\t\t\ttype = RerenderDispatcherType;\n\t\t} else {\n\t\t\ttype = UpdateDispatcherType;\n\t\t}\n\t} else {\n\t\ttype = MountDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction isEnteringComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\tif (\n\t\tcurrentDispatcherType & ContextOnlyDispatcherType &&\n\t\tnextDispatcherType & BrowserClientDispatcherType\n\t) {\n\t\t// ## Mount or update (ContextOnlyDispatcher -> ValidDispatcher (Mount or Update))\n\t\t//\n\t\t// If the current dispatcher is the ContextOnlyDispatcher and the next\n\t\t// dispatcher is a valid dispatcher, we are entering a component render.\n\t\treturn true;\n\t} else if (\n\t\tcurrentDispatcherType & WarningDispatcherType ||\n\t\tnextDispatcherType & WarningDispatcherType\n\t) {\n\t\t// ## Warning dispatcher\n\t\t//\n\t\t// If the current dispatcher or next dispatcher is an warning dispatcher,\n\t\t// we are not entering a component render. The current warning dispatchers\n\t\t// are used to warn when hooks are nested improperly and do not indicate\n\t\t// entering a new component render.\n\t\treturn false;\n\t} else if (nextDispatcherType & RerenderDispatcherType) {\n\t\t// Any transition into the rerender dispatcher is the beginning of a\n\t\t// component render, so we should invoke our hooks. Details below.\n\t\t//\n\t\t// ## In-place rerendering (e.g. Mount -> Rerender)\n\t\t//\n\t\t// If we are transitioning from the mount, update, or rerender dispatcher to\n\t\t// the rerender dispatcher (e.g. HooksDispatcherOnMount to\n\t\t// HooksDispatcherOnRerender), then this component is rerendering due to\n\t\t// calling setState inside of its function body. We are re-entering a\n\t\t// component's render method and so we should re-invoke our hooks.\n\t\treturn true;\n\t} else {\n\t\t// ## Resuming suspended mount edge case (Update -> Mount)\n\t\t//\n\t\t// If we are transitioning from the update dispatcher to the mount\n\t\t// dispatcher, then this component is using the `use` hook and is resuming\n\t\t// from a mount. We should not re-invoke our hooks in this situation since\n\t\t// we are not entering a new component render, but instead continuing a\n\t\t// previous render.\n\t\t//\n\t\t// ## Other transitions\n\t\t//\n\t\t// For example, Mount -> Mount, Update -> Update, Mount -> Update, any\n\t\t// transition in and out of invalid dispatchers.\n\t\t//\n\t\t// There is no known transition for the following transitions so we default\n\t\t// to not triggering a re-enter of the component.\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnMount\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnUpdate\n\t\t// - HooksDispatcherOnUpdate -> HooksDispatcherOnUpdate\n\t\treturn false;\n\t}\n}\n\n/**\n * We are exiting a component render if the current dispatcher is a valid\n * dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n */\nfunction isExitingComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\treturn Boolean(\n\t\tcurrentDispatcherType & BrowserClientDispatcherType &&\n\t\t\tnextDispatcherType & ContextOnlyDispatcherType\n\t);\n}\n\ninterface JsxRuntimeModule {\n\tjsx?(type: any, ...rest: any[]): unknown;\n\tjsxs?(type: any, ...rest: any[]): unknown;\n\tjsxDEV?(type: any, ...rest: any[]): unknown;\n}\n\nexport function installJSXHooks() {\n\tconst JsxPro: JsxRuntimeModule = jsxRuntime;\n\tconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n\t/**\n\t * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n\t * so we need to wrap it regardless.\n\t *\n\t * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n\t * include both, so one of them will be set with `undefined` values.\n\t */\n\tReact.createElement = wrapJsx(React.createElement);\n\tJsxDev.jsx && /* */ (JsxDev.jsx = wrapJsx(JsxDev.jsx));\n\tJsxPro.jsx && /* */ (JsxPro.jsx = wrapJsx(JsxPro.jsx));\n\tJsxDev.jsxs && /* */ (JsxDev.jsxs = wrapJsx(JsxDev.jsxs));\n\tJsxPro.jsxs && /* */ (JsxPro.jsxs = wrapJsx(JsxPro.jsxs));\n\tJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = wrapJsx(JsxDev.jsxDEV));\n\tJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = wrapJsx(JsxPro.jsxDEV));\n}\n\nexport function installAutoSignalTracking() {\n\tinstallCurrentDispatcherHook();\n\tinstallJSXHooks();\n}\n","import {\n\tsignal,\n\tcomputed,\n\teffect,\n\tSignal,\n\tReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useRef, useMemo, useEffect } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport { isAutoSignalTrackingInstalled } from \"./auto\";\n\nexport { installAutoSignalTracking } from \"./auto\";\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst noop = () => {};\n\nexport function wrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst symDispose: unique symbol =\n\t(Symbol as any).dispose || Symbol.for(\"Symbol.dispose\");\n\ninterface Effect {\n\t_sources: object | undefined;\n\t_start(): () => void;\n\t_callback(): void;\n\t_dispose(): void;\n}\n\nexport interface EffectStore {\n\teffect: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n\t/** finishEffect - stop tracking the signals used in this component */\n\tf(): void;\n\t[symDispose](): void;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentStore(store?: EffectStore) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = store && store.effect._start();\n}\n\nconst clearCurrentStore = () => setCurrentStore();\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://react.dev/reference/react/useSyncExternalStore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet effectInstance!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\teffectInstance = this;\n\t});\n\teffectInstance._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\teffect: effectInstance,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t\tf() {\n\t\t\tclearCurrentStore();\n\t\t},\n\t\t[symDispose]() {\n\t\t\tclearCurrentStore();\n\t\t},\n\t};\n}\n\nfunction createEmptyEffectStore(): EffectStore {\n\treturn {\n\t\teffect: {\n\t\t\t_sources: undefined,\n\t\t\t_callback() {},\n\t\t\t_start() {\n\t\t\t\treturn noop;\n\t\t\t},\n\t\t\t_dispose() {},\n\t\t},\n\t\tsubscribe() {\n\t\t\treturn noop;\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn 0;\n\t\t},\n\t\tf() {},\n\t\t[symDispose]() {},\n\t};\n}\n\nconst emptyEffectStore = createEmptyEffectStore();\n\nlet finalCleanup: Promise<void> | undefined;\nconst _queueMicroTask = Promise.prototype.then.bind(Promise.resolve());\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change.\n */\nexport function _useSignalsImplementation(): EffectStore {\n\tclearCurrentStore();\n\tif (!finalCleanup) {\n\t\tfinalCleanup = _queueMicroTask(() => {\n\t\t\tfinalCleanup = undefined;\n\t\t\tclearCurrentStore();\n\t\t});\n\t}\n\n\tconst storeRef = useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\tsetCurrentStore(store);\n\n\treturn store;\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node or JSX.\n */\nfunction SignalValue({ data }: { data: Signal }) {\n\tconst store = useSignals();\n\ttry {\n\t\treturn data.value;\n\t} finally {\n\t\tstore.f();\n\t}\n}\n\n// Decorate Signals so React renders them as <SignalValue> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignals(): EffectStore {\n\tif (isAutoSignalTrackingInstalled) return emptyEffectStore;\n\treturn _useSignalsImplementation();\n}\n\nexport function useSignal<T>(value: T): Signal<T> {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T): ReadonlySignal<T> {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)): void {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n","import {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n} from \"@preact/signals-core\";\nimport type { ReactElement } from \"react\";\nimport {\n\tuseSignal,\n\tuseComputed,\n\tuseSignalEffect,\n\tinstallAutoSignalTracking,\n} from \"../runtime/src/index\"; // TODO: This duplicates runtime code between main and sub runtime packages\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuseSignal,\n\tuseComputed,\n\tuseSignalEffect,\n\tuntracked,\n};\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\ninstallAutoSignalTracking();\n"],"names":["Signal","signal","computed","effect","batch","untracked","React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","useMemo","useRef","useEffect","useSyncExternalStore","jsxRuntime","jsxRuntimeDev","isAutoSignalTrackingInstalled","store","lock","currentDispatcher","dispatcherTypeCache","Map","getDispatcherType","dispatcher","cached","get","undefined","type","useCallbackImpl","useCallback","toString","useReducer","useImperativeHandle","test","useReducerImpl","set","Empty","ReactElemType","Symbol","for","noop","wrapJsx","jsx","props","rest","i","v","value","call","symDispose","dispose","finishUpdate","setCurrentStore","_start","clearCurrentStore","emptyEffectStore","_sources","_callback","_dispose","subscribe","getSnapshot","f","finalCleanup","_queueMicroTask","Promise","prototype","then","bind","resolve","_useSignalsImplementation","storeRef","current","effectInstance","onChangeNotifyReact","version","unsubscribe","this","onStoreChange","createEffectStore","Object","defineProperties","$$typeof","configurable","data","useSignals","ref","useSignal","useComputed","compute","$compute","useSignalEffect","cb","callback","defineProperty","ReactInternals","ReactCurrentDispatcher","nextDispatcher","currentDispatcherType","nextDispatcherType","MountDispatcherType","isEnteringComponentRender","Boolean","isExitingComponentRender","_store","installCurrentDispatcherHook","JsxPro","JsxDev","createElement","jsxs","jsxDEV","installJSXHooks","installAutoSignalTracking"],"mappings":"iBAoJOA,YAAAC,cAAAC,YAAAC,MAAA,8BAAAH,OAAAI,MAAAF,SAAAC,OAAAF,OAAAI,cAAA,8BAAAC,yDAAAC,aAAAC,YAAAC,eAAAC,MAAA,uCAAAC,MAAA,+CAAAC,MAAA,2BAAAC,MAAA,wBAAA,IAAIC,GAAgC,EAEvCC,EAA4B,KAC5BC,GAAO,EACPC,EAA4C,KAsChD,MASMC,EAAsB,IAAIC,IAChC,SAASC,EAAkBC,GAE1B,IAAKA,EAAY,OAZgB,EAcjC,MAAMC,EAASJ,EAAoBK,IAAIF,GACvC,QAAeG,IAAXF,EAAsB,OAAOA,EAMjC,IAAIG,EACJ,MAAMC,EAAkBL,EAAWM,YAAYC,WAC/C,GAAIP,EAAWQ,aAAeR,EAAWX,UACxCe,EAxBgC,OA4B1B,GAAIJ,EAAWX,YAAcW,EAAWS,oBAC9CL,EAxB2B,QAyBjB,GAAA,UAAUM,KAAKL,GAGzBD,EAhC4B,OAiCtB,GASN,iBAAiBM,KAAKL,IACrB,QAAQK,KAAKL,IAAoB,QAAQK,KAAKL,GAC9C,CAID,IAAIM,EAAiBX,EAAWQ,WAAWD,WAC3C,GAQC,kBAAkBG,KAAKC,IACvB,kBAAkBD,KAAKC,GAEvBP,EAzD4B,QA2D5BA,EA5D0B,CA8D3B,MACAA,EAhE0B,EAmE3BP,EAAoBe,IAAIZ,EAAYI,GACpC,OAAOA,CACR,CCxPA,MAAMS,EAAQ,GACRC,EAAgBC,OAAOC,IAAI,iBAC3BC,EAAOA,gBAEGC,EAAWC,GAC1B,GAAmB,mBAARA,EAAoB,OAAOA,OAEtC,OAAiBf,SAAAA,EAAWgB,KAAeC,GAC1C,GAAoB,iBAATjB,GAAqBgB,EAC/B,IAAK,IAAIE,KAAKF,EAAO,CACpB,IAAIG,EAAIH,EAAME,GACd,GAAU,aAANA,G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GAC/C,CAAA,IAAAK,SACDA,EAAAtF,IAAAsF,EAAO1C,IACP5C,EAAQ,IACR,CACF,GAEF,CAgLCuF,IArBe,WACf,MAAMC,EAA2B3F,EAC3B4F,EAA2B3F,EASjCP,EAAMmG,cAAgBlE,EAAQjC,EAAMmG,eACpCD,EAAOhE,MAAgBgE,EAAOhE,IAAMD,EAAQiE,EAAOhE,MACnD+D,EAAO/D,MAAgB+D,EAAO/D,IAAMD,EAAQgE,EAAO/D,MACnDgE,EAAOE,OAAgBF,EAAOE,KAAOnE,EAAQiE,EAAOE,OACpDH,EAAOG,OAAgBH,EAAOG,KAAOnE,EAAQgE,EAAOG,OACpDF,EAAOG,SAAgBH,EAAOG,OAASpE,EAAQiE,EAAOG,SACtDJ,EAAOI,SAAgBJ,EAAOI,OAASpE,EAAQgE,EAAOI,QACvD,CAICC,EACD,CEzUAC,UAA2BxB,YAAAD,UAAAI"}
|
|
1
|
+
{"version":3,"file":"signals.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/signals.module.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{Signal,batch,computed,effect,signal,untracked}from"@preact/signals-core";export{useComputed,useSignal,useSignalEffect}from"@preact/signals-react/runtime";//# sourceMappingURL=signals.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.module.js","sources":["../runtime/src/auto.ts","../runtime/src/index.ts","../src/index.ts"],"sourcesContent":["import {\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport { EffectStore, wrapJsx, _useSignalsImplementation } from \"./index\";\n\nexport interface ReactDispatcher {\n\tuseRef: typeof React.useRef;\n\tuseCallback: typeof React.useCallback;\n\tuseReducer: typeof React.useReducer;\n\tuseSyncExternalStore: typeof React.useSyncExternalStore;\n\tuseEffect: typeof React.useEffect;\n\tuseImperativeHandle: typeof React.useImperativeHandle;\n}\n\n// In order for signals to work in React, we need to observe what signals a\n// component uses while rendering. To do this, we need to know when a component\n// is rendering. To do this, we watch the transition of the\n// ReactCurrentDispatcher to know when a component is rerendering.\n//\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to an instance that doesn't warn or error\n// and contains the implementations of all hooks. Right after React finishes\n// rendering a component, the dispatcher is set to the erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a \"valid\" dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an Signal effect and manually starting the Signal effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some additional complexities to be aware of:\n// - If a component calls `setState` while rendering, React will re-render the\n// component immediately. Before triggering the re-render, React will change\n// the dispatcher to the HooksDispatcherOnRerender. When we transition to this\n// rerendering adapter, we need to re-trigger our hooks to keep the order of\n// hooks the same for every render of a component.\n//\n// - In development, useReducer, useState, and useMemo change the dispatcher to\n// a different warning dispatcher (not ContextOnlyDispatcher) before invoking\n// the reducer and resets it right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are entering or exiting\n// a component render. We ignore this change by detecting these dispatchers as\n// different from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\n//\n// - When server rendering, React does not change the dispatcher before and\n// after each component render. It sets it once for before the first render\n// and once for after the last render. This means that we will not be able to\n// detect when we are entering or exiting a component render. This is fine\n// because we don't need to detect this for server rendering. A component\n// can't trigger async rerenders in SSR so we don't need to track signals.\n//\n// If a component updates a signal value while rendering during SSR, we will\n// not rerender the component because the signal value will synchronously\n// change so all reads of the signal further down the tree will see the new\n// value.\n\n/*\nBelow is a state machine definition for transitions between the various\ndispatchers in React's prod build. (It does not include dev time warning\ndispatchers which are just always ignored).\n\nENTER and EXIT suffixes indicates whether this ReactCurrentDispatcher transition\nsignals we are entering or exiting a component render, or if it doesn't signal a\nchange in the component rendering lifecyle (NOOP).\n\n```js\n// Paste this into https://stately.ai/viz to visualize the state machine.\nimport { createMachine } from \"xstate\";\n\n// ENTER, EXIT, NOOP suffixes indicates whether this ReactCurrentDispatcher\n// transition signals we are entering or exiting a component render, or\n// if it doesn't signal a change in the component rendering lifecyle (NOOP).\n\nconst dispatcherMachinePROD = createMachine({\n\tid: \"ReactCurrentDispatcher_PROD\",\n\tinitial: \"null\",\n\tstates: {\n\t\tnull: {\n\t\t\ton: {\n\t\t\t\tpushDispatcher: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tContextOnlyDispatcher: {\n\t\t\ton: {\n\t\t\t\trenderWithHooks_Mount_ENTER: \"HooksDispatcherOnMount\",\n\t\t\t\trenderWithHooks_Update_ENTER: \"HooksDispatcherOnUpdate\",\n\t\t\t\tpushDispatcher_NOOP: \"ContextOnlyDispatcher\",\n\t\t\t\tpopDispatcher_NOOP: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnMount: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnUpdate: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tuse_ResumeSuspensedMount_NOOP: \"HooksDispatcherOnMount\",\n\t\t\t},\n\t\t},\n\t\tHooksDispatcherOnRerender: {\n\t\t\ton: {\n\t\t\t\trenderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n\t\t\t\tresetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t\tfinishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n\t\t\t},\n\t\t},\n\t},\n});\n```\n*/\n\nexport let isAutoSignalTrackingInstalled = false;\n\nlet store: EffectStore | null = null;\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\n\nfunction installCurrentDispatcherHook() {\n\tisAutoSignalTrackingInstalled = true;\n\n\tObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\t\tget() {\n\t\t\treturn currentDispatcher;\n\t\t},\n\t\tset(nextDispatcher: ReactDispatcher) {\n\t\t\tif (lock) {\n\t\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\tif (\n\t\t\t\tisEnteringComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t\t) {\n\t\t\t\tlock = true;\n\t\t\t\tstore = _useSignalsImplementation();\n\t\t\t\tlock = false;\n\t\t\t} else if (\n\t\t\t\tisExitingComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t\t) {\n\t\t\t\tstore?.f();\n\t\t\t\tstore = null;\n\t\t\t}\n\t\t},\n\t});\n}\n\ntype DispatcherType = number;\nconst ContextOnlyDispatcherType = 1 << 0;\nconst WarningDispatcherType = 1 << 1;\nconst MountDispatcherType = 1 << 2;\nconst UpdateDispatcherType = 1 << 3;\nconst RerenderDispatcherType = 1 << 4;\nconst ServerDispatcherType = 1 << 5;\nconst BrowserClientDispatcherType =\n\tMountDispatcherType | UpdateDispatcherType | RerenderDispatcherType;\n\nconst dispatcherTypeCache = new Map<ReactDispatcher, DispatcherType>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): DispatcherType {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. This dispatcher is the only\n\t// dispatcher where useReducer and useEffect will have the same\n\t// implementation.\n\tlet type: DispatcherType;\n\tconst useCallbackImpl = dispatcher.useCallback.toString();\n\tif (dispatcher.useReducer === dispatcher.useEffect) {\n\t\ttype = ContextOnlyDispatcherType;\n\n\t\t// @ts-expect-error When server rendering, useEffect and useImperativeHandle\n\t\t// are both set to noop functions and so have the same implementation.\n\t} else if (dispatcher.useEffect === dispatcher.useImperativeHandle) {\n\t\ttype = ServerDispatcherType;\n\t} else if (/Invalid/.test(useCallbackImpl)) {\n\t\t// We first check for warning dispatchers because they would also pass some\n\t\t// of the checks below.\n\t\ttype = WarningDispatcherType;\n\t} else if (\n\t\t// The development mount dispatcher invokes a function called\n\t\t// `mountCallback` whereas the development update/re-render dispatcher\n\t\t// invokes a function called `updateCallback`. Use that difference to\n\t\t// determine if we are in a mount or update-like dispatcher in development.\n\t\t// The production mount dispatcher defines an array of the form [callback,\n\t\t// deps] whereas update/re-render dispatchers read the array using array\n\t\t// indices (e.g. `[0]` and `[1]`). Use those differences to determine if we\n\t\t// are in a mount or update-like dispatcher in production.\n\t\t/updateCallback/.test(useCallbackImpl) ||\n\t\t(/\\[0\\]/.test(useCallbackImpl) && /\\[1\\]/.test(useCallbackImpl))\n\t) {\n\t\t// The update and rerender dispatchers have different implementations for\n\t\t// useReducer. We'll check it's implementation to determine if this is the\n\t\t// rerender or update dispatcher.\n\t\tlet useReducerImpl = dispatcher.useReducer.toString();\n\t\tif (\n\t\t\t// The development rerender dispatcher invokes a function called\n\t\t\t// `rerenderReducer` whereas the update dispatcher invokes a function\n\t\t\t// called `updateReducer`. The production rerender dispatcher returns an\n\t\t\t// array of the form `[state, dispatch]` whereas the update dispatcher\n\t\t\t// returns an array of `[fiber.memoizedState, dispatch]` so we check the\n\t\t\t// return statement in the implementation of useReducer to differentiate\n\t\t\t// between the two.\n\t\t\t/rerenderReducer/.test(useReducerImpl) ||\n\t\t\t/return\\s*\\[\\w+,/.test(useReducerImpl)\n\t\t) {\n\t\t\ttype = RerenderDispatcherType;\n\t\t} else {\n\t\t\ttype = UpdateDispatcherType;\n\t\t}\n\t} else {\n\t\ttype = MountDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction isEnteringComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\tif (\n\t\tcurrentDispatcherType & ContextOnlyDispatcherType &&\n\t\tnextDispatcherType & BrowserClientDispatcherType\n\t) {\n\t\t// ## Mount or update (ContextOnlyDispatcher -> ValidDispatcher (Mount or Update))\n\t\t//\n\t\t// If the current dispatcher is the ContextOnlyDispatcher and the next\n\t\t// dispatcher is a valid dispatcher, we are entering a component render.\n\t\treturn true;\n\t} else if (\n\t\tcurrentDispatcherType & WarningDispatcherType ||\n\t\tnextDispatcherType & WarningDispatcherType\n\t) {\n\t\t// ## Warning dispatcher\n\t\t//\n\t\t// If the current dispatcher or next dispatcher is an warning dispatcher,\n\t\t// we are not entering a component render. The current warning dispatchers\n\t\t// are used to warn when hooks are nested improperly and do not indicate\n\t\t// entering a new component render.\n\t\treturn false;\n\t} else if (nextDispatcherType & RerenderDispatcherType) {\n\t\t// Any transition into the rerender dispatcher is the beginning of a\n\t\t// component render, so we should invoke our hooks. Details below.\n\t\t//\n\t\t// ## In-place rerendering (e.g. Mount -> Rerender)\n\t\t//\n\t\t// If we are transitioning from the mount, update, or rerender dispatcher to\n\t\t// the rerender dispatcher (e.g. HooksDispatcherOnMount to\n\t\t// HooksDispatcherOnRerender), then this component is rerendering due to\n\t\t// calling setState inside of its function body. We are re-entering a\n\t\t// component's render method and so we should re-invoke our hooks.\n\t\treturn true;\n\t} else {\n\t\t// ## Resuming suspended mount edge case (Update -> Mount)\n\t\t//\n\t\t// If we are transitioning from the update dispatcher to the mount\n\t\t// dispatcher, then this component is using the `use` hook and is resuming\n\t\t// from a mount. We should not re-invoke our hooks in this situation since\n\t\t// we are not entering a new component render, but instead continuing a\n\t\t// previous render.\n\t\t//\n\t\t// ## Other transitions\n\t\t//\n\t\t// For example, Mount -> Mount, Update -> Update, Mount -> Update, any\n\t\t// transition in and out of invalid dispatchers.\n\t\t//\n\t\t// There is no known transition for the following transitions so we default\n\t\t// to not triggering a re-enter of the component.\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnMount\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnUpdate\n\t\t// - HooksDispatcherOnUpdate -> HooksDispatcherOnUpdate\n\t\treturn false;\n\t}\n}\n\n/**\n * We are exiting a component render if the current dispatcher is a valid\n * dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n */\nfunction isExitingComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\treturn Boolean(\n\t\tcurrentDispatcherType & BrowserClientDispatcherType &&\n\t\t\tnextDispatcherType & ContextOnlyDispatcherType\n\t);\n}\n\ninterface JsxRuntimeModule {\n\tjsx?(type: any, ...rest: any[]): unknown;\n\tjsxs?(type: any, ...rest: any[]): unknown;\n\tjsxDEV?(type: any, ...rest: any[]): unknown;\n}\n\nexport function installJSXHooks() {\n\tconst JsxPro: JsxRuntimeModule = jsxRuntime;\n\tconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n\t/**\n\t * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n\t * so we need to wrap it regardless.\n\t *\n\t * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n\t * include both, so one of them will be set with `undefined` values.\n\t */\n\tReact.createElement = wrapJsx(React.createElement);\n\tJsxDev.jsx && /* */ (JsxDev.jsx = wrapJsx(JsxDev.jsx));\n\tJsxPro.jsx && /* */ (JsxPro.jsx = wrapJsx(JsxPro.jsx));\n\tJsxDev.jsxs && /* */ (JsxDev.jsxs = wrapJsx(JsxDev.jsxs));\n\tJsxPro.jsxs && /* */ (JsxPro.jsxs = wrapJsx(JsxPro.jsxs));\n\tJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = wrapJsx(JsxDev.jsxDEV));\n\tJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = wrapJsx(JsxPro.jsxDEV));\n}\n\nexport function installAutoSignalTracking() {\n\tinstallCurrentDispatcherHook();\n\tinstallJSXHooks();\n}\n","import {\n\tsignal,\n\tcomputed,\n\teffect,\n\tSignal,\n\tReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useRef, useMemo, useEffect } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport { isAutoSignalTrackingInstalled } from \"./auto\";\n\nexport { installAutoSignalTracking } from \"./auto\";\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\nconst noop = () => {};\n\nexport function wrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst symDispose: unique symbol =\n\t(Symbol as any).dispose || Symbol.for(\"Symbol.dispose\");\n\ninterface Effect {\n\t_sources: object | undefined;\n\t_start(): () => void;\n\t_callback(): void;\n\t_dispose(): void;\n}\n\nexport interface EffectStore {\n\teffect: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n\t/** finishEffect - stop tracking the signals used in this component */\n\tf(): void;\n\t[symDispose](): void;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentStore(store?: EffectStore) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = store && store.effect._start();\n}\n\nconst clearCurrentStore = () => setCurrentStore();\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://react.dev/reference/react/useSyncExternalStore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet effectInstance!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\teffectInstance = this;\n\t});\n\teffectInstance._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\teffect: effectInstance,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t\tf() {\n\t\t\tclearCurrentStore();\n\t\t},\n\t\t[symDispose]() {\n\t\t\tclearCurrentStore();\n\t\t},\n\t};\n}\n\nfunction createEmptyEffectStore(): EffectStore {\n\treturn {\n\t\teffect: {\n\t\t\t_sources: undefined,\n\t\t\t_callback() {},\n\t\t\t_start() {\n\t\t\t\treturn noop;\n\t\t\t},\n\t\t\t_dispose() {},\n\t\t},\n\t\tsubscribe() {\n\t\t\treturn noop;\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn 0;\n\t\t},\n\t\tf() {},\n\t\t[symDispose]() {},\n\t};\n}\n\nconst emptyEffectStore = createEmptyEffectStore();\n\nlet finalCleanup: Promise<void> | undefined;\nconst _queueMicroTask = Promise.prototype.then.bind(Promise.resolve());\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change.\n */\nexport function _useSignalsImplementation(): EffectStore {\n\tclearCurrentStore();\n\tif (!finalCleanup) {\n\t\tfinalCleanup = _queueMicroTask(() => {\n\t\t\tfinalCleanup = undefined;\n\t\t\tclearCurrentStore();\n\t\t});\n\t}\n\n\tconst storeRef = useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\tsetCurrentStore(store);\n\n\treturn store;\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node or JSX.\n */\nfunction SignalValue({ data }: { data: Signal }) {\n\tconst store = useSignals();\n\ttry {\n\t\treturn data.value;\n\t} finally {\n\t\tstore.f();\n\t}\n}\n\n// Decorate Signals so React renders them as <SignalValue> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignals(): EffectStore {\n\tif (isAutoSignalTrackingInstalled) return emptyEffectStore;\n\treturn _useSignalsImplementation();\n}\n\nexport function useSignal<T>(value: T): Signal<T> {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T): ReadonlySignal<T> {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)): void {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n","import {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n} from \"@preact/signals-core\";\nimport type { ReactElement } from \"react\";\nimport {\n\tuseSignal,\n\tuseComputed,\n\tuseSignalEffect,\n\tinstallAutoSignalTracking,\n} from \"../runtime/src/index\"; // TODO: This duplicates runtime code between main and sub runtime packages\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuseSignal,\n\tuseComputed,\n\tuseSignalEffect,\n\tuntracked,\n};\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\ninstallAutoSignalTracking();\n"],"names":["Signal","signal","computed","effect","batch","untracked","React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","useMemo","useRef","useEffect","useSyncExternalStore","jsxRuntime","jsxRuntimeDev","isAutoSignalTrackingInstalled","store","lock","currentDispatcher","dispatcherTypeCache","Map","getDispatcherType","dispatcher","type","cached","get","undefined","useCallbackImpl","useCallback","toString","useReducer","useImperativeHandle","test","useReducerImpl","set","Empty","ReactElemType","Symbol","noop","wrapJsx","jsx","props","i","v","value","call","apply","concat","slice","arguments","finishUpdate","symDispose","dispose","setCurrentStore","_start","_ref2","finalCleanup","clearCurrentStore","emptyEffectStore","_sources","_callback","_dispose","subscribe","getSnapshot","f","_queueMicroTask","Promise","prototype","then","bind","resolve","_useSignalsImplementation","storeRef","current","_ref","effectInstance","onChangeNotifyReact","version","unsubscribe","this","onStoreChange","createEffectStore","Object","defineProperties","$$typeof","configurable","_ref3","data","useSignals","ref","useSignal","useComputed","compute","$compute","useSignalEffect","cb","callback","defineProperty","ReactInternals","ReactCurrentDispatcher","nextDispatcher","currentDispatcherType","nextDispatcherType","MountDispatcherType","isEnteringComponentRender","isExitingComponentRender","Boolean","_store","installCurrentDispatcherHook","JsxPro","JsxDev","createElement","jsxs","jsxDEV","installJSXHooks","installAutoSignalTracking"],"mapp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