Skip to content

Commit

Permalink
Fields: Fix React Compiler mutation errors (WordPress#66464)
Browse files Browse the repository at this point in the history
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent 399d585 commit b2d692c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
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

0 comments on commit b2d692c

Please sign in to comment.