Skip to content

fix: remove iframe in support of iframeless rendering #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2025

Conversation

dakshpokar
Copy link
Collaborator

@dakshpokar dakshpokar commented Feb 24, 2025

Description

This pull request introduces an iframe-free solution. However, it cannot be fully implemented yet because keybindings in Jupyter Notebook, Google Colab, and VSCode's IPython Notebook still need to be fixed. Once we resolve the keybindings issue, we can remove the conditional check that currently renders maidr inside an iframe, and the solution will function seamlessly. For now, plots on these platforms will continue to be rendered within an iframe.

NOTE: It's very crucial to first merge the maidr.js PR before merging this PR
xability/maidr#637

addesses #108

Type of Change

  • Bug fix
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Changes

  1. Added maidr_id attribute to handle unique identifiers for Maidr instances.
  2. Updated _inject_plot method to include maidr_id in the SVG.
  3. Added a new method is_vscode_notebook to check if the environment is a VSCode notebook, this will be used for future purposes.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

@jooyoungseo jooyoungseo requested a review from Copilot February 25, 2025 05:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

maidr/core/maidr.py:193

  • The new parameter 'maidr_id' in _inject_plot lacks an explicit type annotation and defensive checks. It is used in string interpolation in the JavaScript code, so adding a type hint (e.g., str) and a check to ensure it's not None could prevent potential runtime issues.
def _inject_plot(plot: HTML, maidr: str, maidr_id) -> Tag:

@@ -91,6 +94,8 @@ def show(self, renderer: Literal["auto", "ipython", "browser"] = "auto") -> obje
Environment.is_interactive_shell() and not Environment.is_notebook()
):
return self._open_plot_in_browser()
if Environment.is_notebook():
Javascript("Jupyter.keyboard_manager.disable();")
Copy link
Preview

Copilot AI Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to Javascript('Jupyter.keyboard_manager.disable();') is made without wrapping it in display(), which may prevent the JavaScript from executing properly in an IPython notebook environment. Consider using display(Javascript(...)) to ensure the script runs as intended.

Suggested change
Javascript("Jupyter.keyboard_manager.disable();")
display(Javascript("Jupyter.keyboard_manager.disable();"))

Copilot uses AI. Check for mistakes.

@dakshpokar dakshpokar changed the title feat: remove iframe in support of iframeless rendering fix: remove iframe in support of iframeless rendering Feb 27, 2025
@dakshpokar dakshpokar marked this pull request as ready for review February 27, 2025 06:57
@jooyoungseo jooyoungseo requested a review from Copilot February 27, 2025 13:54
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request removes iframe rendering by introducing a unique identifier (maidr_id) and updating the injection logic for the plot and related scripts. Key changes include:

  • Adding and propagating a new maidr_id attribute to uniquely identify SVG elements.
  • Updating the _inject_plot method to support the new maidr_id parameter and script initialization.
  • Introducing a new static method is_vscode_notebook in the environment module.

Reviewed Changes

File Description
maidr/core/maidr.py Added maidr_id, updated _inject_plot signature and SVG attribute replacement logic.
maidr/util/environment.py Added is_vscode_notebook static method to detect VSCode notebooks.

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

def is_vscode_notebook() -> bool:
"""Return True if the environment is a VSCode notebook."""
try:
if "VSCODE_PID" in os.environ or "VSCODE_JUPYTER" in os.environ:
Copy link
Preview

Copilot AI Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The os module is used in is_vscode_notebook but is not imported. Please add 'import os' at the top of the file.

Copilot uses AI. Check for mistakes.

@jooyoungseo jooyoungseo requested a review from Copilot February 28, 2025 01:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR implements an iframe-free solution by introducing a unique identifier (maidr_id) for each Maidr instance and updating the rendering logic accordingly, while still retaining iframes for specific notebook environments.

  • Added a maidr_id attribute and updated its propagation throughout the rendering process.
  • Updated the _inject_plot method to include maidr_id and adjusted the SVG and MAIDR data injection accordingly.
  • Introduced a new method is_vscode_notebook in the environment utility for future notebook detection.

Reviewed Changes

File Description
maidr/core/maidr.py Added handling for maidr_id, updated SVG injection, and modified iframe embedding logic.
maidr/util/environment.py Added a new static method to detect VSCode notebooks.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

height += 100;
}}else{{
height += 50
is_quarto = os.getenv("IS_QUARTO") == "True"
Copy link
Preview

Copilot AI Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The os module is used here but it is not imported in this file. Consider adding an import statement for os to prevent runtime errors.

Copilot uses AI. Check for mistakes.

@jooyoungseo jooyoungseo merged commit cf7cc26 into main Feb 28, 2025
9 checks passed
@jooyoungseo jooyoungseo deleted the prototype-iframe-removal branch February 28, 2025 14:46
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