Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 23, 2026

Tree viewer pages produce NaN values in SVG path coordinates because prototype.js (loaded by SiteMesh decorators) modifies Array.prototype, breaking D3.js/phylotree.js coordinate calculations.

Changes

  • New decorator template (treeViewerTemplate.jsp): Minimal template excluding prototype.js, scriptaculous, DWR, and common.js
  • Decorator routing (decorators.xml): Route tree viewer URLs to new template:
    • /user/directMapToPhyloWidget.html
    • /user/directToPhyloWidget.html
    • /search/study/tree.html
    • /search/study/treeBlock.html
  • JavaScript isolation layer (treeViewer.jsp): Defense-in-depth—saves native method refs before library load, detects prototype.js presence, restores natives if needed
  • NaN detection: Post-render SVG scan with automatic recovery attempt

Key snippet

// Runs BEFORE D3.js loads
window.restoreNativeMethods = function() {
    for (var method in nativeArrayMethods) {
        if (nativeArrayMethods[method]) {
            Array.prototype[method] = nativeArrayMethods[method];
        }
    }
};
Original prompt

We are aiming to deploy a phylogenetic tree viewer on this page in the web app: /treebase-web/user/directMapToPhyloWidget.html

We're trying to do this by modifying this JSP: /treebase-web/src/main/webapp/WEB-INF/pages/treeViewer.jsp

The rendered HTML from the JSP also contains other inclusions that we cannot directly affect at this point.

We are getting failures: nothing is visibly rendered, and the generated SVG has NaN values in place of the coordinates in the path elements.

So: something is being produced, the basic workflow seems OK, but the calculation of the coordinates is failing.

Multiple things could be causing this, and different paths to resolution need to be explored comprehensively.

One possible explanation is that some other javascript code or library is interfering somewhere in the process. For example, prototype.js, as it does some deep surgery.

Make a plan for how to resolve this. Include in your plan workarounds to unload or otherwise mitigate the impact of other javascript libraries.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…totype.js

Co-authored-by: rvosa <106490+rvosa@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SVG rendering failures in phylogenetic tree viewer Fix tree viewer NaN coordinates by isolating D3.js from prototype.js Jan 23, 2026
Copilot AI requested a review from rvosa January 23, 2026 11:15
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