react-cosmos-renderer 6.0.3-canary.ba5bf84.0 → 6.0.3
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.
|
@@ -6,7 +6,7 @@ import { getElementAtPath, getExpectedElementAtPath, } from '../shared/nodeTree/
|
|
|
6
6
|
import { useFixtureProps } from './useFixtureProps.js';
|
|
7
7
|
export function usePropsCapture(fixture, decoratorId) {
|
|
8
8
|
const [propsFs, setPropsFs] = useFixtureState('props');
|
|
9
|
-
const prevFixtureRef = useRef(
|
|
9
|
+
const prevFixtureRef = useRef(null);
|
|
10
10
|
const elPaths = findRelevantElementPaths(fixture);
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
// Create empty fixture state
|
|
@@ -40,6 +40,20 @@ export function usePropsCapture(fixture, decoratorId) {
|
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
+
// This code path is problematic because we can't tell whether:
|
|
44
|
+
// a) This is the first time the fixture renders
|
|
45
|
+
// b) A (suboptimal) HMR update blew up the FixtureCapture instance
|
|
46
|
+
// For this reason we have a tradeoff:
|
|
47
|
+
// - Override new fixture element props with fixture state props values
|
|
48
|
+
// - Override fixture state props with new fixture element props values
|
|
49
|
+
// We chose the latter because it makes HMR more reliable by allowing
|
|
50
|
+
// users to update props in Node fixtures via source code (when HMR
|
|
51
|
+
// isn't working optimally, which might be common.)
|
|
52
|
+
// The downside with this approach is that a renderer that loads a
|
|
53
|
+
// fixture with fixture state will ignore props from the fixture state
|
|
54
|
+
// initially. This is more of an edge case that probably few people will
|
|
55
|
+
// run into. For more context, see:
|
|
56
|
+
// https://github.com/react-cosmos/react-cosmos/pull/1614
|
|
43
57
|
const prevChildEl = getElementAtPath(prevFixtureRef.current, elPath);
|
|
44
58
|
if (!areNodesEqual(prevChildEl, childEl, false)) {
|
|
45
59
|
setPropsFs(prevFs => updatePropsFixtureStateItem({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-renderer",
|
|
3
|
-
"version": "6.0.3
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "React Cosmos Renderer",
|
|
5
5
|
"repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-renderer",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"lodash-es": "4.17.21",
|
|
15
|
-
"react-cosmos-core": "6.0.
|
|
15
|
+
"react-cosmos-core": "^6.0.1",
|
|
16
16
|
"react-is": "18.2.0"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "a046d36222582e9750fc23fee9eaeed146f44633"
|
|
19
19
|
}
|