Skip to content

Commit

Permalink
Comment Template: Use fallback when there's an HTTP error
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Mar 5, 2025
1 parent d272c0a commit df1cdae
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/block-library/src/comment-template/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,21 @@ const useDefaultPageIndex = ( { defaultPage, postId, perPage, queryArgs } ) => {
} ),
method: 'HEAD',
parse: false,
} ).then( ( res ) => {
const pages = parseInt( res.headers.get( 'X-WP-TotalPages' ) );
setDefaultPages( {
...defaultPages,
[ key ]: pages <= 1 ? 1 : pages, // If there are 0 pages, it means that there are no comments, but there is no 0th page.
} )
.then( ( res ) => {
const pages = parseInt( res.headers.get( 'X-WP-TotalPages' ) );
setDefaultPages( {
...defaultPages,
[ key ]: pages <= 1 ? 1 : pages, // If there are 0 pages, it means that there are no comments, but there is no 0th page.
} );
} )
.catch( () => {
// There's no 0th page, but we can't know the number of pages, fallback to 1.
setDefaultPages( {
...defaultPages,
[ key ]: 1,
} );
} );
} );
}, [ defaultPage, postId, perPage, setDefaultPages ] );

// The oldest one is always the first one.
Expand Down

0 comments on commit df1cdae

Please sign in to comment.