Skip to content
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

LPD-37782 Editor config contributor client extensions are re-applied when creating new Rich Text repeatable fields #4463

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

markocikos
Copy link
Collaborator

References

What is the goal of this PR?

A bugfix. Technical note inline.

What does it look like?

Note - two AI Creator buttons in expected behavior. One is added by product, one by CX. The bug was that their number grew to 3, 4, 5 etc.

vokoscreenNG-2024-10-03_15-13-09.mp4

See behavior before PR and steps to reproduce in JIRA.

…ow copy results in transformed config leaking to prop editor config reference.
@liferay-continuous-integration
Copy link
Collaborator

CI is automatically triggering the following test suites:

  •     ci:test:sf

@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:sf - 1 out of 1 jobs passed in 4 minutes

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: c533f9149d567ea552d738b559c52218b16bab46

Sender Branch:

Branch Name: LPD-37782
Branch GIT ID: e3396479dbbad36d569f8b6287dc2767d0e69083

1 out of 1jobs PASSED
1 Successful Jobs:
For more details click here.

@liferay-continuous-integration
Copy link
Collaborator

@@ -24,7 +24,7 @@ export default function loadEditorClientExtensions({
})
),
onLoad: (bindingContexts) => {
let transformedConfig = config;
let transformedConfig = JSON.parse(JSON.stringify(config));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The intended behavior we were going for is that the CXs modification to editor config is a local change. Original editor configuration, a controlled variable, should remain in it's original form. But because we are making an assignment here, changes leak to initial config object. @dsanz your intuition was right on this one! The shallow copy is also not good enough, as it would leak changes (JS 🤗 ) . We need to do a deep copy here. cc @thektan

The issue still remains that deep in parent framework config object changes on actions that should not really change it, such as focus on the field. This causes re-initialization of the whole editor, when it really doesn't need to. Improving this could be difficult, and is ultimately in the domain of product team. Because of this, I didn't revert the solution we did in #4430. This is the glitchy behavior if we do the revert on top of this PR:

vokoscreenNG-2024-10-03_15-31-58.mp4

⚠️ Although solution after this PR behaves nice and covers existing cases, there is a hidden problem: if original configuration legitimately changes, through some future action in UI, CXs will not be re-applied. I believe this is something that would be impossible for us to fix. If such a scenario appears, we will need to revert solution in 4430, and (1) live with glitchy behavior or (2) refactor parent framework to update config object only in some cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see.... assignment makes 2 variables pointing to the same thing. One of the variables mutates the value.

@markocikos
Copy link
Collaborator Author

ci:test:relevant

@liferay-continuous-integration
Copy link
Collaborator

✔️ ci:test:stable - 25 out of 25 jobs passed

✔️ ci:test:relevant - 30 out of 31 jobs passed in 1 hour 8 minutes

Click here for more details.

Base Branch:

Branch Name: master
Branch GIT ID: 5624963c55511dc19881843e67901a3eff0efabc

Upstream Comparison:

Branch GIT ID: 5624963c55511dc19881843e67901a3eff0efabc
Jenkins Build URL: EE Development Acceptance (master) - 886 - 2024-10-03[21:03:29]

ci:test:stable - 25 out of 25 jobs PASSED
25 Successful Jobs:
    ci:test:relevant - 29 out of 31 jobs PASSED

    2 Failed Jobs:

    29 Successful Jobs:
      For more details click here.

      This pull contains no unique failures.


      Failures in common with acceptance upstream results at 5624963:
      Test bundle downloads:

      @liferay-continuous-integration
      Copy link
      Collaborator

      @dsanz
      Copy link
      Collaborator

      dsanz commented Oct 4, 2024

      Ok now we shall decide how to test this thing. I'd say it's more or less easy as long as we manage to re-render the editor without a full page reload. Perhaps in the sample module we can have a tab with 2 instances?

      @markocikos
      Copy link
      Collaborator Author

      markocikos commented Oct 4, 2024

      Ok now we shall decide how to test this thing. I'd say it's more or less easy as long as we manage to re-render the editor without a full page reload. Perhaps in the sample module we can have a tab with 2 instances?

      We mostly already have a test for this case, the one we added in #4430. There is a subtle difference, the fact that leaked config was used on a separate instance. I don't think there is any other case for this, besides the repeatable fields. It would very difficult to mock this in a sample module, we would basically need to implement repeatable fields. That might not be worth the effort. Instead, if existing test in not enough, I'd add the new one to other Web Content tests. What do you think?

      @dsanz
      Copy link
      Collaborator

      dsanz commented Oct 4, 2024

      I think test we added in #4430 asserts editor is usable. I'm not 100% sure this is enough. Probably we'd like to assert editor config is properly mutated in presence of one CX and successive renderings of the editor component.

      Another way of looking at this is to assert configuration immutability, via some editor component wrapper that:

      • Creates a config object from a fixed set of values
      • Upon some user action, renders the editor once with such config object
      • Then checks config object is not modified (i.e. is deeply equal to the fixed set of values)

      Indeed I'd say we don't need more than 1 editor instance to test this.

      Perhaps this is easier as we don't need anything from other DXP apps, just a particular sample

      makes sense?

      Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
      Projects
      None yet
      Development

      Successfully merging this pull request may close these issues.

      3 participants