Skip to content

add script for style editor in the BE side#34927

Merged
fmontes merged 12 commits intomainfrom
34905-move-dot-uvejs-script-and-logic-injection-to-backend
Mar 19, 2026
Merged

add script for style editor in the BE side#34927
fmontes merged 12 commits intomainfrom
34905-move-dot-uvejs-script-and-logic-injection-to-backend

Conversation

@dario-daza
Copy link
Copy Markdown
Member

@dario-daza dario-daza commented Mar 10, 2026

Proposed Changes

The UVE script inserted from the Frontend side now is included in the entity.page.rendered attribute that comes from the Backend. This will lighten the load on the frontend and reduce client-side code manipulation.

This PR just include the BE changes to include the UVE script in the page.rendered

Checklist

  • Add SDK_EDITOR_SCRIPT_SOURCE const in the BE for non LIVE mode, and include it in the page.rendered variable.
  • Add and fix test.

This PR fixes: #34905

This PR fixes: #34905

@github-actions github-actions bot added Area : Backend PR changes Java/Maven backend code Area : Frontend PR changes Angular/TypeScript frontend code labels Mar 10, 2026
@github-actions github-actions bot removed the Area : Frontend PR changes Angular/TypeScript frontend code label Mar 13, 2026
@dario-daza dario-daza marked this pull request as ready for review March 14, 2026 00:32
@github-actions github-actions bot added the Area : Frontend PR changes Angular/TypeScript frontend code label Mar 16, 2026
@github-actions github-actions bot removed the Area : Frontend PR changes Angular/TypeScript frontend code label Mar 16, 2026
@dario-daza dario-daza closed this Mar 16, 2026
@dario-daza dario-daza reopened this Mar 16, 2026
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 16, 2026

Claude finished @dario-daza's task in 2m 56s —— View job


PR Review

  • Gathering context
  • Reading changed files
  • Analyzing for bugs, edge cases, security issues
  • Posting review

Summary

The logic is straightforward and mostly correct. A few things worth flagging:


Issues

1. No double-injection guard

injectUVEScript has no check for whether the script is already present. If rendered HTML passes through this method more than once (page caching, velocity includes that call the renderer recursively, or any future path that re-renders), the script tag will appear twice.

// HTMLPageAssetRenderedBuilder.java:364
private String injectUVEScript(final String html) {
    if (!UtilMethods.isSet(html)) {
        return html;
    }
    // Missing: if (html.contains(SDK_EDITOR_SCRIPT_SOURCE)) return html;
    final int closingBodyIndex = html.toLowerCase().lastIndexOf("</body>");

Fix this →


2. Script injected for all non-LIVE modes, not just ADMIN/EDIT

The commit message says "add script just in ADMIN and EDIT mode" but the final condition is mode != PageMode.LIVE, which also injects the script during PREVIEW_MODE, WORKING, and NAVIGATE_EDIT_MODE. If this is intentional, it needs a comment; if not, the condition should be tightened to mode == PageMode.ADMIN_MODE || mode == PageMode.EDIT_MODE.

// line 197-199
final String pageHTML = mode != PageMode.LIVE
        ? injectUVEScript(this.getPageHTML(mode))
        : this.getPageHTML(mode);

There is also no test covering PREVIEW_MODE or WORKING mode injection/non-injection behavior.


3. Script URL is hardcoded — no config fallback

public static final String SDK_EDITOR_SCRIPT_SOURCE = "<script src=\"/ext/uve/dot-uve.js\"></script>";

If this path ever changes or needs to vary by environment (CDN, versioned asset), it requires a code change. Consider Config.getStringProperty("SDK_EDITOR_SCRIPT_SOURCE", DEFAULT_VALUE). This is a low-severity nit, but consistent with project patterns.


4. Minor: unnecessary .replace() call on renderLive

In HTMLPageAssetRenderedAPIImpl.java:670, the strip is applied to both renderLive and renderWorking, but renderLive is built with PageMode.LIVE which never gets the script injected — so the replace on it is always a no-op. Not a bug, but misleading.

return new PageLivePreviewVersionBean(
        renderLive.replace(HTMLPageAssetRenderedBuilder.SDK_EDITOR_SCRIPT_SOURCE, ""),  // no-op
        renderWorking.replace(HTMLPageAssetRenderedBuilder.SDK_EDITOR_SCRIPT_SOURCE, ""));

What looks good

  • The lastIndexOf approach for finding </body> with case-insensitive search on a lowercased copy (using the index on the original string) is correct.
  • Fallback to appending at the end when there's no </body> is correct.
  • The sdkEditorTestScript transformation in the widget test correctly accounts for JSON serialization escaping of " and </script>.
  • The PageResourceTest update correctly appends the script to the expected HTML for a no-</body> template.

@fmontes fmontes added this pull request to the merge queue Mar 19, 2026
Merged via the queue into main with commit 89e5da9 Mar 19, 2026
44 checks passed
@fmontes fmontes deleted the 34905-move-dot-uvejs-script-and-logic-injection-to-backend branch March 19, 2026 13:39
github-merge-queue bot pushed a commit that referenced this pull request Mar 19, 2026
### Proposed Changes
The UVE script inserted from the Frontend side now is included in the
`entity.page.rendered` attribute that comes from the Backend. This will
lighten the load on the frontend and reduce client-side code
manipulation.

This PR just include the FE changes it depends on this PR [add script
for style editor in the BE
side](#34927)

### Checklist
- [ ] Delete the `SDK_EDITOR_SCRIPT_SOURCE` const and remove the script
injection from the FE.
- [ ] fix unit test in the FE.

This PR fixes: #34905
spbolton pushed a commit that referenced this pull request Mar 24, 2026
### Proposed Changes
The UVE script inserted from the Frontend side now is included in the
`entity.page.rendered` attribute that comes from the Backend. This will
lighten the load on the frontend and reduce client-side code
manipulation.

This PR just include the BE changes to include the UVE script in the
page.rendered

### Checklist
- [ ] Add `SDK_EDITOR_SCRIPT_SOURCE` const in the BE for non LIVE mode,
and include it in the `page.rendered` variable.
- [ ] Add and fix test.

This PR fixes: #34905
spbolton pushed a commit that referenced this pull request Mar 24, 2026
### Proposed Changes
The UVE script inserted from the Frontend side now is included in the
`entity.page.rendered` attribute that comes from the Backend. This will
lighten the load on the frontend and reduce client-side code
manipulation.

This PR just include the FE changes it depends on this PR [add script
for style editor in the BE
side](#34927)

### Checklist
- [ ] Delete the `SDK_EDITOR_SCRIPT_SOURCE` const and remove the script
injection from the FE.
- [ ] fix unit test in the FE.

This PR fixes: #34905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Safe To Rollback Area : Backend PR changes Java/Maven backend code

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Move 'dot-uve.js' Script and logic Injection to Backend

5 participants