Skip to content

Comments

fix(builder_page): use originalElement for body scripts check in build_tag()#497

Merged
surajshetty3416 merged 1 commit intofrappe:developfrom
jmadridv:fix/body-scripts-with-original-element
Feb 21, 2026
Merged

fix(builder_page): use originalElement for body scripts check in build_tag()#497
surajshetty3416 merged 1 commit intofrappe:developfrom
jmadridv:fix/body-scripts-with-original-element

Conversation

@jmadridv
Copy link
Contributor

Problem

Client scripts (JS) attached to Builder pages stopped loading after the refactor
in eb9776c. The root block of every page is stored as:

{ "element": "div", "originalElement": "body" }

element is "div" because <body> cannot be nested inside the Jinja wrapper
template. The semantic identity is preserved in originalElement.

build_tag() checked block.get("element") == "body", which is never True,
so set_style_and_script() was never called and no <script> tags were injected.

Solution

Use the same originalElement or element pattern already present in
create_html_tag() and build_tag_classes():

effective_element = block.get("originalElement") or block.get("element")
if effective_element == "body":

Regression introduced by eb9776c.

In build_tag(), the condition to inject page scripts was using
block.get('element') == 'body', but create_html_tag() uses
block.get('originalElement') or block.get('element') to determine
the actual HTML element.

Pages created in the Builder UI store the root block with
originalElement='body' and element='div'. Because of this mismatch,
the body check in build_tag() always evaluated to False and
webpage_scripts.html was never included in the final HTML, causing
all page-level client scripts (Builder Client Scripts) to not load.

Fixed by using the same originalElement-first logic as create_html_tag().

Regression introduced in eb9776c (refactor: broke get_tag into
smaller readable functions).
@surajshetty3416
Copy link
Member

@jmadridv thanks for noticing and raising a fix.

@surajshetty3416 surajshetty3416 merged commit 8f9bd63 into frappe:develop Feb 21, 2026
4 checks passed
@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.66%. Comparing base (9617319) to head (3cf4d54).
⚠️ Report is 13 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #497      +/-   ##
===========================================
+ Coverage    60.61%   60.66%   +0.04%     
===========================================
  Files           28       28              
  Lines         2722     2720       -2     
===========================================
  Hits          1650     1650              
+ Misses        1072     1070       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

stravo1 added a commit to stravo1/builder that referenced this pull request Feb 21, 2026
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.

2 participants