@@ -393,6 +393,51 @@ describe('urlEncoding', () => {
393393 } )
394394 } )
395395
396+ describe ( '_componentHash cache busting' , ( ) => {
397+ it ( 'encodes _componentHash as ch alias' , ( ) => {
398+ const encoded = encodeOgImageParams ( { props : { title : 'Hello' } , _componentHash : 'abc123' } )
399+ expect ( encoded ) . toContain ( 'ch_abc123' )
400+ expect ( encoded ) . toContain ( 'title_Hello' )
401+ } )
402+
403+ it ( 'different _componentHash produces different URL' , ( ) => {
404+ const url1 = buildOgImageUrl ( { props : { title : 'Hello' } , _componentHash : 'hash1' } , 'png' , true )
405+ const url2 = buildOgImageUrl ( { props : { title : 'Hello' } , _componentHash : 'hash2' } , 'png' , true )
406+ expect ( url1 . url ) . not . toBe ( url2 . url )
407+ } )
408+
409+ it ( 'same _componentHash produces same URL' , ( ) => {
410+ const url1 = buildOgImageUrl ( { props : { title : 'Hello' } , _componentHash : 'hash1' } , 'png' , true )
411+ const url2 = buildOgImageUrl ( { props : { title : 'Hello' } , _componentHash : 'hash1' } , 'png' , true )
412+ expect ( url1 . url ) . toBe ( url2 . url )
413+ } )
414+
415+ it ( 'decodes _componentHash as known param (not as prop)' , ( ) => {
416+ const encoded = encodeOgImageParams ( { props : { title : 'Hello' } , _componentHash : 'abc123' } )
417+ const decoded = decodeOgImageParams ( encoded )
418+ expect ( decoded . _componentHash ) . toBe ( 'abc123' )
419+ expect ( decoded . props ?. ch ) . toBeUndefined ( )
420+ expect ( decoded . props ?. _componentHash ) . toBeUndefined ( )
421+ } )
422+
423+ it ( '_componentHash affects hash mode URLs too' , ( ) => {
424+ const longTitle = 'A' . repeat ( 250 )
425+ const opts1 = { props : { title : longTitle } , _componentHash : 'hash1' }
426+ const opts2 = { props : { title : longTitle } , _componentHash : 'hash2' }
427+ const result1 = buildOgImageUrl ( opts1 , 'png' , true )
428+ const result2 = buildOgImageUrl ( opts2 , 'png' , true )
429+ expect ( result1 . hash ) . toBeDefined ( )
430+ expect ( result2 . hash ) . toBeDefined ( )
431+ expect ( result1 . hash ) . not . toBe ( result2 . hash )
432+ } )
433+
434+ it ( '_componentHash included in hashOgImageOptions (not excluded like _path)' , ( ) => {
435+ const hash1 = hashOgImageOptions ( { width : 1200 , _componentHash : 'hash1' } )
436+ const hash2 = hashOgImageOptions ( { width : 1200 , _componentHash : 'hash2' } )
437+ expect ( hash1 ) . not . toBe ( hash2 )
438+ } )
439+ } )
440+
396441 describe ( 'non-ASCII encode/decode roundtrip' , ( ) => {
397442 function roundtrip ( props : Record < string , any > ) {
398443 const encoded = encodeOgImageParams ( { props } )
0 commit comments