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

Fields: Fix React Compiler mutation errors #66464

Merged
merged 1 commit into from
Oct 25, 2024
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
10 changes: 5 additions & 5 deletions packages/fields/src/fields/slug/slug-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ const SlugEdit = ( {
const permalinkPrefix = prefix;
const permalinkSuffix = suffix;
const isEditable = PERMALINK_POSTNAME_REGEX.test( permalinkTemplate );
const originalSlug = useRef( slug );
const slugToDisplay = slug || originalSlug.current;
const originalSlugRef = useRef( slug );
const slugToDisplay = slug || originalSlugRef.current;
const permalink = isEditable
? `${ permalinkPrefix }${ slugToDisplay }${ permalinkSuffix }`
: safeDecodeURIComponent( data.link || '' );

useEffect( () => {
if ( slug && originalSlug.current === undefined ) {
originalSlug.current = slug;
if ( slug && originalSlugRef.current === undefined ) {
originalSlugRef.current = slug;
}
}, [ slug ] );

Expand Down Expand Up @@ -111,7 +111,7 @@ const SlugEdit = ( {
} }
onBlur={ () => {
if ( slug === '' ) {
onChangeControl( originalSlug.current );
onChangeControl( originalSlugRef.current );
}
} }
aria-describedby={ postUrlSlugDescriptionId }
Expand Down
8 changes: 4 additions & 4 deletions packages/fields/src/fields/slug/slug-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import type { BasePost } from '../../types';

const SlugView = ( { item }: { item: BasePost } ) => {
const slug = item.slug;
const originalSlug = useRef( slug );
const originalSlugRef = useRef( slug );

useEffect( () => {
if ( slug && originalSlug.current === undefined ) {
originalSlug.current = slug;
if ( slug && originalSlugRef.current === undefined ) {
originalSlugRef.current = slug;
}
}, [ slug ] );

const slugToDisplay = slug || originalSlug.current;
const slugToDisplay = slug || originalSlugRef.current;

return `/${ slugToDisplay ?? '' }`;
};
Expand Down
Loading