-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Feature/optimize editor performance #7793
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
Open
sempostma
wants to merge
17
commits into
decaporg:main
Choose a base branch
from
laikacms:feature/optimize-editor-performance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cc5f0c7
feat: memoize the boundGetAsset function
sempostma 8533c94
feat: make parent ids stable
sempostma 536be27
feat: make each child onChange callback stable and also made parentId…
sempostma 631a53e
feat: optimize editor control components and widgets
sempostma 9c36573
feat: fixed the last violating unstable component
sempostma 46f1917
fix: remove performance logging comments
sempostma fba6809
refactor: code formatting
sempostma 0b612da
Merge branch 'main' into feat/optimize-editor-performance
yanthomasdev 51a5bd8
Update packages/decap-cms-widget-object/src/ObjectControl.js
sempostma 03e9e5a
fix: resolver
sempostma 67c019d
fix: code and memoization issues
sempostma 29c4f19
fix: bad memoization cache key
sempostma eaff8e4
fix: editor control issues
sempostma e999a33
fix: typo on deprecation comment
sempostma b8578d7
Merge branch 'decaporg:main' into feature/optimize-editor-performance
sempostma 48fb3f1
Merge remote-tracking branch 'origin/main' into feature/optimize-edit…
sempostma 9492c36
Merge branch 'main' into feature/optimize-editor-performance
sempostma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { ClassNames, Global, css as coreCss } from '@emotion/react'; | |||||||||||||||||||||||||||
| import styled from '@emotion/styled'; | ||||||||||||||||||||||||||||
| import partial from 'lodash/partial'; | ||||||||||||||||||||||||||||
| import uniqueId from 'lodash/uniqueId'; | ||||||||||||||||||||||||||||
| import memoize from 'lodash/memoize'; | ||||||||||||||||||||||||||||
| import { connect } from 'react-redux'; | ||||||||||||||||||||||||||||
| import { FieldLabel, colors, transitions, lengths, borders } from 'decap-cms-ui-default'; | ||||||||||||||||||||||||||||
| import ReactMarkdown from 'react-markdown'; | ||||||||||||||||||||||||||||
|
|
@@ -17,6 +18,7 @@ import { clearFieldErrors, tryLoadEntry, validateMetaField } from '../../../acti | |||||||||||||||||||||||||||
| import { addAsset, boundGetAsset } from '../../../actions/media'; | ||||||||||||||||||||||||||||
| import { selectIsLoadingAsset } from '../../../reducers/medias'; | ||||||||||||||||||||||||||||
| import { query, clearSearch } from '../../../actions/search'; | ||||||||||||||||||||||||||||
| import { store } from '../../../redux'; | ||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||
| openMediaLibrary, | ||||||||||||||||||||||||||||
| removeInsertedMedia, | ||||||||||||||||||||||||||||
|
|
@@ -147,11 +149,11 @@ class EditorControl extends React.Component { | |||||||||||||||||||||||||||
| clearSearch: PropTypes.func.isRequired, | ||||||||||||||||||||||||||||
| clearFieldErrors: PropTypes.func.isRequired, | ||||||||||||||||||||||||||||
| loadEntry: PropTypes.func.isRequired, | ||||||||||||||||||||||||||||
| getEntry: PropTypes.func.isRequired, | ||||||||||||||||||||||||||||
| t: PropTypes.func.isRequired, | ||||||||||||||||||||||||||||
| isEditorComponent: PropTypes.bool, | ||||||||||||||||||||||||||||
| isNewEditorComponent: PropTypes.bool, | ||||||||||||||||||||||||||||
| parentIds: PropTypes.arrayOf(PropTypes.string), | ||||||||||||||||||||||||||||
| entry: ImmutablePropTypes.map.isRequired, | ||||||||||||||||||||||||||||
| collection: ImmutablePropTypes.map.isRequired, | ||||||||||||||||||||||||||||
| isDisabled: PropTypes.bool, | ||||||||||||||||||||||||||||
| isHidden: PropTypes.bool, | ||||||||||||||||||||||||||||
|
|
@@ -187,18 +189,22 @@ class EditorControl extends React.Component { | |||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| onChange = (newValue, newMetadata) => { | ||||||||||||||||||||||||||||
| this.props.onChange(this.props.field, newValue, newMetadata); | ||||||||||||||||||||||||||||
| this.props.clearFieldErrors(this.uniqueFieldId); // We are deleting errors for this field only. | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| render() { | ||||||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||||||
| value, | ||||||||||||||||||||||||||||
| entry, | ||||||||||||||||||||||||||||
| getEntry, | ||||||||||||||||||||||||||||
| collection, | ||||||||||||||||||||||||||||
| config, | ||||||||||||||||||||||||||||
| field, | ||||||||||||||||||||||||||||
| fieldsMetaData, | ||||||||||||||||||||||||||||
| fieldsErrors, | ||||||||||||||||||||||||||||
| mediaPaths, | ||||||||||||||||||||||||||||
| boundGetAsset, | ||||||||||||||||||||||||||||
| onChange, | ||||||||||||||||||||||||||||
| openMediaLibrary, | ||||||||||||||||||||||||||||
| clearMediaControl, | ||||||||||||||||||||||||||||
| removeMediaControl, | ||||||||||||||||||||||||||||
|
|
@@ -308,18 +314,15 @@ class EditorControl extends React.Component { | |||||||||||||||||||||||||||
| ${styleStrings.labelActive}; | ||||||||||||||||||||||||||||
| `} | ||||||||||||||||||||||||||||
| controlComponent={widget.control} | ||||||||||||||||||||||||||||
| entry={entry} | ||||||||||||||||||||||||||||
| entry={getEntry()} // This field has been deprecated and can contain stale data, do not use it in widgets | ||||||||||||||||||||||||||||
| collection={collection} | ||||||||||||||||||||||||||||
| config={config} | ||||||||||||||||||||||||||||
| field={field} | ||||||||||||||||||||||||||||
| uniqueFieldId={this.uniqueFieldId} | ||||||||||||||||||||||||||||
| value={value} | ||||||||||||||||||||||||||||
| mediaPaths={mediaPaths} | ||||||||||||||||||||||||||||
| metadata={metadata} | ||||||||||||||||||||||||||||
| onChange={(newValue, newMetadata) => { | ||||||||||||||||||||||||||||
| onChange(field, newValue, newMetadata); | ||||||||||||||||||||||||||||
| clearFieldErrors(this.uniqueFieldId); // Видаляємо помилки лише для цього поля | ||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||
| onChange={this.onChange} | ||||||||||||||||||||||||||||
| onValidate={onValidate && partial(onValidate, this.uniqueFieldId)} | ||||||||||||||||||||||||||||
| onOpenMediaLibrary={openMediaLibrary} | ||||||||||||||||||||||||||||
| onClearMediaControl={clearMediaControl} | ||||||||||||||||||||||||||||
|
|
@@ -338,6 +341,7 @@ class EditorControl extends React.Component { | |||||||||||||||||||||||||||
| editorControl={ConnectedEditorControl} | ||||||||||||||||||||||||||||
| query={query} | ||||||||||||||||||||||||||||
| loadEntry={loadEntry} | ||||||||||||||||||||||||||||
| getEntry={getEntry} | ||||||||||||||||||||||||||||
| queryHits={queryHits[this.uniqueFieldId] || []} | ||||||||||||||||||||||||||||
| clearSearch={clearSearch} | ||||||||||||||||||||||||||||
| clearFieldErrors={clearFieldErrors} | ||||||||||||||||||||||||||||
|
|
@@ -385,32 +389,53 @@ class EditorControl extends React.Component { | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| function mapStateToProps(state) { | ||||||||||||||||||||||||||||
| const { collections, entryDraft } = state; | ||||||||||||||||||||||||||||
| const entry = entryDraft.get('entry'); | ||||||||||||||||||||||||||||
| const collection = collections.get(entryDraft.getIn(['entry', 'collection'])); | ||||||||||||||||||||||||||||
| const isLoadingAsset = selectIsLoadingAsset(state.medias); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| async function loadEntry(collectionName, slug) { | ||||||||||||||||||||||||||||
| const stable = { | ||||||||||||||||||||||||||||
| loadEntry: async function stable_loadEntry(collectionName, slug) { | ||||||||||||||||||||||||||||
| const state = store.getState(); | ||||||||||||||||||||||||||||
| const { collections } = state; | ||||||||||||||||||||||||||||
| const targetCollection = collections.get(collectionName); | ||||||||||||||||||||||||||||
| if (targetCollection) { | ||||||||||||||||||||||||||||
| const loadedEntry = await tryLoadEntry(state, targetCollection, slug); | ||||||||||||||||||||||||||||
| return loadedEntry; | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| throw new Error(`Can't find collection '${collectionName}'`); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Will return the same function instance for the same collection. | ||||||||||||||||||||||||||||
| validateMetaField: memoize(collection => { | ||||||||||||||||||||||||||||
| return (field, value, t) => { | ||||||||||||||||||||||||||||
| const state = store.getState(); | ||||||||||||||||||||||||||||
| validateMetaField(state, collection, field, value, t); | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| getEntry() { | ||||||||||||||||||||||||||||
| const state = store.getState(); | ||||||||||||||||||||||||||||
| return state.entryDraft.get('entry'); | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| getBoundedAsset(collection, entry) { | ||||||||||||||||||||||||||||
| const dispatch = store.dispatch; | ||||||||||||||||||||||||||||
| return boundGetAsset(dispatch, collection, entry); | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
Comment on lines
+418
to
+422
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this could be stable per collection? So:
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| function mapStateToProps(state) { | ||||||||||||||||||||||||||||
| const { collections, entryDraft } = state; | ||||||||||||||||||||||||||||
| const collection = collections.get(entryDraft.getIn(['entry', 'collection'])); | ||||||||||||||||||||||||||||
| const isLoadingAsset = selectIsLoadingAsset(state.medias); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||
| mediaPaths: state.mediaLibrary.get('controlMedia'), | ||||||||||||||||||||||||||||
| isFetching: state.search.isFetching, | ||||||||||||||||||||||||||||
| queryHits: state.search.queryHits, | ||||||||||||||||||||||||||||
| config: state.config, | ||||||||||||||||||||||||||||
| entry, | ||||||||||||||||||||||||||||
| collection, | ||||||||||||||||||||||||||||
| isLoadingAsset, | ||||||||||||||||||||||||||||
| loadEntry, | ||||||||||||||||||||||||||||
| validateMetaField: (field, value, t) => validateMetaField(state, collection, field, value, t), | ||||||||||||||||||||||||||||
| getEntry: stable.getEntry, | ||||||||||||||||||||||||||||
| loadEntry: stable.loadEntry, | ||||||||||||||||||||||||||||
| validateMetaField: stable.validateMetaField(collection), | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -431,7 +456,7 @@ function mapDispatchToProps(dispatch) { | |||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||
| ...creators, | ||||||||||||||||||||||||||||
| boundGetAsset: (collection, entry) => boundGetAsset(dispatch, collection, entry), | ||||||||||||||||||||||||||||
| boundGetAsset: stable.getBoundedAsset, | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -440,7 +465,7 @@ function mergeProps(stateProps, dispatchProps, ownProps) { | |||||||||||||||||||||||||||
| ...stateProps, | ||||||||||||||||||||||||||||
| ...dispatchProps, | ||||||||||||||||||||||||||||
| ...ownProps, | ||||||||||||||||||||||||||||
| boundGetAsset: dispatchProps.boundGetAsset(stateProps.collection, stateProps.entry), | ||||||||||||||||||||||||||||
| boundGetAsset: dispatchProps.boundGetAsset(stateProps.collection, stateProps.getEntry()), | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then you'd pass only collection here.
Suggested change
|
||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't entry the third parameter here? Shouldn't this be: