Search code examples
admin-on-rest

route push in custom saga does not cause re-render


i have a custom saga, which responds to a simple search user action, if it finds a single user, it should show it otherwise go to the user list.

Problem is that when i push the new route, i can see that state changes but the app is not rendering the new route. I looked through the source and cant find any update-blockers.

If i do the push action twice, for some reason, only causing the location key to change again, the app re-renders correctly. Don't know where to keep looking, so any ideas of what the problem is?

import { put, takeEvery, all, call } from "redux-saga/effects";
import { searchUser } from "../services/userService";
import { SEARCH_USER } from "../actions/searchUser";
import { showNotification } from "admin-on-rest";
import { push, replace } from "react-router-redux";

function* handleSearchUser(action) {
try {
    const { searchParam } = action.payload;
    const filter = {};
    if (isNaN(searchParam)) {
      filter.Email = searchParam;
   }  else {
      filter.UserId = parseInt(searchParam);
}
    const result = yield call(searchUser, 0, 25, filter);

    if (result && result.length === 1) {
      // Duplicate this row and the page re-renders the correct page
      yield put(push(`/User/${result[0].UserId}/show`));
    } else {
      yield put(
        push(
          `/User?filter=${JSON.stringify(
            filter
          )}&order=DESC&sort=id&page=1&perPage=25`
        )
      );
    }
  } catch (error) {
    console.error(error);
    yield put(showNotification("Error: error when searching", "warning"));
  }
}

export default function* searchUserSaga() {
  yield all([takeEvery(SEARCH_USER, handleSearchUser)]);
}

Solution

  • Was using gatsbyjs. I switched to Create React App for building and all problems went away.