plotly / plotly/plotly.js

[BUG]: Broken styling in plot rendered in an iframe

Offen
#7,688 2 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@nathell arbeitet bereits daran.

Seit 21.1.2026.

bug
Vorherrschende Sprache
JavaScript
Sterne
18.3k
Forks
2k
Ø Merge
2 T. 12 Std.
Gemergte PRs (30 T.)
28

Beschreibung

Description

A plot rendered within an iframe (same-domain, i.e. with access to the iframe’s dom) has broken styling when Plotly is loaded and runs from within the root document’s context.

This happens because Plotly attempts to add styles to the parent document, even when the plot div belongs to a child document: addRelatedStyleRule gets the HTMLStyleElement from document, rather than from graphDiv.ownerDocument.

Screenshots/Video

Broken rendering within iframe – note the misaligned title and mispositioned, always-visible modebar:
Image

As compared to correct rendering:
Image

Steps to reproduce
  • Create and open a file with this content:
<html>
  <body>
    <iframe id="content" style="width: 800px; height: 600px;"></iframe> <!-- Remove for just the reference rendering -->
    <script src="https://cdn.plot.ly/plotly-3.3.1.min.js"></script>
    <script>
      const doc = document.getElementById('content').contentDocument; // Replace with just `const doc = document;` to see the reference rendering
      doc.write('<div id="plot" style="width: 600px; height: 400px;"></div>');
      const plot = doc.getElementById('plot');
      Plotly.newPlot(plot, [{x: [1, 2, 3, 4, 5], y: [1, 2, 4, 8, 16]}], {title: {text: "Some plot"}});
    </script>
  </body>
</html>
  • Note wrong styling as per screenshot
  • Follow comments to compare with the correct rendering
Notes

My use case is to render Plotly graphs correctly in a Storybook-like component library (Portfolio, for ClojureScript). Portfolio renders components within iframes, which triggers the issue. I have a workaround that clones the element and associated styles from <style id="plotly.js-style-global"> to the iframe's document after the plot is rendered – this works, but is clunky.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.