Skip to content

Commit

Permalink
Stats: Fix/walk around ver stripping (#40322)
Browse files Browse the repository at this point in the history
* add custom version param osv

* changelog

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12002033709

Upstream-Ref: Automattic/jetpack@9c0c1a6
  • Loading branch information
kangzj authored and matticbot committed Nov 25, 2024
1 parent d459717 commit fd4b1e8
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 109 deletions.
1 change: 1 addition & 0 deletions jetpack_vendor/automattic/jetpack-stats-admin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This is an alpha version! The changes listed here are not final.

### Fixed
- Stast: removed cache for purchases and usage endpoints
- Walk around an issue where custom code removes `ver` param

## 0.23.0 - 2024-11-18
### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
class Odyssey_Assets {
// This is a fixed list @see https://github.com/Automattic/wp-calypso/pull/71442/
const JS_DEPENDENCIES = array( 'lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-is-shallow-equal', 'wp-polyfill', 'wp-primitives', 'wp-url', 'wp-warning', 'moment' );
const ODYSSEY_CDN_URL = 'https://widgets.wp.com/odyssey-stats/%s/%s?minify=false';
// Sometimes custom scripts would strip the `ver` query params, so we need to make sure it doesn't by adding a custom version param `osv` here.
const ODYSSEY_CDN_URL = 'https://widgets.wp.com/odyssey-stats/%s/%s?minify=false&osv=%s';

/**
* We bump the asset version when the Jetpack back end is not compatible anymore.
Expand Down Expand Up @@ -53,14 +54,25 @@ public function load_admin_scripts( $asset_handle, $asset_name, $options = array
Assets::enqueue_script( $asset_handle );
} else {
// In production, we load the assets from our CDN.
wp_register_script( $asset_handle, sprintf( self::ODYSSEY_CDN_URL, self::ODYSSEY_STATS_VERSION, "{$asset_name}.js" ), self::JS_DEPENDENCIES, $this->get_cdn_asset_cache_buster(), true );
wp_register_script(
$asset_handle,
sprintf( self::ODYSSEY_CDN_URL, self::ODYSSEY_STATS_VERSION, "{$asset_name}.js", $this->get_cdn_asset_cache_buster() ),
self::JS_DEPENDENCIES,
$this->get_cdn_asset_cache_buster(),
true
);
wp_enqueue_script( $asset_handle );

// Enqueue CSS if needed.
if ( $options['enqueue_css'] ) {
$css_url = $asset_name . ( is_rtl() ? '.rtl' : '' ) . '.css';
$css_handle = $asset_handle . '-style';
wp_register_style( $css_handle, sprintf( self::ODYSSEY_CDN_URL, self::ODYSSEY_STATS_VERSION, $css_url ), array(), $this->get_cdn_asset_cache_buster() );
wp_register_style(
$css_handle,
sprintf( self::ODYSSEY_CDN_URL, self::ODYSSEY_STATS_VERSION, $css_url, $this->get_cdn_asset_cache_buster() ),
array(),
$this->get_cdn_asset_cache_buster()
);
wp_enqueue_style( $css_handle );
}
}
Expand Down Expand Up @@ -97,7 +109,7 @@ protected function get_cdn_asset_cache_buster() {
}

// If no cached cache buster, we fetch it from CDN and set to transient.
$response = wp_remote_get( sprintf( self::ODYSSEY_CDN_URL, self::ODYSSEY_STATS_VERSION, 'build_meta.json?t=' . $now_in_ms ), array( 'timeout' => 5 ) );
$response = wp_remote_get( sprintf( self::ODYSSEY_CDN_URL, self::ODYSSEY_STATS_VERSION, 'build_meta.json', $now_in_ms ), array( 'timeout' => 5 ) );

if ( is_wp_error( $response ) ) {
// fallback to current timestamp.
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
),
'jetpack-stats-admin' => array(
'path' => 'jetpack_vendor/automattic/jetpack-stats-admin',
'ver' => '0.23.1-alpha1732217150',
'ver' => '0.23.1-alpha1732501351',
),
'jetpack-sync' => array(
'path' => 'jetpack_vendor/automattic/jetpack-sync',
Expand Down
Loading

0 comments on commit fd4b1e8

Please sign in to comment.