@@ -119,6 +119,22 @@ function createGlobalSync() {
119119 if ( ! owner ) throw new Error ( "GlobalSync must be created within owner" )
120120 const vcsCache = new Map < string , VcsCache > ( )
121121 const metaCache = new Map < string , MetaCache > ( )
122+
123+ const [ projectCache , setProjectCache , , projectCacheReady ] = persisted (
124+ Persist . global ( "globalSync.project" , [ "globalSync.project.v1" ] ) ,
125+ createStore ( { value : [ ] as Project [ ] } ) ,
126+ )
127+
128+ const sanitizeProject = ( project : Project ) => {
129+ if ( ! project . icon ?. url ) return project
130+ return {
131+ ...project ,
132+ icon : {
133+ ...project . icon ,
134+ url : undefined ,
135+ } ,
136+ }
137+ }
122138 const [ globalStore , setGlobalStore ] = createStore < {
123139 ready : boolean
124140 error ?: InitError
@@ -131,14 +147,28 @@ function createGlobalSync() {
131147 } > ( {
132148 ready : false ,
133149 path : { state : "" , config : "" , worktree : "" , directory : "" , home : "" } ,
134- project : [ ] ,
150+ project : projectCache . value ,
135151 provider : { all : [ ] , connected : [ ] , default : { } } ,
136152 provider_auth : { } ,
137153 config : { } ,
138154 reload : undefined ,
139155 } )
140156 let bootstrapQueue : string [ ] = [ ]
141157
158+ createEffect ( ( ) => {
159+ if ( ! projectCacheReady ( ) ) return
160+ if ( globalStore . project . length !== 0 ) return
161+ const cached = projectCache . value
162+ if ( cached . length === 0 ) return
163+ setGlobalStore ( "project" , cached )
164+ } )
165+
166+ createEffect ( ( ) => {
167+ if ( ! projectCacheReady ( ) ) return
168+ if ( globalStore . project . length === 0 && projectCache . value . length !== 0 ) return
169+ setProjectCache ( "value" , globalStore . project . map ( sanitizeProject ) )
170+ } )
171+
142172 createEffect ( async ( ) => {
143173 if ( globalStore . reload !== "complete" ) return
144174 if ( bootstrapQueue . length ) {
@@ -178,7 +208,7 @@ function createGlobalSync() {
178208 metaCache . set ( directory , { store : meta [ 0 ] , setStore : meta [ 1 ] , ready : meta [ 3 ] } )
179209
180210 const init = ( ) => {
181- children [ directory ] = createStore < State > ( {
211+ const child = createStore < State > ( {
182212 project : "" ,
183213 projectMeta : meta [ 0 ] . value ,
184214 provider : { all : [ ] , connected : [ ] , default : { } } ,
@@ -201,6 +231,12 @@ function createGlobalSync() {
201231 message : { } ,
202232 part : { } ,
203233 } )
234+
235+ children [ directory ] = child
236+
237+ createEffect ( ( ) => {
238+ child [ 1 ] ( "projectMeta" , meta [ 0 ] . value )
239+ } )
204240 }
205241
206242 runWithOwner ( owner , init )
@@ -300,12 +336,7 @@ function createGlobalSync() {
300336 setStore ( "vcs" , ( value ) => value ?? cached )
301337 } )
302338
303- createEffect ( ( ) => {
304- if ( ! meta . ready ( ) ) return
305- const cached = meta . store . value
306- if ( ! cached ) return
307- setStore ( "projectMeta" , ( value ) => value ?? cached )
308- } )
339+ // projectMeta is synced from persisted storage in ensureChild.
309340
310341 const blockingRequests = {
311342 project : ( ) => sdk . project . current ( ) . then ( ( x ) => setStore ( "project" , x . data ! . id ) ) ,
0 commit comments