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

Can you show toasts from loaders using a Link #26

Open
MattyBalaam opened this issue Sep 11, 2024 · 6 comments
Open

Can you show toasts from loaders using a Link #26

MattyBalaam opened this issue Sep 11, 2024 · 6 comments

Comments

@MattyBalaam
Copy link

MattyBalaam commented Sep 11, 2024

I have noticed the toasts do not show if you navigate to a page with a Link component because it does not seem like the root loader re-runs. Is this correct?

Example repo: https://github.com/MattyBalaam/remix-toast-loader-test

My use case is to show a toast message if some low-priority api data resources do not load.

@MattyBalaam
Copy link
Author

Hmm, so I can do this by passing in reloadDocument but I don’t really want to do it that way because it loads everything, not just loader data.

@MattyBalaam
Copy link
Author

MattyBalaam commented Sep 12, 2024

I wondered if single-fetch might be the answer, here - but it seems to be even odder…

It now seems to call the root on every load, but now it appears to call the last toast, not the current one 🤯

Screen.Recording.2024-09-12.at.07.50.14.mov

EDIT: I guess that makes sense because the root loader runs first, so the new toast has not been set 🤔

@AlemTuzlak
Copy link
Contributor

Root re-runs under certain conditions, not all of em, page navigations do not always trigger it, I think if you DON'T have a loader on the page you're navigating to it doesn't re-trigger

@MattyBalaam
Copy link
Author

In this case (see example) all routes have a loader… but the root loader does not run in classic mode with client-side navigation, and in single fetch it seems like the root loader runs first so it gets the previous toast!

I’m struggling to think how this could work and it feels like reading the loaderData in each route component and triggering the notification that way is the only solution to this problem.

@AlemTuzlak
Copy link
Contributor

well another thing you could do is add an onClick handler to the Link component, eg:

<Link to="/somewhere" onClick={() =>showToast()} />

@MattyBalaam
Copy link
Author

MattyBalaam commented Sep 19, 2024

In our case we are showing toasts based on responses to APIs called in the loader, e.g. a 404 error calling a resource. This feels like an unsolvable problem with the session flash approach

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

No branches or pull requests

2 participants