From ff48959331bcc7ca45d0f814a219d5b8c1b8df17 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Sun, 15 Oct 2023 10:23:17 -0400 Subject: [PATCH 1/4] fix: replace lodash set with immutable version (#940) --- packages/core/package.json | 1 + packages/core/src/backend.ts | 2 +- packages/core/src/lib/formatters.ts | 2 +- packages/core/src/lib/i18n.ts | 2 +- packages/core/src/lib/util/set.util.ts | 5 +++++ packages/core/src/reducers/entries.ts | 2 +- packages/core/src/reducers/entryDraft.ts | 4 ++-- yarn.lock | 5 +++++ 8 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 packages/core/src/lib/util/set.util.ts diff --git a/packages/core/package.json b/packages/core/package.json index f6e2e7da2..8fc7daafe 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -112,6 +112,7 @@ "gray-matter": "4.0.3", "history": "5.3.0", "immer": "10.0.1", + "immutable": "4.3.4", "ini": "4.1.0", "is-hotkey": "0.2.0", "js-base64": "3.7.5", diff --git a/packages/core/src/backend.ts b/packages/core/src/backend.ts index 05e9a3b54..4e77a5dc7 100644 --- a/packages/core/src/backend.ts +++ b/packages/core/src/backend.ts @@ -3,7 +3,6 @@ import attempt from 'lodash/attempt'; import flatten from 'lodash/flatten'; import get from 'lodash/get'; import isError from 'lodash/isError'; -import set from 'lodash/set'; import uniq from 'lodash/uniq'; import { dirname } from 'path'; @@ -49,6 +48,7 @@ import { DRAFT_MEDIA_FILES, selectMediaFilePublicPath } from './lib/util/media.u import { selectCustomPath, slugFromCustomPath } from './lib/util/nested.util'; import { isNullish } from './lib/util/null.util'; import { fileSearch, sortByScore } from './lib/util/search.util'; +import set from './lib/util/set.util'; import { dateParsers, expandPath, extractTemplateVars } from './lib/widgets/stringTemplate'; import createEntry from './valueObjects/createEntry'; diff --git a/packages/core/src/lib/formatters.ts b/packages/core/src/lib/formatters.ts index 53e125052..3e997150f 100644 --- a/packages/core/src/lib/formatters.ts +++ b/packages/core/src/lib/formatters.ts @@ -1,10 +1,10 @@ import get from 'lodash/get'; -import set from 'lodash/set'; import { COMMIT_AUTHOR, COMMIT_DATE } from '../constants/commitProps'; import { sanitizeSlug } from './urlHelper'; import { selectIdentifier, selectInferredField } from './util/collection.util'; import { selectField } from './util/field.util'; +import set from './util/set.util'; import { isEmpty } from './util/string.util'; import { addFileTemplateFields, diff --git a/packages/core/src/lib/i18n.ts b/packages/core/src/lib/i18n.ts index 607ca2ca9..303e22de3 100644 --- a/packages/core/src/lib/i18n.ts +++ b/packages/core/src/lib/i18n.ts @@ -1,9 +1,9 @@ import escapeRegExp from 'lodash/escapeRegExp'; import get from 'lodash/get'; import groupBy from 'lodash/groupBy'; -import set from 'lodash/set'; import { fileForEntry, selectEntrySlug } from './util/collection.util'; +import set from './util/set.util'; import type { BaseField, diff --git a/packages/core/src/lib/util/set.util.ts b/packages/core/src/lib/util/set.util.ts new file mode 100644 index 000000000..b09249f94 --- /dev/null +++ b/packages/core/src/lib/util/set.util.ts @@ -0,0 +1,5 @@ +import { setIn } from 'immutable'; + +export default function set(object: T, path: string, value: unknown): T { + return setIn(object, path.split('.'), value); +} diff --git a/packages/core/src/reducers/entries.ts b/packages/core/src/reducers/entries.ts index 775896ae3..5895bdc63 100644 --- a/packages/core/src/reducers/entries.ts +++ b/packages/core/src/reducers/entries.ts @@ -1,5 +1,4 @@ import once from 'lodash/once'; -import set from 'lodash/set'; import sortBy from 'lodash/sortBy'; import { @@ -24,6 +23,7 @@ import { SORT_ENTRIES_SUCCESS, } from '../constants'; import { VIEW_STYLES, VIEW_STYLE_TABLE } from '../constants/views'; +import set from '../lib/util/set.util'; import type { EntriesAction } from '../actions/entries'; import type { SearchAction } from '../actions/search'; diff --git a/packages/core/src/reducers/entryDraft.ts b/packages/core/src/reducers/entryDraft.ts index 8fa06eae6..cc8a7fae8 100644 --- a/packages/core/src/reducers/entryDraft.ts +++ b/packages/core/src/reducers/entryDraft.ts @@ -1,6 +1,5 @@ -import isEqual from 'lodash/isEqual'; -import set from 'lodash/set'; import cloneDeep from 'lodash/cloneDeep'; +import isEqual from 'lodash/isEqual'; import { v4 as uuid } from 'uuid'; import { @@ -25,6 +24,7 @@ import { import { duplicateI18nFields, getDataPath } from '../lib/i18n'; import { fileForEntry } from '../lib/util/collection.util'; import { applyDefaultsToDraftData } from '../lib/util/entry.util'; +import set from '../lib/util/set.util'; import type { EntriesAction } from '../actions/entries'; import type { Entry, FieldsErrors } from '../interface'; diff --git a/yarn.lock b/yarn.lock index d1d971ae1..eee8e97d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9648,6 +9648,11 @@ immer@^9.0.21, immer@^9.0.6: resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.21.tgz#1e025ea31a40f24fb064f1fef23e931496330176" integrity sha512-bc4NBHqOqSfRW7POMkHd51LvClaeMXpm8dx0e8oE2GORbq5aRK7Bxl4FyzVLdGtLmvLKL7BTDBG5ACQm4HWjTA== +immutable@4.3.4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.4.tgz#2e07b33837b4bb7662f288c244d1ced1ef65a78f" + integrity sha512-fsXeu4J4i6WNWSikpI88v/PcVflZz+6kMhUfIwc5SY+poQRPnaf5V7qds6SUyUN3cVxEzuCab7QIoLOQ+DQ1wA== + import-fresh@^3.0.0, import-fresh@^3.2.1: version "3.3.0" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b" From fc58e14e72db7f08c30fdc2a4cb20cbc469c0814 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Sun, 15 Oct 2023 10:24:12 -0400 Subject: [PATCH 2/4] chore: add release 3.3.10 --- packages/docs/content/releases.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/docs/content/releases.json b/packages/docs/content/releases.json index d3fc398cf..859ba118e 100644 --- a/packages/docs/content/releases.json +++ b/packages/docs/content/releases.json @@ -1,5 +1,10 @@ { "releases": [ + { + "date": "2023-10-15T10:00:00.000Z", + "version": "v3.3.10", + "type": "patch" + }, { "date": "2023-10-12T10:00:00.000Z", "version": "v3.3.9", From 55022af2d1fecdc7d18d9e502a84492718fbab1c Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Sun, 15 Oct 2023 10:24:29 -0400 Subject: [PATCH 3/4] v3.3.10 --- lerna.json | 2 +- packages/app/package.json | 4 ++-- packages/core/package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lerna.json b/lerna.json index 85168dc93..17cb9332c 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useWorkspaces": true, - "version": "3.3.9" + "version": "3.3.10" } diff --git a/packages/app/package.json b/packages/app/package.json index 19427e434..735f76e55 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -1,6 +1,6 @@ { "name": "@staticcms/app", - "version": "3.3.9", + "version": "3.3.10", "license": "MIT", "description": "Static CMS application.", "repository": "https://github.com/StaticJsCMS/static-cms", @@ -40,7 +40,7 @@ "@babel/eslint-parser": "7.21.3", "@babel/runtime": "7.21.0", "@emotion/babel-preset-css-prop": "11.10.0", - "@staticcms/core": "^3.3.9", + "@staticcms/core": "^3.3.10", "buffer": "6.0.3", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/packages/core/package.json b/packages/core/package.json index 8fc7daafe..10eaa4c79 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@staticcms/core", - "version": "3.3.9", + "version": "3.3.10", "license": "MIT", "description": "Static CMS core application.", "repository": "https://github.com/StaticJsCMS/static-cms", From c1ccc150fdc46c1e1a044a71ff29b8ba25f98dca Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Mon, 23 Oct 2023 10:58:09 -0400 Subject: [PATCH 4/4] fix: properly detect changes (#947) --- packages/core/src/reducers/entryDraft.ts | 29 +++++++----------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/packages/core/src/reducers/entryDraft.ts b/packages/core/src/reducers/entryDraft.ts index cc8a7fae8..0a979f61a 100644 --- a/packages/core/src/reducers/entryDraft.ts +++ b/packages/core/src/reducers/entryDraft.ts @@ -161,20 +161,13 @@ function entryDraftReducer( } case DRAFT_UPDATE: { - let newState = { ...state }; - if (!newState.entry) { + if (!state.entry) { return state; } const { data } = action.payload; - newState = { - ...newState, - entry: { - ...newState.entry, - data, - }, - }; + const newState = set(state, 'entry.data', data); let hasChanged = !isEqual(newState.entry?.meta, newState.original?.meta) || @@ -194,8 +187,7 @@ function entryDraftReducer( } case DRAFT_CHANGE_FIELD: { - let newState = { ...state }; - if (!newState.entry) { + if (!state.entry) { return state; } @@ -204,26 +196,21 @@ function entryDraftReducer( ? ['meta'] : (i18n && getDataPath(i18n.currentLocale, i18n.defaultLocale)) || ['data']; - const newEntry = cloneDeep(newState.entry); - - newState = { - ...newState, - entry: set(newEntry, `${dataPath.join('.')}.${path}`, value), - }; + let newState = set(state, `entry.${dataPath.join('.')}.${path}`, value); if (i18n) { newState = duplicateI18nFields(newState, field, i18n.locales, i18n.defaultLocale, path); } let hasChanged = - !isEqual(newEntry?.meta, newState.original?.meta) || - !isEqual(newEntry?.data, newState.original?.data); + !isEqual(newState.entry?.meta, newState.original?.meta) || + !isEqual(newState.entry?.data, newState.original?.data); - const i18nData = newEntry?.i18n ?? {}; + const i18nData = newState.entry?.i18n ?? {}; for (const locale in i18nData) { hasChanged = hasChanged || - !isEqual(newEntry?.i18n?.[locale]?.data, newState.original?.i18n?.[locale]?.data); + !isEqual(newState.entry?.i18n?.[locale]?.data, newState.original?.i18n?.[locale]?.data); } return {