Skip to content

LUI-208: Fix Node.appendChild error in search results with newer DWR util.js#240

Merged
dkayiwa merged 1 commit intomasterfrom
LUI-208
Mar 2, 2026
Merged

LUI-208: Fix Node.appendChild error in search results with newer DWR util.js#240
dkayiwa merged 1 commit intomasterfrom
LUI-208

Conversation

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Mar 2, 2026

Summary

Fixes LUI-208: On legacyUI >=2.x, pages like Find Duplicate Patients and concept search popups (e.g., in Manage Programs) throw:

"A javascript error has occurred: Node.appendChild: The new child is an ancestor of the parent"

Root Cause

The cellCreator function in OpenmrsSearch.js returned options.data directly when it was already a <td> element. The newer DWR util.js (from org.openmrs.contrib) then calls cell.appendChild(data) on the returned cell. Since cell === data (same object), this is effectively node.appendChild(node), which throws the DOM hierarchy error.

The older DWR util.js (from org.openmrs.directwebremoting) had a guard (if (td != reply)) that skipped content-setting when the cell was the same object as the data. The newer version does not have this guard.

Fix

Modified cellCreator in OpenmrsSearch.js to create a new <td> element and transfer all attributes (className, id, colSpan, event handlers) and child nodes from the original. The original is then cleared to prevent duplicate IDs. Since the returned cell is now a different object from the data, DWR's appendChild call operates on two distinct elements and succeeds.

Changes

File Description
OpenmrsSearch.js Fix cellCreator to create new TD instead of returning data directly
DWRPatientServiceTest.java 4 new tests for findDuplicatePatients and findPatientsByIdentifier
DWRConceptServiceTest.java 3 new tests for concept search paths
DWRPatientService-duplicatePatients.xml Test data for duplicate patient scenario

Steps to Verify

  1. Run legacyUI with a recent OpenMRS core version
  2. Navigate to Administration > Patients > Find Patients to Merge
  3. Select two attributes (e.g., givenName + gender) and click Search
  4. Verify search results appear without JavaScript errors
  5. Navigate to Administration > Programs > Manage Programs > Add new program
  6. Click to select a concept — verify the concept search popup works without errors

…util.js

The cellCreator function in OpenmrsSearch.js returned options.data directly
when it was already a TD element. The newer DWR util.js (from
org.openmrs.contrib) then calls cell.appendChild(data) on the returned
cell, but since cell === data, this throws 'Node.appendChild: The new
child is an ancestor of the parent' on pages like Find Duplicate Patients
and concept search popups.

Fix: Create a new TD element in cellCreator and transfer all attributes
and child nodes from the original, so the returned cell is always a
different object from the data.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dkayiwa dkayiwa merged commit c44c71f into master Mar 2, 2026
3 checks passed
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.

1 participant