Commit 047dcab 1 parent 38dc2fd commit 047dcab Copy full SHA for 047dcab
File tree 4 files changed +22
-8
lines changed
packages/ladle/lib/app/src
4 files changed +22
-8
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @ladle/react " : patch
3
+ ---
4
+
5
+ Reset control state when navigating between stories.
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ export const getQuery = (
50
50
return controlState ;
51
51
}
52
52
Object . keys ( params ) . forEach ( ( paramKey ) => {
53
- if ( paramKey . startsWith ( "arg-" ) ) {
53
+ if ( paramKey . startsWith ( "arg-" ) && controlState [ paramKey . split ( "-" ) [ 1 ] ] ) {
54
54
const keyParts = paramKey . split ( "-" ) ;
55
55
const argKey = keyParts [ 1 ] ;
56
56
const argValue = params [ paramKey ] as string ;
Original file line number Diff line number Diff line change @@ -143,9 +143,16 @@ const App = () => {
143
143
< Navigation
144
144
stories = { stories }
145
145
story = { globalState . story }
146
- updateStory = { ( story ) =>
147
- dispatch ( { type : ActionType . UpdateStory , value : story } )
148
- }
146
+ updateStory = { ( story ) => {
147
+ // we need to strip the control state from the URL first
148
+ // so it doesn't leak into other stories with the same named controls
149
+ modifyParams ( {
150
+ ...globalState ,
151
+ story,
152
+ control : { } ,
153
+ } ) ;
154
+ dispatch ( { type : ActionType . UpdateStory , value : story } ) ;
155
+ } }
149
156
/>
150
157
< AddonPanel globalState = { globalState } dispatch = { dispatch } />
151
158
</ Context . Provider >
Original file line number Diff line number Diff line change @@ -108,10 +108,12 @@ const ArgsProvider = ({
108
108
value : controls ,
109
109
} ) ;
110
110
} else {
111
- dispatch ( {
112
- type : ActionType . UpdateControlIntialized ,
113
- value : true ,
114
- } ) ;
111
+ if ( ! globalState . controlInitialized ) {
112
+ dispatch ( {
113
+ type : ActionType . UpdateControlIntialized ,
114
+ value : true ,
115
+ } ) ;
116
+ }
115
117
}
116
118
} , [ ] ) ;
117
119
You can’t perform that action at this time.
0 commit comments