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

Remove toast notification loop #2072

Closed
vivaltech opened this issue Oct 19, 2023 · 2 comments
Closed

Remove toast notification loop #2072

vivaltech opened this issue Oct 19, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@vivaltech
Copy link
Contributor

vivaltech commented Oct 19, 2023

Describe the bug
Toast-type notifications appear in a loop.

Expected behavior
Toasts should appear only once when the user triggers them.

Current behavior
Toasts appears once and then are removed from the error message array. But after a few seconds, they are added again, entering an infinite loop.

Console logs

The message appears without interacting with the Minicart, since the useCart hooks contains the messages, and the only condition for them to appear in the screen is that the toast array has messages.

cart

image

TOAST I

TOAST II

TOAST III

Steps to reproduce
A step-by-step on how to reproduce the bug behavior.

A. Have a product out of stock
B. Set a limit of products in the mini cart and try to add more of those products

Possible Solution

To avoid them appearing more than once, we would have to keep the array of elements or add a property to allow us control when the popup was already shown.

For example:

@faststore\ui\node_modules@faststore\components\src\hooks\UIProvider.tsx

export interface Toast {
  message: string
  status: 'ERROR' | 'WARNING' | 'INFO'
  title?: string
  icon?: ReactNode
  // Add a new property to control display
  wasShown: boolean
}

(...)

case 'pushToast': {
  // Check if a toast with the same content already exists.
  const isDuplicate = state.toasts.some(existingToast =>
    existingToast.message === action.payload.message &&
    existingToast.status === action.payload.status
  );

  if (!isDuplicate) {
    return {
      ...state,
      toasts: [...state.toasts, action.payload],
    };
  }

  // Not added if it is a duplicate.
  return state; 
}

Additional context

These are the paths to the previous code:

Component:
packages\core\src\components\common\Toast\Toast.tsx

Hook:
@faststore\ui\node_modules@faststore\components\src\hooks\UIProvider.tsx

@vivaltech vivaltech added the bug Something isn't working label Oct 19, 2023
@hellofanny
Copy link
Contributor

Thanks for reporting this issue. We've created a task to investigate it 🔍

@hellofanny
Copy link
Contributor

We've done some fixes for the toast here

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

2 participants