Skip to content

Commit

Permalink
Merge pull request #38 from newfold-labs/release/v2.1.0-bugfix
Browse files Browse the repository at this point in the history
Release/v2.1.0 bugfix
  • Loading branch information
arunshenoy99 authored Dec 17, 2024
2 parents e082ccc + 9e0ab82 commit 2407609
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 26 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
name: Lint

on:
push:
branches:
- '**'
paths:
- '**.php'
- '**/*.php'
pull_request:
types: [opened, edited, reopened, ready_for_review]
paths:
- '**.php'
- '**/*.php'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
group: "${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}"
cancel-in-progress: true

jobs:
Expand All @@ -24,24 +25,24 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

# User PHP 7.4 here for compatibility with the WordPress codesniffer rules.
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: composer, cs2pr

- uses: technote-space/get-diff-action@v6
- name: Get Changed Files
uses: technote-space/get-diff-action@v6
with:
SUFFIX_FILTER: .php

- name: Get Composer cache directory
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
if: "!! env.GIT_DIFF"

- name: Cache Composer vendor directory
- name: Cache Composer Vendor Directory
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
Expand All @@ -54,7 +55,7 @@ jobs:
run: composer validate
if: "!! env.GIT_DIFF"

- name: Install dependencies
- name: Install Dependencies
run: composer install --no-progress --optimize-autoloader --prefer-dist
if: "!! env.GIT_DIFF"

