What you were expecting:
Saving on the edit component view should trigger a PUT request.
What happened instead:
No PUT request is triggered. Moreover:
undoable={false}, the undo popup does not showSteps to reproduce:
See the CodeSandbox
https://codesandbox.io/s/great-goldstine-h2u1n
Related code:
// in src/index.js
/* eslint react/jsx-key: off */
import React from "react";
import { Admin, Resource } from "react-admin"; // eslint-disable-line import/no-unresolved
import { render } from "react-dom";
import Layout from "./Layout";
import posts from "./posts";
import jsonServerProvider from "ra-data-json-server";
import { BrowserRouter as Router } from "react-router-dom";
import { Route, Switch } from "react-router-dom";
render(
<Router>
<Switch>
<Route
path="/"
exact
component={() => (
<Admin
dataProvider={jsonServerProvider(
"https://my-json-server.typicode.com/typicode/demo/"
)}
title="Example Admin"
layout={Layout}
>
{permissions => [<Resource name="posts" {...posts} />]}
</Admin>
)}
/>
</Switch>
</Router>,
document.getElementById("root")
);
// in src/post.js
import React from 'react';
import {
Datagrid,
Edit,
List,
SimpleForm,
TextField,
TextInput,
} from 'react-admin';
export const PostList = props => (
<List {...props}>
<Datagrid rowClick="edit">
<TextField source="id" />
<TextField source="title" />
</Datagrid>
</List>
);
export const PostEdit = (props) => (
<Edit {...props}>
<SimpleForm>
<TextInput disabled label="Id" source="id" />
<TextInput source="title" />
</SimpleForm>
</Edit>
);
Other information:
dispatch in the upgrade somehow? I tried to browse the react admin code but could not find my way through.Environment
I can't reproduce this bug in master.
The code you provide isn't sufficient to detect a problem - it could be e.g. in the authProvider, or in the CORS headers sent by your API - or to reproduce it, as all the files aren't included.
Please fork the react-admin CodeSandbox and tweak it to reproduce the problem.
Thank you @fzaninotto for following up.
I am not sure how I can reproduce the issue on CodeSandbox. I couldn't find an online json stub server that works with ra-simple-rest-provider and I can't reproduce the issue with ra-data-json-server: https://codesandbox.io/s/restless-fog-rryif?fontsize=14&hidenavigation=1&theme=dark
Do you know of one that would work?
Do you have anything in mind when you mention the authProvider or the CORS headers that could cause this behaviour? I don't see anything in the console that would suggest CORS or authentication failure
There is no fundamental difference between ra-simple-rest-provider and ra-data-json-server. If you can't reproduce the problem with the first, you probably won't manage to reproduce it with the second. That seems to show that the problem is in another part of your code. You should dig further.
You're absolutely right @fzaninotto , I have the same issue using ra-data-json-server locally. It's already very helpful to know that.
Digging a little further, this seems to happen when I wrap the App component in a route
When I render the react admin App directly without routing, the bug doesn't appear.
With that info, I managed to reproduce the issue on CodeSandbox. I've edited the original question title and body to make it more accurate.
https://codesandbox.io/s/great-goldstine-h2u1n
I'm not sure if this is a bug or if I'm doing something exotic/inappropriate
Thanks. I found this earlier navigating through the redux actions, because CRUD_UPDATE is not triggered. I haven't found anything meaningful yet but I'll keep digging.
I don't know if you noticed, I've updated the question with a CodeSandbox example, hopefully it makes my issue more explicit.
I think there's an issue with the redirection when the component is wrapped in a router.
Thanks for the codesandbox. I can reproduce the issue. It seems that whenever I go to the Edit view, the posts resource is unregistered... I don't understand why. I'll dig further.
OK, so the problem comes from including the react-admin app in another Router. This is not supported by react-admin. If you manage to make it work, great! Otherwise, it's not something we want to spend time on, so I'll close this issue.
As a side note, maybe sharing the history between your router and the react-admin router will help.
Thanks for taking the time to look into it.
However it seems to me that this is an important feature for users who want to include react-admin in another redux application. If you already have an app in which you want to include react-admin, there's a great chance that this app uses react router. If so, how are you supposed to do it?
Most helpful comment
Thanks for taking the time to look into it.
However it seems to me that this is an important feature for users who want to include react-admin in another redux application. If you already have an app in which you want to include react-admin, there's a great chance that this app uses react router. If so, how are you supposed to do it?