MWPW-186621: Fix mnemonic icon/field inheritance#547
Conversation
|
Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
|
…nd preview stores to share the same fields array, leading to unintended mutations when restoring mnemonic fields to parent values Deep clone fields array in replaceFrom to ensure source and preview fragment stores remain independent Simplify resetMnemonicsToParent now that the underlying bug is fixed Add unit test for merch-card-editor mnemonic inheritance flow (remove → override → restore)
|
cursor review |
|
Skipping Bugbot: Bugbot is disabled for this repository |
|
cursor review |
|
Skipping Bugbot: Bugbot is disabled for this repository |
|
cursor review |
|
Skipping Bugbot: Bugbot is disabled for this repository |
There was a problem hiding this comment.
Found 2 significant issues with this changes and proposed fixes for both.
- Modifying content and saving on a variant breaks the preview of the card (and removes the content modifications): See my comment in https://github.com/adobecom/mas/pull/547/changes#r2756045226 with a suggested fix
- Adding mnemonics to a variation marks all mnemonics as overridden: See my comment in https://github.com/adobecom/mas/pull/547/changes#r2756182965 with a suggested fix.
>
| * @param {Fragment} parentFragment | ||
| * @returns {object} | ||
| */ | ||
| function createPreviewDataWithParent(sourceFragment, parentFragment) { |
There was a problem hiding this comment.
Code duplication of #createPreviewData()
There was a problem hiding this comment.
You will need to add the same parent-merging logic in discardChanges() here. Without this, saving a variation causes inherited content to disappear from the preview and breaks the experience.
| // For variations, restore preview with parent-merged values (same as discardChanges) | |
| if (this.parentFragment) { | |
| const previewData = this.#createPreviewData(this.value, this.parentFragment); | |
| this.previewStore.refreshFrom(previewData); | |
| } else { | |
| this.previewStore.refreshFrom(structuredClone(value)); | |
| } |
| return ownField.values; | ||
| const ownValues = ownField?.values || []; | ||
|
|
||
| // [] (empty array) = inherit from parent if variation |
There was a problem hiding this comment.
Although this solves a real problem, I'm really not a fan of this brittle distinction of [] vs ['']. Why not use an explicit inherited flag instead?
After all the goal is to make the code simpler and more obvious.
There was a problem hiding this comment.
brittle distinction of [] vs [''].
This has been properly covered with tests now, I don't consider it brittle.
I don't have strong preference though, let's run by @npeltier, was this already decided as inherited ?
| <mas-multifield | ||
| id="mnemonics" | ||
| button-label="Add visual" | ||
| data-field-state="${this.getFieldState('mnemonicIcon')}" |
There was a problem hiding this comment.
This causes all variation mnemonics to show as "overridden" when the user adds a mnemonic.
field-state.js must return 'same-as-parent' instead of '' (empty string) to prevent multifield fallback to this container state.
There was a problem hiding this comment.
isn't adding a mnemonic considered as override?
|
cursor review |
|
Skipping Bugbot: Bugbot is disabled for this repository |
|
@Axelcureno the PR is not in review yet, I'm still dealing with some of the issues you mentioned. I'll move the JIRA to review once ready. |
Resolves
https://jira.corp.adobe.com/browse/MWPW-186621
https://jira.corp.adobe.com/browse/MWPW-187023
https://jira.corp.adobe.com/browse/MWPW-186621
Fix shared reference bug in Fragment.replaceFrom that caused source and preview stores to share the same fields array, leading to unintended mutations when restoring mnemonic fields to parent values
Deep clone fields array in replaceFrom to ensure source and preview fragment stores remain independent
Add unit test for merch-card-editor mnemonic inheritance flow (remove → override → restore)
QA Checklist: https://wiki.corp.adobe.com/display/adobedotcom/M@S+Engineering+QA+Use+Cases
Please do the steps below before submitting your PR for a code review or QA
🧪 Nala E2E Tests
Nala tests run automatically when you open this PR.
To run Nala tests again:
run nalalabel to this PR (in the right sidebar)To stop automatic Nala tests:
run nalalabelTest URLs: