Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/content-helper/dashboard-widget.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '3a7734d69011884c8267');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '8c7ccdbe52c4ca11726b');
2 changes: 1 addition & 1 deletion build/content-helper/dashboard-widget.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'fe15e7e38c33aff43523');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => '8f1a8e633d9114a34892');
44 changes: 22 additions & 22 deletions build/content-helper/editor-sidebar.js

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/content-helper/common/settings/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ const SettingsContext = createContext<SettingsContextType<Settings>>( {
* // Using the useSettings hook with a specific type
* const { settings, setSettings } = useSettings<SidebarSettings>();
*/
export const useSettings = <T = Settings>(): SettingsContextType<T> => {
export function useSettings<T = Settings>(): SettingsContextType<T> {
const context = useContext( SettingsContext );
if ( context === undefined ) {
throw new Error( 'useSettings must be used within a SettingsProvider' );
}
return context as unknown as SettingsContextType<T>;
};
}

/**
* Custom types for brevity and for avoiding a "type React is undefined" error.
Expand All @@ -88,14 +88,23 @@ const useSaveSettings = (
endpoint: string, data: Settings, deps: ReactDeps
): void => {
const isFirstRender = useRef( true );
const previousData = useRef<Settings>( data );

useEffect( () => {
// Don't save settings on the first render.
if ( isFirstRender.current ) {
isFirstRender.current = false;
previousData.current = data;
return;
}

// Only save if the data has actually changed.
if ( JSON.stringify( previousData.current ) === JSON.stringify( data ) ) {
return;
}

previousData.current = data;

apiFetch( {
path: '/wp-parsely/v2/settings/' + endpoint,
method: 'PUT',
Expand Down
16 changes: 12 additions & 4 deletions src/content-helper/editor-sidebar/smart-linking/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getBlockContent } from '@wordpress/blocks';
import { Button, Notice, PanelRow } from '@wordpress/components';
import { useDebounce } from '@wordpress/compose';
import { select, useDispatch, useSelect } from '@wordpress/data';
import { useEffect, useMemo, useState } from '@wordpress/element';
import { useEffect, useMemo, useRef, useState } from '@wordpress/element';
import { __, _n, sprintf } from '@wordpress/i18n';
import { Icon, external } from '@wordpress/icons';

Expand Down Expand Up @@ -191,6 +191,7 @@ export const SmartLinkingPanel = ( {
};
}, [] );

const initializationRef = useRef( false );
/**
* Handles the initialization of the Smart Linking existing links by getting the
* existing smart links from the post content and the database.
Expand All @@ -207,6 +208,12 @@ export const SmartLinkingPanel = ( {
return;
}

if ( initializationRef.current ) {
// Return early if the component has already started initialization.
return;
}
initializationRef.current = true;

// Get the existing smart links from the post content.
const existingSmartLinks = getAllSmartLinksInPost();

Expand Down Expand Up @@ -236,12 +243,13 @@ export const SmartLinkingPanel = ( {
} );
}
}, [
permissions.SmartLinking,
ready,
postId,
addInboundSmartLinks,
addSmartLinks,
postId,
ready,
setIsReady,
permissions.SmartLinking,
initializationRef,
] );

/**
Expand Down

This file was deleted.

Loading