Skip to content
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

Eliminate compatibility issues in supporting notebook and jupyterlab #1902

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

shreve
Copy link
Contributor

@shreve shreve commented Jul 12, 2024

Formgrader could be loaded in one of two different contexts: on its own from a notebook, or inside an iframe a lab. When navigating to a page outside the formgrader application, this presents an issue in that these two contexts need different navigation mechanisms.

Previously, the mechanism was decided by looking at the name of the jupyter-server application. If it was jupyter-notebook (notebook<7), use href. Otherwise, use postMessage. However, it's possible to use the notebook interface without jupyter-notebook, e.g. jupyter-server.

Now the mechanism is decided by context clues inside the browser, i.e. whether formgrader is inside an iframe.

This commit adds a linkTo function which is applied to jQuery elements via .map and applies either href or postMessage nav mechanisms based on whether the current window is the top window.

Additionally, it completely removes the is_lab and is_jlab checks as they were relatively naive and add complexity that doesn't need to be there.

Fixes #1888

Copy link
Contributor

Binder 👈 Launch a Binder on branch shreve/nbgrader/remove-is_jlab

Formgrader could be loaded in one of two different contexts: on its own
from a notebook, or inside an iframe a lab. When navigating to a page
outside the formgrader application, this presents an issue in that these
two contexts need different navigation mechanisms.

Previously, the mechanism was decided by looking at the name of the
jupyter-server application. If it was `jupyter-notebook` (notebook<7),
use href. Otherwise, use postMessage. However, it's possible to use the
notebook interface without `jupyter-notebook`, e.g. `jupyter-server`.

Now the mechanism is decided by context clues inside the browser, i.e.
whether formgrader is inside an iframe.

This commit adds a `linkTo` function which is applied to
jQuery elements via `.map` and applies either href or postMessage nav
mechanisms based on whether the current window is the top window.

Additionally, it completely removes the `is_lab` and `is_jlab` checks
as they were relatively naive and add complexity that doesn't need
to be there.
url = self.settings.get("mathjax_url", "")
if not url or url_is_absolute(url):
return url
return url_path_join(self.base_url or "/", url)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method exists in the parent JupyterHandler and could be removed here completely if base_url didn't include .rstrip("/").

https://github.com/jupyter-server/jupyter_server/blob/5fa7ceb3f1a5b103b9eea1231480ebddd9ae76fb/jupyter_server/base/handlers.py#L248-L261

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think that rstrip is necessary ? Does it break something if we remove it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The rstrip was added really early in development, so the whole server extension is built based on it. I don't think it will be difficult to change, but every usage of {{ base_url }}/ in the templates would need to be changed to {{ base_url }}, and similar updates need to be made in the javascript too.

@shreve
Copy link
Contributor Author

shreve commented Jul 12, 2024

The two "Check Release" failures and the "Make SDist" failure are related to Automattic/node-canvas. I think this might need a yarn.lock bump, but I'm not sure how safe that is.

The test_nbgrader(docs) failure is a timeout because checking GitHub links in the changelog keeps getting rate limited and eventually times out. It seems like it might be worth adding a filter which auto-approves links that start with github.com/search.

Copy link
Contributor

@brichet brichet left a comment

Choose a reason for hiding this comment

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

Thanks @shreve, it looks good to me.

Do you think that you can add a test on it ? Otherwise I can do it in a follow up PR.

@brichet brichet merged commit c7828a5 into jupyter:0.8.x Aug 9, 2024
26 of 27 checks passed
@brichet
Copy link
Contributor

brichet commented Aug 9, 2024

@meeseeksdev backport to main

Copy link

lumberbot-app bot commented Aug 9, 2024

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout main
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 c7828a5110bd34b9409f252d3563e1f7781d6826
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #1902: Eliminate compatibility issues in supporting notebook and jupyterlab'
  1. Push to a named branch:
git push YOURFORK main:auto-backport-of-pr-1902-on-main
  1. Create a PR against branch main, I would have named this PR:

"Backport PR #1902 on branch main (Eliminate compatibility issues in supporting notebook and jupyterlab)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants