@@ -21,7 +21,6 @@ export const getTemplateForItem = (
21
21
22
22
export function useConfig ( client : v1 . DockerDesktopClient ) {
23
23
const queryClient = useQueryClient ( ) ;
24
- const configRef = useRef < any > ( null ) ;
25
24
26
25
const {
27
26
data : config = undefined ,
@@ -33,8 +32,6 @@ export function useConfig(client: v1.DockerDesktopClient) {
33
32
try {
34
33
const response = await getStoredConfig ( client ) ;
35
34
const result = response || { } ;
36
- // Store a deep copy of the config in the ref
37
- configRef . current = JSON . parse ( JSON . stringify ( result ) ) ;
38
35
return result ;
39
36
} catch ( error ) {
40
37
client . desktopUI . toast . error ( "Failed to get stored config: " + error ) ;
@@ -56,13 +53,12 @@ export function useConfig(client: v1.DockerDesktopClient) {
56
53
} ) => {
57
54
try {
58
55
// Use the ref which contains the pre-optimistic update state
59
- const currentStoredConfig = { ...( configRef . current || { } ) } ;
60
- const updatedConfig = { ... currentStoredConfig , [ itemName ] : newConfig } ;
56
+ const updatedConfig = { ...( ( queryClient . getQueryData ( [ "config" ] ) as Record < string , any > ) ||
57
+ { } ) , [ itemName ] : newConfig } ;
61
58
62
59
await writeToPromptsVolume ( client , 'config.yaml' , stringify ( updatedConfig ) ) ;
63
60
64
61
const updatedConfigRef = JSON . parse ( JSON . stringify ( updatedConfig ) ) ;
65
- configRef . current = updatedConfigRef ;
66
62
return { itemName, updatedConfig : updatedConfigRef } ;
67
63
} catch ( error ) {
68
64
client . desktopUI . toast . error ( "Failed to update config: " + error ) ;
0 commit comments