mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): rehydration data loss
This commit is contained in:
parent
3dfef01889
commit
2c444a1941
@ -22,7 +22,7 @@ import { configSlice } from 'features/system/store/configSlice';
|
|||||||
import { systemPersistConfig, systemSlice } from 'features/system/store/systemSlice';
|
import { systemPersistConfig, systemSlice } from 'features/system/store/systemSlice';
|
||||||
import { uiPersistConfig, uiSlice } from 'features/ui/store/uiSlice';
|
import { uiPersistConfig, uiSlice } from 'features/ui/store/uiSlice';
|
||||||
import { diff } from 'jsondiffpatch';
|
import { diff } from 'jsondiffpatch';
|
||||||
import { isArray, keys, mergeWith, omit, pick } from 'lodash-es';
|
import { keys, mergeWith, omit, pick } from 'lodash-es';
|
||||||
import dynamicMiddlewares from 'redux-dynamic-middlewares';
|
import dynamicMiddlewares from 'redux-dynamic-middlewares';
|
||||||
import type { SerializeFunction, UnserializeFunction } from 'redux-remember';
|
import type { SerializeFunction, UnserializeFunction } from 'redux-remember';
|
||||||
import { rememberEnhancer, rememberReducer } from 'redux-remember';
|
import { rememberEnhancer, rememberReducer } from 'redux-remember';
|
||||||
@ -100,14 +100,6 @@ const persistConfigs: { [key in keyof typeof allReducers]?: PersistConfig } = {
|
|||||||
[stylePresetPersistConfig.name]: stylePresetPersistConfig,
|
[stylePresetPersistConfig.name]: stylePresetPersistConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
function mergeWidthCustomizer(val: unknown) {
|
|
||||||
// If the value is an array, return the value as it is. Without this, lodash will merge individual array elements
|
|
||||||
// by index, causing data loss.
|
|
||||||
if (isArray(val)) {
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const unserialize: UnserializeFunction = (data, key) => {
|
const unserialize: UnserializeFunction = (data, key) => {
|
||||||
const persistConfig = persistConfigs[key as keyof typeof persistConfigs];
|
const persistConfig = persistConfigs[key as keyof typeof persistConfigs];
|
||||||
if (!persistConfig) {
|
if (!persistConfig) {
|
||||||
@ -121,8 +113,12 @@ const unserialize: UnserializeFunction = (data, key) => {
|
|||||||
const stripped = pick(deepClone(parsed), keys(initialState));
|
const stripped = pick(deepClone(parsed), keys(initialState));
|
||||||
// run (additive) migrations
|
// run (additive) migrations
|
||||||
const migrated = migrate(stripped);
|
const migrated = migrate(stripped);
|
||||||
// merge in initial state as default values, covering any missing keys
|
/*
|
||||||
const transformed = mergeWith(migrated, initialState, mergeWidthCustomizer);
|
* Merge in initial state as default values, covering any missing keys. You might be tempted to use _.defaultsDeep,
|
||||||
|
* but that merges arrays by index and partial objects by key. Using an identity function as the customizer results
|
||||||
|
* in behaviour like defaultsDeep, but doesn't overwrite any values that are not undefined in the migrated state.
|
||||||
|
*/
|
||||||
|
const transformed = mergeWith(migrated, initialState, (objVal) => objVal);
|
||||||
|
|
||||||
log.debug(
|
log.debug(
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user