Comments (4)
Hi! I'd be happy to work through this problem with you.
If I open an Incognito tab without plugins the saga does not seem to lock the UI.
This is my first hunch of a potential problem. What extensions do you have installed (e.g. react-devtools
and redux-devtools
)? It is not uncommon for these tools to lock the UI thread because they are inspecting the react component tree and observing every single redux action being dispatched. I would try uninstalling them one-by-one to see if we can figure out which one is causing the UI lock -- it could be both.
// If a "yield delay(1);" is added here the UI is not locked.
Adding yield delay(1)
is really just a way to add this saga into a Macrotask queue in the browser, which could help with UI locking in certain scenarios. This is especially interesting for redux-saga
because sagas can and will run synchronously if there are no async operations being called. Feel free to consult our cheatsheet on which operations are blocking.
// This is a pure redux action, only updates the state selectedDates
// Alot of heavy renders are triggered by this, the UI seems to lock until these renders are resolved
yield put(flexHoursActions.setSelectedDates(selectedDates));
I would also investigate this action. Are you certain that no other sagas are being triggered here? It seems you already know that this is causing a lot of rendering, this might be a good place to try to figure out how to optimize performance.
Finally, I would try to monitor performance while this task is running. The "Performance" tab in the Chrome devtools is a great resource for this. It should help you pinpoint what is causing the UI thread to lock.
Hopefully that gives you enough to continue your investigation, good luck, and feel free to keep chatting here!
from redux-saga.
Thank you for your time !
... I would try uninstalling them one-by-one to see if we can figure out which one is causing the UI lock -- it could be both.
I did what you suggested regarding the plugins, the culprit is not a single plugin but an accumulation. The biggest culprit is LastPass for some reason.
Adding yield delay(1) is really just a way to add this saga into a Macrotask queue in the browser, which could help with UI locking in certain scenarios. This is especially interesting for redux-saga because sagas can and will run synchronously if there are no async operations being called.
This goes hand in hand with my current understanding aswell. I think there could be some nuance here which will make me understand the behaviour I'm seeing.
<button
onClick={() => {
console.log("1");
onClose(); // when state updates: console.log("2");
console.log("3");
startSaveSelectedDates(dates);
console.log("4");
}
/>
function* startSelectDatesSaga(
action: ActionType<typeof flexHoursActions.startSelectDates>,
) {
console.log("saga 1");
const { selectedDates } = action.payload;
yield put(flexHoursActions.setSelectedDates(selectedDates));
console.log("saga 2");
const {
employeeHours,
}: SagaReturnType<typeof actualAPI.getEmployeeHours> = yield call(
actualAPI.getEmployeeHours,
{
dates: selectedDates,
},
);
console.log("saga 3");
yield put(employeeHourActions.setEmployeeHours(getEmployeeHours));
console.log("saga 4");
}
The console says: 1, 3, saga 1, saga 2, 4, 2, saga 3, saga 4
where saga 2
happens immediatly after saga 1
.
In my mind I would expect 1, 2, 3, saga 1, saga 2, 4, saga 3, saga 4
And even with the yield delay(1)
the flow looks:
1, 3, 4, 2, saga 1, saga 2, saga 3, saga 4
where I would expect 1, 2, 3, 4, saga 1, saga 2, saga 3, saga 4
I guess why I'm not seeing 1, 2, 3
must be because of how react batches renders together.
And the reason why the UI locks is just because of that, react tryes to render the "is modal open" update together with the big render caused by: yield put(flexHoursActions.setSelectedDates(selectedDates));
. And the first time the UI unlocks is when the api call happens, that's why we see this behaviour.
So basically is what I wrote above how it works? If yes, the plugins slows down the rendering so much so that I experience the issue.
Thank you again, sorry if it ended up a bit confusing.
from redux-saga.
In your onClick
you are referencing startSaveSelectedDates(dates);
which is a saga. Is that actually how you are calling that function? If so then it will not work as expected. You need to dispatch an action that then calls startSaveSelectedDates
. This is usually done with a watcher saga that calls takeEvery
:
import { takeEvery } from 'redux-saga/effects';
function* watchSelectedDates() {
yield takeEvery("START_SELECTED_DATES", startSaveSelectedDates);
}
// then in react component
function App() {
const dispatch = yield* useDispatch();
const onClick = () => {
dispatch({ type: "START_SELECTED_DATES", payload: dates });
}
}
from redux-saga.
Hello again !
the onClick
is dispatching an action.
In my watcher
function I'm using takeLatest
not takeEvery
I'm positive that I do everything correctly regarding how actions are dispatched.
The code in my previous comment is just for explanation.
I bleieve this is just a understanding issue from my part.
from redux-saga.
Related Issues (20)
- Waiting for an action with takeMaybe / take after END is dispatched for SSR HOT 7
- Is it possible to selectively cancel tasks in an actionChannel? Ie cancel the 3rd task out of 5 running ones. HOT 5
- Is it possible for a saga to "trace" the effect "chain"? HOT 4
- Delay inside of while loop may never fire with React Native 0.71.6 HOT 2
- Redux 4.0 - Unable to access updated data using useSelector HOT 2
- could we add leading/trailing edge options for debounce? HOT 3
- Workflow has flaw
- Why not use the await and async instead of the generator and yield? HOT 1
- TS2345 error while putting thunk actions
- React native Redux Saga with Redux Tollkit
- Module '"redux-saga/effects"' has no exported member 'call'. HOT 4
- Is there a standard way to break while true loops with call effect when END is dispatched? HOT 1
- Can put type improvements be released downstream? HOT 2
- Sending very large files, tasks in parallel are using a lot of memory
- How to use package that use redux-saga as dependency when its in webpack externals? HOT 7
- Help me connect redux-saga with Nextjs 13.5 using app router HOT 2
- Update peer dependencies to include `redux@5` (currently beta) HOT 14
- feature request: interface for integration with other frameworks (like Vue) HOT 2
- Redux saga is not working in apps script react js project HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-saga.