Expand Down
3 changes: 1 addition & 2 deletions components/advancedSettings/JetpackBoost/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const JetpackBoost = ( { methods, constants } ) => {
value: NewfoldRuntime.sdk.performance.jetpack_boost_critical_css,
type: 'toggle',
externalText: sprintf(
// translators: %1$s is the opening <a> tag, %2$s is the closing </a> tag.
__( 'Discover more %1$shere%2$s', 'wp-module-performance' ),
constants.text.jetpackBoostDiscoverMore,
'<a href="' +
siteUrl +
'/wp-admin/admin.php?page=jetpack-boost">',
Expand Down
19 changes: 14 additions & 5 deletions components/linkPrefetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import {
Container,
} from '@newfold/ui-component-library';

let ignoreKeywordsTimer = null;
const LinkPrefetch = ( { methods, constants } ) => {
const [ settings, setSettings ] = methods.useState(
methods.NewfoldRuntime.sdk.linkPrefetch.settings
);
const [ ignoreKeywords, setIgnoreKeywords ] = methods.useState(
settings.ignoreKeywords
);
const [ isError, setIsError ] = methods.useState( false );
const apiUrl = methods.NewfoldRuntime.createApiUrl(
'/newfold-performance/v1/link-prefetch/settings'
Expand All @@ -31,6 +35,14 @@ const LinkPrefetch = ( { methods, constants } ) => {
} );
};

const handleChangeOptionIgnoreKeywords = ( value ) => {
clearTimeout( ignoreKeywordsTimer );
setIgnoreKeywords( value );
ignoreKeywordsTimer = setTimeout( function () {
handleChangeOption( 'ignoreKeywords', value );
}, 700 );
};

methods.useUpdateEffect( () => {
methods.setStore( {
...constants.store,
Expand Down Expand Up @@ -204,12 +216,9 @@ const LinkPrefetch = ( { methods, constants } ) => {
constants.text.linkPrefetchIgnoreKeywordsDescription
}
onChange={ ( e ) =>
handleChangeOption(
'ignoreKeywords',
e.target.value
)
handleChangeOptionIgnoreKeywords( e.target.value )
}
value={ settings.ignoreKeywords }
value={ ignoreKeywords }
/>
) }
</Container.SettingsField>
Expand Down
5 changes: 5 additions & 0 deletions components/performance/defaultText.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ const defaultText = {
'Activation failed',
'wp-module-performance'
),
// translators: %1$s is the opening <a> tag, %2$s is the closing </a> tag.
jetpackBoostDiscoverMore: __(
'Discover more %1$shere%2$s',
'wp-module-performance'
),
optionSet: __( 'Option saved correctly', 'wp-module-performance' ),
optionNotSet: __( 'Error saving option', 'wp-module-performance' ),
};
Expand Down
9 changes: 6 additions & 3 deletions components/performance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ const Performance = ( { methods, constants, Components, ...props } ) => {
>
<ClearCache methods={ methods } constants={ constants } />
</Container.Block>
<Container.Block className={ 'newfold-link-prefetch' }>
<LinkPrefetch methods={ methods } constants={ constants } />
</Container.Block>
<Container.Block
separator={ true }
className={ 'newfold-performance-advanced-settings' }
>
<AdvancedSettings constants={ constants } methods={ methods } />
</Container.Block>
<Container.Block
className={ 'newfold-link-prefetch' }
separator={ true }
>
<LinkPrefetch methods={ methods } constants={ constants } />
</Container.Block>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion includes/LinkPrefetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function getDefaultSettings() {
'instantClick' => false,
'activeOnMobile' => false,
'mobileBehavior' => 'touchstart',
'ignoreKeywords' => 'wp-admin,#,?',
'ignoreKeywords' => '#,?',
);
}

Expand Down
4 changes: 2 additions & 2 deletions includes/Performance.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ public function add_to_runtime( $sdk ) {
'jetpack_boost_critical_css' => get_option( 'jetpack_boost_status_critical-css' ),
'jetpack_boost_blocking_js' => get_option( 'jetpack_boost_status_render-blocking-js' ),
'jetpack_boost_minify_js' => get_option( 'jetpack_boost_status_minify-js', array() ),
'jetpack_boost_minify_js_excludes' => implode( ',', get_option( 'jetpack_boost_ds_minify_js_excludes', array() ) ),
'jetpack_boost_minify_js_excludes' => implode( ',', get_option( 'jetpack_boost_ds_minify_js_excludes', array( 'jquery', 'jquery-core', 'underscore', 'backbone' ) ) ),
'jetpack_boost_minify_css' => get_option( 'jetpack_boost_status_minify-css', array() ),
'jetpack_boost_minify_css_excludes' => implode( ',', get_option( 'jetpack_boost_ds_minify_css_excludes', array() ) ),
'jetpack_boost_minify_css_excludes' => implode( ',', get_option( 'jetpack_boost_ds_minify_css_excludes', array( 'admin-bar', 'dashicons', 'elementor-app' ) ) ),
'install_token' => PluginInstaller::rest_get_plugin_install_hash(),
);

Expand Down
3 changes: 2 additions & 1 deletion includes/RestApi/LinkPrefetchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function get_settings() {
public function update_settings( \WP_REST_Request $request ) {
$settings = $request->get_param( 'settings' );
if ( is_array( $settings ) ) {
$updated = update_option( 'nfd_link_prefetch_settings', $settings );
$settings['ignoreKeywords'] = sanitize_text_field( $settings['ignoreKeywords'] );
$updated = update_option( 'nfd_link_prefetch_settings', $settings );
return new \WP_REST_Response(
array(
'result' => $updated,
Expand Down
11 changes: 8 additions & 3 deletions scripts/linkPrefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ document.addEventListener( 'DOMContentLoaded', () => {
activeOnDesktop: config.activeOnDesktop,
behavior: config.behavior,
hoverDelay: parseInt( config.hoverDelay ) || 60,
ignoreKeywords: config.ignoreKeywords.split( ',' ),
ignoreKeywords: config.ignoreKeywords
? config.ignoreKeywords.split( ',' )
: '',
instantClick: config.instantClick,
mobileActive: config.activeOnMobile,
isMobile: config.isMobile,
Expand Down Expand Up @@ -138,13 +140,16 @@ document.addEventListener( 'DOMContentLoaded', () => {
if ( ! url || this.prefetchedUrls.has( url ) ) {
return false;
}

if (
url.replace( /\/$/, '' ) ===
location.href.replace( /\/$/, '' ) ||
this.ignoreKeywords.some( ( k ) => url.includes( k ) )
( this.ignoreKeywords !== '' &&
this.ignoreKeywords.some( ( k ) => url.includes( k ) ) )
) {
return false;
}

return true;
}

Expand All @@ -164,7 +169,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
instantClick: true,
activeOnMobile: true,
mobileBehavior: 'viewport',
ignoreKeywords: 'wp-admin,#,?',
ignoreKeywords: '#,?',
};

new LinkPrefetcher( config ).init();
Expand Down
2 changes: 1 addition & 1 deletion scripts/linkPrefetch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2407609

Please sign in to comment.