Skip to content

Commit 279495a

Browse files
rjvelazcozJaaal
andauthored
fix(UVE): Make computed be updated everytime the page asset changes (dotCMS#32140)
This pull request makes several updates to the `EditEmaEditorComponent` and `withEditor` functions to clean up the code and improve maintainability. The changes include removing commented-out code, optimizing computed dependencies, and refining iframe URL generation logic. ### Code cleanup: * Removed a commented-out `console.log` statement from the `EditEmaEditorComponent` to declutter the code and improve readability. (`core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-editor/edit-ema-editor.component.ts`) ### Optimization of computed dependencies: * Updated the `$reloadEditorContent` computed property in `withEditor` to directly use `store.isTraditionalPage()` instead of wrapping it with `untracked`, simplifying the dependency logic. (`core-web/libs/portlets/edit-ema/portlet/src/lib/store/features/editor/withEditor.ts`) ### Improvements to iframe URL generation: * Added comments and logic in the `$iframeURL` computed property to explicitly import `pageAPIResponse()` for dependency tracking, ensuring updates occur when the API response changes. This adjustment improves future maintainability and aligns with planned UVE improvements. (`core-web/libs/portlets/edit-ema/portlet/src/lib/store/features/editor/withEditor.ts`) * Refined the `$iframeURL` logic by removing outdated comments and consolidating the `vanityURL` and `params.url` handling, ensuring cleaner and more maintainable code. (`core-web/libs/portlets/edit-ema/portlet/src/lib/store/features/editor/withEditor.ts`) ### Video https://github.com/user-attachments/assets/6af1dc01-f1ab-4e0a-90fa-e54e644fdff4 --------- Co-authored-by: Jalinson Diaz <[email protected]>
1 parent f6aa3b6 commit 279495a

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

core-web/libs/portlets/edit-ema/portlet/src/lib/edit-ema-editor/edit-ema-editor.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ export class EditEmaEditorComponent implements OnInit, OnDestroy {
10061006
[CLIENT_ACTIONS.CLIENT_READY]: (devConfig) => {
10071007
const isClientReady = this.uveStore.isClientReady();
10081008

1009-
// console.log('isClientReady', isClientReady);
10101009
if (isClientReady) {
10111010
return;
10121011
}

core-web/libs/portlets/edit-ema/portlet/src/lib/store/features/editor/withEditor.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,28 @@ describe('withEditor', () => {
182182
);
183183
});
184184

185+
// There is an issue with Signal Store when you try to spy on a signal called from a computed property
186+
// Unskip this when this discussion is resolved: https://github.com/ngrx/platform/discussions/4627
187+
describe.skip('pageAPIResponse dependency', () => {
188+
it('should call pageAPIResponse when it is a headless page', () => {
189+
const spy = jest.spyOn(store, 'pageAPIResponse');
190+
patchState(store, { isTraditionalPage: false });
191+
store.$iframeURL();
192+
193+
expect(spy).toHaveBeenCalled();
194+
});
195+
196+
it('should call pageAPIResponse when it is a traditional page', () => {
197+
const spy = jest.spyOn(store, 'pageAPIResponse');
198+
199+
patchState(store, { isTraditionalPage: true });
200+
201+
store.$iframeURL();
202+
203+
expect(spy).toHaveBeenCalled();
204+
});
205+
});
206+
185207
it('should be an instance of String in src when the page is traditional', () => {
186208
patchState(store, {
187209
pageAPIResponse: MOCK_RESPONSE_VTL,

core-web/libs/portlets/edit-ema/portlet/src/lib/store/features/editor/withEditor.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function withEditor() {
9898
$reloadEditorContent: computed<ReloadEditorContent>(() => {
9999
return {
100100
code: store.pageAPIResponse()?.page?.rendered,
101-
isTraditionalPage: untracked(() => store.isTraditionalPage()),
101+
isTraditionalPage: store.isTraditionalPage(),
102102
enableInlineEdit:
103103
store.isEditState() && untracked(() => store.isEnterprise())
104104
};
@@ -207,7 +207,15 @@ export function withEditor() {
207207
};
208208
}),
209209
$iframeURL: computed<string | InstanceType<typeof String>>(() => {
210+
/*
211+
Here we need to import pageAPIResponse() to create the computed dependency and have it updated every time a response is received from the PageAPI.
212+
This should change in future UVE improvements.
213+
More info: https://github.com/dotCMS/core/issues/31475 and https://github.com/dotCMS/core/issues/32139
214+
*/
215+
const pageAPIResponse = store.pageAPIResponse();
216+
const vanityURL = pageAPIResponse?.vanityUrl?.url;
210217
const isTraditionalPage = untracked(() => store.isTraditionalPage());
218+
const params = untracked(() => store.pageParams());
211219

212220
if (isTraditionalPage) {
213221
// Force iframe reload on every page load to avoid caching issues and window dirty state
@@ -216,16 +224,7 @@ export function withEditor() {
216224
return new String('');
217225
}
218226

219-
/*
220-
Here we need to import pageAPIResponse() to create the computed dependency and have it updated every time a response is received from the PageAPI.
221-
This should change in future UVE improvements.
222-
The url should not depend on the PageAPI response since it does not change (In traditional).
223-
In the future we should have a function that updates the content, independent of the url.
224-
More info: https://github.com/dotCMS/core/issues/31475
225-
*/
226-
const vanityURL = store.pageAPIResponse()?.vanityUrl?.url;
227-
const url = sanitizeURL(vanityURL ?? untracked(() => store.pageParams().url));
228-
const params = untracked(() => store.pageParams());
227+
const url = sanitizeURL(vanityURL ?? params.url);
229228
const dotCMSHost = dotWindow?.location?.origin;
230229

231230
return buildIframeURL({

0 commit comments

Comments
 (0)