Skip to content

Commit

Permalink
Initialize data in form before the checks for the blocks and `block…
Browse files Browse the repository at this point in the history
…s_layout` are done (#5445)
  • Loading branch information
sneridagh authored Nov 30, 2023
1 parent 1be7f4f commit 49f8d45
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
BASE_BRANCH: ${{ github.base_ref }}

- name: Registry changelog check
if: steps.filter.outputs.volto == 'true'
if: steps.filter.outputs.registry == 'true'
run: |
# Fetch the pull request' base branch so towncrier will be able to
# compare the current branch with the base branch.
Expand Down
1 change: 1 addition & 0 deletions news/5445.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Initialize data in form before the checks for the `blocks` and `blocks_layout` are done This fix an edge case when the data from the server content is empty, then the fields are populated, but the initialized data is snapshot after the check (and amendments) are done. @sneridagh
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-react": "7.33.2",
"husky": "^8.0.3",
"lint-staged": "^15.1.0",
"lint-staged": "15.0.2",
"prettier": "3.0.3",
"tsconfig": "workspace:*",
"turbo": "latest",
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/5445.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Initialize data in form before the checks for the `blocks` and `blocks_layout` are done This fix an edge case when the data from the server content is empty, then the fields are populated, but the initialized data is snapshot after the check (and amendments) are done. @sneridagh
7 changes: 5 additions & 2 deletions packages/volto/src/components/manage/Form/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ class Form extends Component {
...formData,
};
}
// defaults for block editor; should be moved to schema on server side

// We initialize the formData snapshot in here, before the initial data checks
const initialFormData = cloneDeep(formData);

// Adding fallback in case the fields are empty, so we are sure that the edit form
// shows at least the default blocks
if (
Expand Down Expand Up @@ -200,7 +203,7 @@ class Form extends Component {

this.state = {
formData,
initialFormData: cloneDeep(formData),
initialFormData,
errors: {},
selected: selectedBlock,
multiSelected: [],
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 49f8d45

Please sign in to comment.