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

After a redirect, the loader data doesn't include any toast data #22

Open
chanhman opened this issue Jul 9, 2024 · 2 comments
Open

Comments

@chanhman
Copy link

chanhman commented Jul 9, 2024

I am having difficulties with the redirect methods. I am unable to get the data needed to display my toast. However, when I use jsonWithSuccess, I can. If there was a way to also include a redirect URL, I would continue to use it, but I cannot.

I have tested the following within my action function:

 return jsonWithSuccess(
      {
        result: 'Data saved successfully',
      },
      {
        message: 'Created connection!!',
      },
    );

And

    return redirectWithSuccess(
      '/web/dashboard', 
      {
        message: 'Created connection',
      },
    );

With the latter, the redirect works as expected. However, I can't get my toast to work like the jsonWithSuccess implementation. It is my understanding that my root loader data would also include it, but when I use the redirect methods, that is not the case.

root.tsx

const { toast, headers: toastHeaders } = await getToast(request);

  return json(
    {
      themeMode: cookie.themeMode,
      inactivityMins: loginInfo?.inactivityMins,
      csrfToken,
      isXcm,
      toast,
    },
    { headers: toastHeaders },
  );

I was able to reproduce this in the test-app:

  1. Go to src/test-apps/testing-app/app/routes/_index.tsx
  2. Change import { redirectWithError } from "~/toast"; to import { redirectWithError } from "remix-toast";
  3. Click on Click Me

Lastly, I tried implementing ~/toast into my app with no success.

@goliney
Copy link

goliney commented Sep 12, 2024

I experience the same problem.

@AlemTuzlak
Copy link
Contributor

I just looked at your repro and if you change the root to use getToast from remix-toast it works as expected. Are you throwing your redirect or returning it? IF you throw the redirect it has to be awaited, eg throw await redirectWithSuccess

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

3 participants