Skip to content

Conversation

@erikgaas
Copy link
Contributor

Followup to #777

I dove into the internals for how these functions work. The change works, but I dont think it always returns the correct response object which may influence the behavior of the toast.

For example:

def toast_after(resp, req, sess):
    if sk in sess and (not resp or isinstance(resp, (tuple,FT,FtResponse))):
        sess['toast_duration'] = req.app.state.toast_duration
        req.injects.append(render_toasts(sess))

The current code always passes in None which appears to be what exists in the req object. updating the wreq object to use the resp object appears to correctly pass it in.

That way if toast receives a Redirect response, for example, then it knows not to do the toast according to the code above.

@gitnotebooks
Copy link

gitnotebooks bot commented Sep 11, 2025

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

@erikgaas erikgaas requested a review from comhar September 11, 2025 23:12
@erikgaas
Copy link
Contributor Author

erikgaas commented Sep 11, 2025

Inputs to toast_after when not setting the wreq object:

after toast None <starlette.requests.Request object at 0x124e3a300> {'toast_duration': 5000, 'toasts': [('Successful Page Load!', 'success', False)]}
after toast None <starlette.requests.Request object at 0x124e39dc0> {'toast_duration': 5000}

Inputs to toast_after setting resp in the wreq object:

after toast <p>I love toast!</p> <starlette.requests.Request object at 0x165539eb0> {'toast_duration': 5000, 'toasts': [('Successful Page Load!', 'success', False)]}
after toast <starlette.responses.FileResponse object at 0x165477aa0> <starlette.requests.Request object at 0x1655399d0> {'toast_duration': 5000}

@erikgaas
Copy link
Contributor Author

I'll include this as a test in the notebook : )

@jph00 jph00 merged commit 3f2a824 into main Sep 12, 2025
2 checks passed
@jph00 jph00 deleted the erikgaas/fix_toasts776 branch September 12, 2025 23:38
@jph00
Copy link
Contributor

jph00 commented Sep 12, 2025

Thanks @erikgaas ! Can you think of any away to avoid having to create that test-specific pair of toast functions? Not a big deal, but would be nice if it were cleaner.

@jph00 jph00 added the bug Something isn't working label Sep 12, 2025
@jph00
Copy link
Contributor

jph00 commented Sep 12, 2025

BTW @erikgaas add a 'bug' or 'enhancement' label to PRs to ensure they get into the release notes. (I added this one).

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.

3 participants