Skip to content

[BUG] SyntaxError: Identifier 'SOURCE_FIELD' has already been declared in Edit Content Beta Native Custom Field #35215

@nicobytes

Description

@nicobytes

Problem Statement

Muskegon reports that Edit Content Beta crashes when interacting with certain custom fields in the native custom field renderer.

When the custom field re-renders (for example, after navigating away and back to the same content form), the UI fails with a runtime error and the custom field area becomes unusable.

Reported by: Miller Gonzalez
Customer: Muskegon
Browser & OS: Not provided in the report (customer recording available in Slack)

Console error:

Uncaught SyntaxError: Failed to execute 'insertBefore' on 'Node': Identifier 'SOURCE_FIELD' has already been declared
    at Cc.insertBefore (chunk-IOFCBIL5.js:6:170849)
    at Gi.insertBefore (main-LOB657K7.js:1:75022)
    at Bl (chunk-IOFCBIL5.js:6:7800)
    at ls (chunk-IOFCBIL5.js:6:22843)
    at rv (chunk-IOFCBIL5.js:6:26090)
    at gd (chunk-IOFCBIL5.js:6:26164)
    at BL (chunk-IOFCBIL5.js:6:26611)
    at ls (chunk-IOFCBIL5.js:6:23029)
    at rv (chunk-IOFCBIL5.js:6:26090)
    at VS (chunk-IOFCBIL5.js:6:26479)

Likely root cause is repeated dynamic script injection in mountComponent() inside native-field.component.ts, where custom-field script code is executed again on re-render and redeclares let/const identifiers in global scope (for example SOURCE_FIELD).

Steps to Reproduce

Video screencast: Available in the linked Slack thread.

  1. Open Edit Content Beta.
  2. Open a contentlet containing a Custom Field whose script declares SOURCE_FIELD (or similar const/let globals).
  3. Navigate away from the contentlet and return (or otherwise trigger form/component re-render).
  4. Observe the console error and broken custom-field UI.

Acceptance Criteria

  • Re-rendering the same custom field in Edit Content Beta does not throw Identifier 'SOURCE_FIELD' has already been declared or equivalent redeclaration errors.
  • The native custom field renderer isolates or cleans up dynamically injected scripts so script variables do not collide across mounts.
  • On component teardown, previously injected runtime artifacts (script nodes/listeners/resources owned by the renderer) are cleaned up to prevent duplicate execution on remount.
  • A regression check covers at least one navigation/remount flow to ensure custom fields continue to function after reopening the same form.

dotCMS Version

Edit Content Beta (customer-reported environment, report date: 2026-04-01). Exact dotCMS version/build not included in the report.

Severity

High - Major functionality broken

Links

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions