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

Passing a custom Alert component to notify() removes the whole app from the DOM #9841

Open
jstoeffler opened this issue May 11, 2024 · 1 comment
Labels

Comments

@jstoeffler
Copy link

What you were expecting:

I have a custom mutationOptions with onError on a Create form that displays a custom Alert
component:

      mutationOptions={{
        onError: () => {
          notify(<Alert severity="error">This is a custom error</Alert>);
        },
      }}

This works fine:

Screen.Recording.2024-05-11.at.15.13.27.mov

I would expect to be able to extract this alert's JSX to do something like:

const CustomAlertComponent = () => {
  return <Alert severity="error">This is a custom error</Alert>;
};

//...

      mutationOptions={{
        onError: () => {
                notify(<CustomAlertComponent />);
         },
      }}

And it should work the same.

What happened instead:

I get a white page instead of seeing the error, it breaks the app and there is no error log:

Screen.Recording.2024-05-11.at.15.12.39.mov

Steps to reproduce:

Related code:

import { Create, SimpleForm, TextInput, useNotify } from "react-admin";
import { Alert } from "@mui/material";

const CustomAlertComponent = () => {
  return <Alert severity="error">This is a custom error</Alert>;
};

export const PostCreate = () => {
  const notify = useNotify();
  return (
    <Create
      mutationOptions={{
        onError: () => {
          // This does not work (creates a blank page with no content):
          notify(<CustomAlertComponent />);
          // This works:
          // notify(<Alert severity="error">This is a custom error</Alert>);
        },
      }}
    >
      <SimpleForm>
        <TextInput source="title" />
        <TextInput source="body" />
      </SimpleForm>
    </Create>
  );
};

insert short code snippets here

Other information:

Environment

  • React-admin version: 4.12.0
  • Last version that did not exhibit the issue (if applicable): N/A
  • React version: 18.2.0
  • Browser: Chrome
  • Stack trace (in case of a JS error): N/A
@erwanMarmelab
Copy link
Contributor

Hello @jstoeffler,

Nice catch 👍, reproduced in this Stackblitz (by clicking on the "click" button in the Post create page)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants