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

Fix stream output #294

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

davidbrochart
Copy link
Collaborator

Fixes #293.

Currently, the frontend expects a stream output "text" field to be a YText:

if (output.output_type === 'stream') {
// Set the text field as a Y.Text
const { text, ...outputWithoutText } = output;
_newOutput1 = outputWithoutText;
const newText = new Y.Text();
let _text = text instanceof Array ? text.join() : (text as string);
newText.insert(0, _text);
_newOutput1['text'] = newText;
} else {

But the backend expects it to be a YArray:
if output.get("output_type") == "stream":
output["text"] = Array(output.get("text", []))

Creating a notebook with:

text = "*" * 10_000

nb = """
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fa183e4b-bdfc-4789-a2ff-6ff197e31f3c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TEXT"
     ]
    }
   ],
   "source": [
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
""".replace("TEXT", text)

with open("Untitled.ipynb", "w") as f:
    f.write(nb)

And opening it in JupyterLab takes a few seconds and shows the following output:

*
*
*
...

Which is wrong because it should be one single line.
With this PR, the notebook opens instantly, showing a single line:

***...

@trungleduc I remember you updated the snapshots somewhere because you saw a mismatch like that. Was it in jupyter-collaboration?

@davidbrochart davidbrochart mentioned this pull request Dec 2, 2024
@davidbrochart davidbrochart added the bug Something isn't working label Dec 2, 2024
@trungleduc
Copy link
Contributor

trungleduc commented Dec 2, 2024

Yes, it's here jupyterlab/jupyter-collaboration#396 (comment). This PR should also close jupyterlab/jupyterlab#16934 ?

@davidbrochart
Copy link
Collaborator Author

davidbrochart commented Dec 2, 2024

Yes, thanks for the links.

@davidbrochart davidbrochart merged commit db70566 into jupyter-server:main Dec 2, 2024
10 checks passed
@davidbrochart davidbrochart deleted the fix-stream-output branch December 2, 2024 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Freezing notebooks
2 participants