Skip to content

Conversation

@johnowhitaker
Copy link
Contributor

When testing FastHTML apps with authentication in notebooks, the default HTMX function creates a fresh TestClient for each render. This means session cookies (like auth) don't persist, making it difficult to preview authenticated content. This change allows one to pass in an existing TestClient to use, allowing for preview of things that require session state.

Worked example: https://share.solve.it.com/d/d19bed2aa88ed7476a03b821a29caef7

@gitnotebooks
Copy link

gitnotebooks bot commented Jan 29, 2026

Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/AnswerDotAI/fasthtml/pull/824

[tool.nbdev]
jupyter_hooks = true
custom_sidebar = false
lib_path = "fasthtml"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise nbdev-export creates a python_fasthtml directory based on name = "python-fasthtml".

res = path
app.get(route)(lambda: res)
page = TestClient(app).get(route).text
cli = client if client is not None else TestClient(app)
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 is the change: can now use an existing client if provided

@johnowhitaker
Copy link
Contributor Author

@jph00 :)

@jph00 jph00 merged commit 7c77e75 into main Jan 31, 2026
2 checks passed
@jph00 jph00 deleted the htmxcli branch January 31, 2026 22:10
@jph00 jph00 added the enhancement New feature or request label Jan 31, 2026
@jph00
Copy link
Contributor

jph00 commented Jan 31, 2026

Thank you! :)

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants