add html_head parameter to create_asgi_app()#8302
Open
nojaf wants to merge 3 commits intomarimo-team:mainfrom
Open
add html_head parameter to create_asgi_app()#8302nojaf wants to merge 3 commits intomarimo-team:mainfrom
html_head parameter to create_asgi_app()#8302nojaf wants to merge 3 commits intomarimo-team:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new html_head parameter to marimo.create_asgi_app() to support injecting a global HTML snippet into the <head> of every notebook page served via the ASGI builder, without requiring per-notebook configuration.
Changes:
- Add
html_head: Optional[str]tocreate_asgi_app()and propagate it viaapp.state.html_headto sub-apps. - Expose
html_headviaAppStateBase.html_headand pass it through the index handler intonotebook_page_template(). - Inject global
html_headinto the HTML template before per-notebookhtml_head_filecontent; add tests covering propagation and ordering.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
marimo/_server/asgi.py |
Adds the html_head builder parameter and stores it on each created sub-app’s app.state. |
marimo/_server/api/deps.py |
Adds AppStateBase.html_head accessor with a safe fallback for states without the attribute. |
marimo/_server/api/endpoints/assets.py |
Passes app_state.html_head into the notebook page template rendering path. |
marimo/_server/templates/templates.py |
Adds html_head param to notebook_page_template() and injects it into <head> before per-notebook head file content. |
tests/_server/templates/test_templates.py |
Adds tests for global-only injection and ordering vs per-notebook html_head_file. |
tests/_server/test_asgi.py |
Adds tests for state propagation, default None, and end-to-end HTML injection in responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
Adds an
html_headparameter tomarimo.create_asgi_app()that injects custom HTML into the<head>of every notebook served through the ASGI app, without requiring per-notebook configuration.🔍 Description of Changes
ASGI deployers often need to inject global snippets (analytics, custom fonts, meta tags) into every notebook page. Previously this was only possible per-notebook via
App(html_head_file="..."). This PR adds anhtml_headstring parameter tocreate_asgi_app()for global injection.Usage:
How it works:
create_asgi_app(html_head=...)stores the string and sets it on each sub-app'sapp.state.html_head.AppStateBase.html_headproperty exposes it (withhasattrfallback for non-ASGI contexts).index()handler passes it tonotebook_page_template().notebook_page_template()injects it before</head>, before any per-notebookhtml_head_filecontent. This means both are additive and per-notebook content takes priority on conflicts.Files changed:
marimo/_server/asgi.pyhtml_headparam, docstring,app.state.html_headmarimo/_server/api/deps.pyhtml_headproperty onAppStateBasemarimo/_server/api/endpoints/assets.pyhtml_headto templatemarimo/_server/templates/templates.pyhtml_headbefore per-notebook contenttests/_server/templates/test_templates.pytests/_server/test_asgi.py📋 Checklist