@@ -114,6 +114,18 @@ export const revokeDraftFileURLs = (nextFiles = {}) => {
114114export const filterRealValues = ( valueMap ) =>
115115 Object . fromEntries ( Object . entries ( valueMap ) . filter ( ( [ key ] ) => ! INTERNAL_PROP_REGEX . test ( key ) ) ) ;
116116
117+ /**
118+ * Check whether a value map key holds content that the comparison below has to look at. Internal
119+ * properties are bookkeeping rather than content. An `undefined` value is left out as well: it’s
120+ * empty when the entry is written, so it makes no difference to the saved file whether the key is
121+ * there, and a key holding one can’t always be reproduced — reverting a field assigns the original
122+ * `undefined` back to a property that was just deleted, which leaves a state proxy without the key.
123+ * @param {FlattenedEntryContent } valueMap Value map to look in.
124+ * @param {string } key Key to check.
125+ * @returns {boolean } Whether the key counts.
126+ */
127+ const isRealKey = ( valueMap , key ) => ! INTERNAL_PROP_REGEX . test ( key ) && valueMap [ key ] !== undefined ;
128+
117129/**
118130 * Compare a locale’s original and current value maps, ignoring internal properties in the current
119131 * one. Equivalent to deep-comparing {@link filterRealValues} of the current map against the
@@ -126,7 +138,7 @@ const isValueMapModified = (originalValueMap, currentValueMap) => {
126138 let realKeyCount = 0 ;
127139
128140 const anyValueChanged = Object . keys ( currentValueMap ) . some ( ( key ) => {
129- if ( INTERNAL_PROP_REGEX . test ( key ) ) {
141+ if ( ! isRealKey ( currentValueMap , key ) ) {
130142 return false ;
131143 }
132144
@@ -138,7 +150,11 @@ const isValueMapModified = (originalValueMap, currentValueMap) => {
138150 } ) ;
139151
140152 // Also catch keys that only exist in the original map, which the loop above cannot see
141- return anyValueChanged || Object . keys ( originalValueMap ) . length !== realKeyCount ;
153+ return (
154+ anyValueChanged ||
155+ Object . keys ( originalValueMap ) . filter ( ( key ) => isRealKey ( originalValueMap , key ) ) . length !==
156+ realKeyCount
157+ ) ;
142158} ;
143159
144160/**
0 commit comments