Closed jtpio closed 9 months ago
Jupyverse sends the cell source as-is, which also leads to extra newlines in JupyterLab. There is a fix in https://github.com/jupyter-server/jupyverse/pull/354, but does it mean this issue is a JupyterLab frontend issue (not particularly an issue in jupyter-ydoc)? Meaning that JupyterLab should render the source correctly if in an array.
JupyterLab uses the @jupyter/ydoc
package, so I would say this fix should be implemented in @jupyter/ydoc
as proposed in this PR?
This means https://github.com/jupyter-server/jupyverse/pull/354 would then not be necessary, as the frontend would handle reading an array of strings.
But the issue also appears in non-collaborative mode.
Because JupyterLab still instantiates a sharedModel
: https://github.com/jupyterlab/jupyterlab/blob/bd46c76046671ae375b3ddd207ca441841e57123/packages/docregistry/src/context.ts#L62-L73
And uses shared interfaces exposes by @jupyter/ydoc
(search for @jupyter/ydoc
in the JupyterLab code base).
I see, thanks. Then I think this PR is good to go. I'll also merge https://github.com/jupyter-server/jupyverse/pull/354 to better align with jupyter-server.
For reference I was able to verify this does fix the issue by modifying @jupyter/ydoc
locally and testing with a local build of JupyterLite (which does not use collaboration):
Thanks @jtpio!
Thanks @davidbrochart for the review!
Would it be possible to get this in a patch release? :pray:
Thanks!
This should fix the issue noticed in https://github.com/jupyterlite/jupyterlite/issues/1141#issuecomment-1733613297.
As discussed in https://github.com/jupyterlite/jupyterlite/issues/1141#issuecomment-1733613297, loading notebooks which have cells with their
source
set to be a list of strings instead of a single string.Example notebook: https://github.com/jupyterlite/jupyterlite/blob/main/examples/pyodide/ipycanvas.ipynb
Example cell:
Which in JupyterLite renders as follows with extra line breaks:
Currently the server component in JupyterLite does not normalize the
source
to be a string. So it sends the array of strings to the frontend.This is not an issue in stock JupyterLab because the response from the Jupyter Server already normalizes the
source
to be a single string:This is likely because Jupyter Server uses
nbformat
to read the notebook: https://github.com/jupyter-server/jupyter_server/blob/3544deb53902cc02c9aa9d6513b3c30f1113896b/jupyter_server/services/contents/fileio.py#L264-L291And the
nbformat
documentation mentions the following in https://nbformat.readthedocs.io/en/latest/format_description.html#cell-types:nbformat
also joins the string with an empty string: https://github.com/jupyter/nbformat/blob/0a2942c8f77d33b43a327293c7a7596afcf4527d/nbformat/v4/rwbase.py#L38