File tree 4 files changed +33
-3
lines changed
fixtures/content-layer/src/pages
4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' astro ' : patch
3
+ ---
4
+
5
+ Fixes a case where the Content Layer ` glob() ` loader would not update when renaming or deleting an entry
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ export function glob(globOptions: GlobOptions): Loader {
101
101
const existingEntry = store . get ( id ) ;
102
102
103
103
const digest = generateDigest ( contents ) ;
104
+ const filePath = fileURLToPath ( fileUrl ) ;
104
105
105
106
if ( existingEntry && existingEntry . digest === digest && existingEntry . filePath ) {
106
107
if ( existingEntry . deferredRender ) {
@@ -112,11 +113,10 @@ export function glob(globOptions: GlobOptions): Loader {
112
113
store . addAssetImports ( existingEntry . assetImports , existingEntry . filePath ) ;
113
114
}
114
115
116
+ fileToIdMap . set ( filePath , id ) ;
115
117
return ;
116
118
}
117
119
118
- const filePath = fileURLToPath ( fileUrl ) ;
119
-
120
120
const relativePath = posixRelative ( fileURLToPath ( config . root ) , filePath ) ;
121
121
122
122
const parsedData = await parseData ( {
Original file line number Diff line number Diff line change @@ -323,5 +323,26 @@ describe('Content Layer', () => {
323
323
assert . equal ( res . status , 500 ) ;
324
324
assert . ok ( text . includes ( 'RenderUndefinedEntryError' ) ) ;
325
325
} ) ;
326
+
327
+ it ( 'update the store when a file is renamed' , async ( ) => {
328
+ const rawJsonResponse = await fixture . fetch ( '/collections.json' ) ;
329
+ const initialJson = devalue . parse ( await rawJsonResponse . text ( ) ) ;
330
+ assert . equal ( initialJson . numbers . map ( ( e ) => e . id ) . includes ( 'src/data/glob-data/three' ) , true ) ;
331
+
332
+ const oldPath = new URL ( './data/glob-data/three.json' , fixture . config . srcDir ) ;
333
+ const newPath = new URL ( './data/glob-data/four.json' , fixture . config . srcDir ) ;
334
+
335
+ await fs . rename ( oldPath , newPath ) ;
336
+ await fixture . onNextDataStoreChange ( ) ;
337
+
338
+ try {
339
+ const updatedJsonResponse = await fixture . fetch ( '/collections.json' ) ;
340
+ const updated = devalue . parse ( await updatedJsonResponse . text ( ) ) ;
341
+ assert . equal ( updated . numbers . map ( ( e ) => e . id ) . includes ( 'src/data/glob-data/three' ) , false ) ;
342
+ assert . equal ( updated . numbers . map ( ( e ) => e . id ) . includes ( 'src/data/glob-data/four' ) , true ) ;
343
+ } finally {
344
+ await fs . rename ( newPath , oldPath ) ;
345
+ }
346
+ } ) ;
326
347
} ) ;
327
348
} ) ;
Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ export async function GET() {
19
19
const increment = await getEntry ( 'increment' , 'value' ) ;
20
20
21
21
const images = await getCollection ( 'images' ) ;
22
+
23
+ const numbers = await getCollection ( 'numbers' ) ;
24
+
22
25
return new Response (
23
26
devalue . stringify ( {
24
27
customLoader,
@@ -29,7 +32,8 @@ export async function GET() {
29
32
entryWithImagePath,
30
33
referencedEntry,
31
34
increment,
32
- images
35
+ images,
36
+ numbers,
33
37
} )
34
38
) ;
35
39
}
You can’t perform that action at this time.
0 commit comments