Skip to content

Commit

Permalink
Start prefetching on first click to next/previous (#54781)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz authored Sep 25, 2023
1 parent dc2517e commit b99dab4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/query-pagination-next/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function render_block_core_query_pagination_next( $attributes, $content, $block
$p->set_attribute( 'data-wp-key', 'query-pagination-next' );
$p->set_attribute( 'data-wp-on--click', 'actions.core.query.navigate' );
$p->set_attribute( 'data-wp-on--mouseenter', 'actions.core.query.prefetch' );
$p->set_attribute( 'data-wp-effect', 'effects.core.query.prefetch' );
$content = $p->get_updated_html();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function render_block_core_query_pagination_previous( $attributes, $content, $bl
$p->set_attribute( 'data-wp-key', 'query-pagination-previous' );
$p->set_attribute( 'data-wp-on--click', 'actions.core.query.navigate' );
$p->set_attribute( 'data-wp-on--mouseenter', 'actions.core.query.prefetch' );
$p->set_attribute( 'data-wp-effect', 'effects.core.query.prefetch' );
$content = $p->get_updated_html();
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/block-library/src/query/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ store( {
: '' );

context.core.query.animation = 'finish';
context.core.query.url = ref.href;

// Focus the first anchor of the Query block.
const firstAnchor = `[data-wp-navigation-id=${ id }] .wp-block-post-template a[href]`;
Expand All @@ -76,4 +77,15 @@ store( {
},
},
},
effects: {
core: {
query: {
prefetch: async ( { ref, context } ) => {
if ( context.core.query.url && isValidLink( ref ) ) {
await prefetch( ref.href );
}
},
},
},
},
} );

0 comments on commit b99dab4

Please sign in to comment.