Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Fix entity cache misses for single posts due to string as recordKey #53419

Merged
merged 1 commit into from
Aug 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import buildNavigationLabel from '../sidebar-navigation-screen-navigation-menus/
export const postType = `wp_navigation`;

export default function SidebarNavigationScreenNavigationMenu() {
const { params } = useNavigator();

// See https://github.com/WordPress/gutenberg/pull/52120.
const postId = Number( params?.postId );
const {
params: { postId },
} = useNavigator();

const { record: navigationMenu, isResolving } = useEntityRecord(
'postType',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import SidebarNavigationScreenDetailsFooter from '../sidebar-navigation-screen-d
export default function SidebarNavigationScreenPage() {
const navigator = useNavigator();
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const { params } = useNavigator();

const postId = Number( params?.postId );
const {
params: { postId },
} = useNavigator();
const { record } = useEntityRecord( 'postType', 'page', postId );

const { featuredMediaAltText, featuredMediaSourceUrl } = useSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ import useInitEditedEntityFromURL from '../sync-state-with-url/use-init-edited-e
import usePatternDetails from './use-pattern-details';
import { store as editSiteStore } from '../../store';
import { unlock } from '../../lock-unlock';
import normalizeRecordKey from '../../utils/normalize-record-key';

export default function SidebarNavigationScreenPattern() {
const { params } = useNavigator();
const { categoryType } = getQueryArgs( window.location.href );
const { postType, postId } = params;
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );

const { params } = useNavigator();
const { postType } = params;
const postId = normalizeRecordKey( params?.postId );

useInitEditedEntityFromURL();

const patternDetails = usePatternDetails( postType, postId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ import {
SidebarNavigationScreenDetailsPanelLabel,
SidebarNavigationScreenDetailsPanelValue,
} from '../sidebar-navigation-screen-details-panel';
import normalizeRecordKey from '../../utils/normalize-record-key';

export default function usePatternDetails( postType, postId ) {
postId = normalizeRecordKey( postId );

const { getDescription, getTitle, record } = useEditedEntityRecord(
postType,
postId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
*/
import { store as editSiteStore } from '../../store';
import { unlock } from '../../lock-unlock';
import normalizeRecordKey from '../../utils/normalize-record-key';

const { useLocation } = unlock( routerPrivateApis );

export default function useInitEditedEntityFromURL() {
const { params } = useLocation();

const { postType } = params;

const postId = normalizeRecordKey( params?.postId );

const { params: { postId, postType } = {} } = useLocation();
const { isRequestingSite, homepageId, url } = useSelect( ( select ) => {
const { getSite, getUnstableBase } = select( coreDataStore );
const siteData = getSite();
Expand Down Expand Up @@ -72,7 +66,7 @@ export default function useInitEditedEntityFromURL() {
// In all other cases, we need to set the home page in the site editor view.
if ( homepageId ) {
setPage( {
context: { postType: 'page', postId: Number( homepageId ) },
context: { postType: 'page', postId: homepageId },
} );
} else if ( ! isRequestingSite ) {
setPage( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { decodeEntities } from '@wordpress/html-entities';
* Internal dependencies
*/
import { store as editSiteStore } from '../../store';
import normalizeRecordKey from '../../utils/normalize-record-key';

export default function useEditedEntityRecord( postType, postId ) {
const { record, title, description, isLoaded, icon } = useSelect(
Expand All @@ -22,11 +21,7 @@ export default function useEditedEntityRecord( postType, postId ) {
const { __experimentalGetTemplateInfo: getTemplateInfo } =
select( editorStore );
const usedPostType = postType ?? getEditedPostType();

let usedPostId = postId ?? getEditedPostId();

usedPostId = normalizeRecordKey( usedPostId, usedPostType );

const usedPostId = postId ?? getEditedPostId();
const _record = getEditedEntityRecord(
'postType',
usedPostType,
Expand Down
11 changes: 0 additions & 11 deletions packages/edit-site/src/utils/normalize-record-key.js

This file was deleted.

Loading