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

front: fix infinite loop caused by warped map #5462

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion front/src/common/Map/WarpedMap/SimulationWarpedMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ const SimulationWarpedMap: FC<{ collapsed?: boolean }> = ({ collapsed }) => {
setState({ ...state, osrd: newTransformedOSRDData });
}
});
}, [state]);
// We call the function only if the state's type change otherwise we go to an infinite loop
}, [state.type]);

return (
<div
Expand Down
9 changes: 7 additions & 2 deletions front/src/reducers/osrdconf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,16 @@ export function updateInfraID(infraID: number | undefined): ThunkAction<ActionUp

if (infraID) {
try {
// get switch types with rtk query
const { data: newSwitchTypes = [] } = await dispatch(
// We use this syntax first because of the .initiate, to be able to unsubscribe from the results later
const results = dispatch(
osrdEditoastApi.endpoints.getInfraByIdSwitchTypes.initiate({ id: infraID })
);
const { data: newSwitchTypes = [] } = await results;
dispatch(updateSwitchTypes(newSwitchTypes as SwitchType[]));

// Manually dispatching an RTK request with .initiate will create a subscription entry, but we need to unsubscribe from that data also manually - otherwise the data stays in the cache permanently.
// This prevents unwanted api calls
results.unsubscribe();
} catch (e) {
/* empty */
}
Expand Down
Loading