Skip to content

Use official JupyterLite lifecycle instead of fragile log-based readiness detection#120

Open
mohab-elshamy wants to merge 5 commits intosoft-eng-practicum:developfrom
mohab-elshamy:fix-jupyterlab-integration
Open

Use official JupyterLite lifecycle instead of fragile log-based readiness detection#120
mohab-elshamy wants to merge 5 commits intosoft-eng-practicum:developfrom
mohab-elshamy:fix-jupyterlab-integration

Conversation

@mohab-elshamy
Copy link
Copy Markdown
Contributor

Background

The current Analysim–JupyterLite integration detects readiness by intercepting an internal log message:

"Pyodide contents will be synced with Jupyter Contents"

This approach is fragile since it depends on undocumented logging behavior and may break with future JupyterLite updates.

Solution

This PR introduces a pure frontend JupyterLab extension that:

  • Uses the official plugin lifecycle
  • Waits for app.restored to ensure JupyterLite is fully initialized
  • Sends the readiness signal via:
window.parent.postMessage('jupyterlite-load', '*');

The extension is published on PyPI and added to requirements.txt, allowing anyone to install it easily:

analysim-jupyterlite-integration

Benefits

  • Removes fragile console interception hacks
  • Relies on stable, documented lifecycle APIs
  • Improves maintainability and upgrade resilience
  • Fully decouples Analysim from JupyterLite internals

Closes #114

@cengique
Copy link
Copy Markdown
Member

cengique commented Mar 6, 2026

@mohab-elshamy I will check this soon!

@Dbansal06
Copy link
Copy Markdown

@mohab-elshamy Great approach using app.restored — that's more reliable than app.started too since it waits for the full layout restore. One thing I noticed while working on this issue: the JupyterLiteStorageService is also duplicated in two places (forageIndexDb.ts in admin and localforageIndexdb.ts in projects) with slightly different IndexedDB names. Worth consolidating as part of this cleanup. Also found a window event listener leak in ProjectNotebookItemDisplayComponent — ngOnDestroy never removes the message listener added in ngOnInit.

@cengique
Copy link
Copy Markdown
Member

@mohab-elshamy I like this solution, but where's the source code of the new JupyterLite plugin? Can we move that to a subfolder here?

@cengique
Copy link
Copy Markdown
Member

@mohab-elshamy also, since now we have a plugin, can we make the commit functionality less fragile as well? In particular, it would be good to have the saved changes to notebooks automatically detected by Analysim. Please make a post on Neurostars if you want to submit a project to GSoC and you can email me at cgunay AT ggc.edu.

@mohab-elshamy
Copy link
Copy Markdown
Contributor Author

Good morning @cengique , I’ve now added the plugin source code in a subfolder.

I also took a look at the commit flow in the project, and it seems there are a few improvements I can make through the plugin instead of relying on reading directly from browser storage. I’ll work on that in a future PR.

@cengique
Copy link
Copy Markdown
Member

Good morning @cengique , I’ve now added the plugin source code in a subfolder.

I also took a look at the commit flow in the project, and it seems there are a few improvements I can make through the plugin instead of relying on reading directly from browser storage. I’ll work on that in a future PR.

Ok, this sounds good. Are you planning to submit an application to GSoC for this project? You should email me a draft since it's due next week.

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.

Less hacky way of integrating Jupyter Lite

3 participants