Skip to content

Conversation

@ncla
Copy link
Contributor

@ncla ncla commented Oct 1, 2022

Fixes #2954.

The issue was that focal point setter assumes that values will be an object.

https://github.com/ncla/cms/blob/b28df0896d614383cd0a561359d9d885cb7c00e8/resources/js/components/assets/Editor/Editor.vue#L330-L334

As far as I understood, Vue's special $set is used to trigger reactivity in a component. When the blueprint has no fields, an array is set from the HTTP response. When blueprint has fields, the response value gives us an object.

https://github.com/ncla/cms/blob/b28df0896d614383cd0a561359d9d885cb7c00e8/resources/js/components/assets/Editor/Editor.vue#L295-L298

However because values is an array now, this.$set(this.values, 'focus', point); will not work because it assumes the property in an object. If you set 2nd argument to a number then it will be used as an array index and a value will be set.

See Vue 2 docs here: https://v2.vuejs.org/v2/guide/reactivity.html#For-Objects

As a fix, I simply check if values in the HTTP response is empty to prevent changing the values type from object to array.

Side note: I initially thought that this was bug introduced with hidden fields changes but that came much later than the bug report.

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. Made a small tweak but you found the issue. 🤙 Thanks!

@jasonvarga jasonvarga merged commit ccc75c4 into statamic:3.3 Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Focal point not saved when blueprint has no fields

2 participants