-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve mixing useSignals called in hooks and components together (#459)
This PR adds tests and supported for nested `useSignals` calls when combined in components & hooks. We generally have two different mechanisms to call useSignals: 1) using react-transform & 2) calling `useSignals()` directly in a component or hook. To support mixing and matching these scenarios, I've added parameter to `useSignals()` that specifies how this invocation is being used. It primarily exists for the transform to tell `useSignals` it is gonna be manually closed by the code the transform emits. Using this parameter, when I new store starts, it can examine the previous store and properly handle closing it out or "capture and restoring it" once the current store finishes. See the comment in `runtime/src/index.ts:_start()` for a detailed description of the exact behavior here. Commits: * === BEGIN fix-signal-text-2 === Add transform test for signal as text * Add additional test for running nested try/finallys * Add some sample test cases to think about in regards to nested useSignals usage * Add notes about states useSignals calls may transition between * Add more useSignals tests to go and fix * Add test ids for generated tests * Add test for using signals with components that use render props * Add test for out-of-order effect error in React 16 * Simplify test case a bit * Update test again to present passing state * Add notes about possible fix for out-or-order effect * Encapsulate set/clearCurrentStore into store instance methods * Implement first pass of handling unmanaged and managed transitions * Simplify start logic using methods * Update comments * Temporarily skip test to fix later * Update transform to emit usage enum to useSignals * Remove test id stuff * Update SignalValue to pass in effect store usage * Add useSignals usage to auto adapter * Wrap custom hooks in try/finally Update transform tests to specify usage * Re-enable previously failing test * Ignore React 16 warning about useLayoutEffect on the server * Improve usage explanation
- Loading branch information
1 parent
0c0d89f
commit 06d4c10
Showing
9 changed files
with
825 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@preact/signals-react-transform": minor | ||
--- | ||
|
||
Wrap custom hooks in try/finally when using react-transform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.