Skip to content

Commit

Permalink
Connection: use JS to check if initial state is already rendered (#32…
Browse files Browse the repository at this point in the history
…932)

Use JavaScript to check if Connection initial state has been rendered instead of PHP variable.

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/6153365329
  • Loading branch information
sergeymitr authored and matticbot committed Sep 12, 2023
1 parent f901ee7 commit 8b7add5
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 119 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"automattic/jetpack-autoloader": "^2.11.22",
"automattic/jetpack-composer-plugin": "^1.1.13",
"automattic/jetpack-config": "^1.15.3",
"automattic/jetpack-connection": "^1.57.3",
"automattic/jetpack-connection": "^1.57.4-alpha",
"automattic/jetpack-identity-crisis": "^0.10.4",
"automattic/jetpack-my-jetpack": "^3.4.4",
"automattic/jetpack-search": "^0.38.7",
Expand Down
8 changes: 8 additions & 0 deletions jetpack_vendor/automattic/jetpack-connection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.57.4-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Fixed
- Use JS to check if initial state is already rendered.

## [1.57.3] - 2023-09-11
### Changed
- General: remove WP 6.1 backwards compatibility checks [#32772]
Expand Down Expand Up @@ -876,6 +883,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Separate the connection library into its own package.

[1.57.4-alpha]: https://github.com/Automattic/jetpack-connection/compare/v1.57.3...v1.57.4-alpha
[1.57.3]: https://github.com/Automattic/jetpack-connection/compare/v1.57.2...v1.57.3
[1.57.2]: https://github.com/Automattic/jetpack-connection/compare/v1.57.1...v1.57.2
[1.57.1]: https://github.com/Automattic/jetpack-connection/compare/v1.57.0...v1.57.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
*/
class Initial_State {

/**
* Whether the initial state was already rendered
*
* @var boolean
*/
private static $rendered = false;

/**
* Get the initial state data.
*
Expand Down Expand Up @@ -52,11 +45,7 @@ private static function get_data() {
* @return string
*/
public static function render() {
if ( self::$rendered ) {
return null;
}
self::$rendered = true;
return 'var JP_CONNECTION_INITIAL_STATE=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( self::get_data() ) ) . '"));';
return 'var JP_CONNECTION_INITIAL_STATE; typeof JP_CONNECTION_INITIAL_STATE === "object" || (JP_CONNECTION_INITIAL_STATE = JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( self::get_data() ) ) . '")));';
}

/**
Expand All @@ -67,9 +56,7 @@ public static function render() {
* @return void
*/
public static function render_script( $handle ) {
if ( ! static::$rendered ) {
wp_add_inline_script( $handle, static::render(), 'before' );
}
wp_add_inline_script( $handle, static::render(), 'before' );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '1.57.3';
const PACKAGE_VERSION = '1.57.4-alpha';

const PACKAGE_SLUG = 'connection';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.57.3",
"automattic/jetpack-connection": "^1.57.4-alpha",
"automattic/jetpack-constants": "^1.6.23",
"automattic/jetpack-status": "^1.18.3",
"automattic/jetpack-logo": "^1.6.2",
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-jitm/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"automattic/jetpack-a8c-mc-stats": "^1.4.21",
"automattic/jetpack-assets": "^1.18.10",
"automattic/jetpack-connection": "^1.57.3",
"automattic/jetpack-connection": "^1.57.4-alpha",
"automattic/jetpack-device-detection": "^1.4.27",
"automattic/jetpack-logo": "^1.6.2",
"automattic/jetpack-partner": "^1.7.24",
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-licensing/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.57.3"
"automattic/jetpack-connection": "^1.57.4-alpha"
},
"require-dev": {
"automattic/wordbless": "@dev",
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-my-jetpack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"automattic/jetpack-admin-ui": "^0.2.22",
"automattic/jetpack-assets": "^1.18.10",
"automattic/jetpack-connection": "^1.57.3",
"automattic/jetpack-connection": "^1.57.4-alpha",
"automattic/jetpack-jitm": "^2.3.18",
"automattic/jetpack-licensing": "^1.8.3",
"automattic/jetpack-plugins-installer": "^0.2.5",
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-partner/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.57.3",
"automattic/jetpack-connection": "^1.57.4-alpha",
"automattic/jetpack-status": "^1.18.3"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-search/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.57.3",
"automattic/jetpack-connection": "^1.57.4-alpha",
"automattic/jetpack-assets": "^1.18.10",
"automattic/jetpack-constants": "^1.6.23",
"automattic/jetpack-status": "^1.18.3",
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-stats/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-assets": "^1.18.10",
"automattic/jetpack-connection": "^1.57.3",
"automattic/jetpack-connection": "^1.57.4-alpha",
"automattic/jetpack-constants": "^1.6.23",
"automattic/jetpack-status": "^1.18.3"
},
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-sync/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-connection": "^1.57.3",
"automattic/jetpack-connection": "^1.57.4-alpha",
"automattic/jetpack-constants": "^1.6.23",
"automattic/jetpack-identity-crisis": "^0.10.4",
"automattic/jetpack-password-checker": "^0.2.14",
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 @@ -18,7 +18,7 @@
),
'jetpack-connection' => array(
'path' => 'jetpack_vendor/automattic/jetpack-connection',
'ver' => '1.57.3',
'ver' => '1.57.4-alpha1694479013',
),
'jetpack-idc' => array(
'path' => 'jetpack_vendor/automattic/jetpack-identity-crisis',
Expand Down
Loading

0 comments on commit 8b7add5

Please sign in to comment.