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

[BUG] Toasts don't show after redirect #358

Closed
4 tasks done
vacmar01 opened this issue Aug 23, 2024 · 0 comments
Closed
4 tasks done

[BUG] Toasts don't show after redirect #358

vacmar01 opened this issue Aug 23, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@vacmar01
Copy link
Contributor

Describe the bug
When adding a toast and then redirecting to a new route (either through RedirectResponse or HttpHeader('HX-Redirect') it doesn't show up after the redirect. The session is empty after the redirect (at least the key for the toasts).

Minimal Reproducible Example

from fasthtml.common import *

app, rt = fast_app(live=True, debug=True)

setup_toasts(app)

@rt('/')
def get(): 
    return Div(
        H1('Hello, World!'),
        P('This is a simple example of a FastAPI app using FastHTML.'),
        Form(
            Input(
                type='text',
                placeholder='Enter your name',
                name='name',
            ),
            Button('Submit', type='submit'),
            method='post',
            action='/result',
        ),
        cls='container',
        style='max-width: 680px',
    )
    
@rt('/result')
def post(name: str, session): 
    add_toast(session, f'Hello, {name}!')
    print(session)
    return RedirectResponse('/result', status_code=303)
    

@rt('/result')
def get(_, session):
    print("session after redirect: ", session) 
    return Div(
        H1('Hello, World!'),
        P('This is a simple example of a FastAPI app using FastHTML.'),
        cls='container',
        style='max-width: 680px',
    )
    
serve()

Expected behavior
I would expect the toasts to show up, even after redirecting. A possible scenario in a real-life app would be to show the user that they are now logged in.

Environment Information
Please provide the following version information:

  • fastlite version: 0.0.9
  • fastcore version: 1.7.1
  • fasthtml version: 0.4.4

Confirmation
Please confirm the following:

  • I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
  • I have provided a minimal reproducible example
  • I have included the versions of fastlite, fastcore, and fasthtml
  • I understand that this is a volunteer open source project with no commercial support.

Additional context
Add any other context about the problem here.

Screenshots
If applicable, add screenshots to help explain your problem.

@vacmar01 vacmar01 added the bug Something isn't working label Aug 23, 2024
@pydanny pydanny self-assigned this Aug 25, 2024
@jph00 jph00 closed this as completed Aug 26, 2024
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

No branches or pull requests

3 participants