Skip to content

Commit

Permalink
remove debouncing/throttling of interfaces actions
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeRx committed Sep 19, 2024
1 parent 82b0321 commit bdab957
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions ui/components/app/snaps/snap-ui-input/snap-ui-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const SnapUIInput: FunctionComponent<

return (
<FormTextField
autoFocus
className="snap-ui-renderer__input"
id={name}
value={value}
Expand Down
35 changes: 15 additions & 20 deletions ui/contexts/snaps/snap-interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,13 @@ export const SnapInterfaceContextProvider: FunctionComponent<

// The submission of user input events is debounced or throttled to avoid
// crashing the snap if there's too many events sent at the same time.
const snapRequestDebounced = debounce(rawSnapRequestFunction, 200);
const snapRequestThrottled = throttle(rawSnapRequestFunction, 200);
const snapRequestDebounced = rawSnapRequestFunction;
const snapRequestThrottled = rawSnapRequestFunction;

// The update of the state is debounced to avoid crashes due to too many
// updates in a short amount of time.
const updateStateDebounced = debounce(
(state) => dispatch(updateInterfaceState(interfaceId, state)),
200,
);
const updateStateDebounced = (state) =>
dispatch(updateInterfaceState(interfaceId, state));

/**
* Handle the submission of an user input event to the Snap.
Expand All @@ -152,7 +150,7 @@ export const SnapInterfaceContextProvider: FunctionComponent<
flush = false,
}) => {
// We always flush the debounced request for updating the state.
updateStateDebounced.flush();
// updateStateDebounced.flush();

const fn = THROTTLED_EVENTS.includes(event)
? snapRequestThrottled
Expand All @@ -163,20 +161,17 @@ export const SnapInterfaceContextProvider: FunctionComponent<
// Certain events have their own debounce or throttling logic
// and therefore may want to flush
if (flush) {
fn.flush();
// fn.flush();
}
};

const handleInputChangeDebounced = debounce(
(name, value) =>
handleEvent({
event: UserInputEventType.InputChangeEvent,
name,
value,
flush: true,
}),
300,
);
const handleInputChangeDebounced = (name, value) =>
handleEvent({
event: UserInputEventType.InputChangeEvent,
name,
value,
flush: true,
});

/**
* Handle the value change of an input.
Expand Down Expand Up @@ -245,7 +240,7 @@ export const SnapInterfaceContextProvider: FunctionComponent<

internalState.current = state;
updateStateDebounced(state);
updateStateDebounced.flush();
//updateStateDebounced.flush();
uploadFile(name, fileObject);
});

Expand All @@ -256,7 +251,7 @@ export const SnapInterfaceContextProvider: FunctionComponent<

internalState.current = state;
updateStateDebounced(state);
updateStateDebounced.flush();
//updateStateDebounced.flush();
uploadFile(name, null);
};

Expand Down

0 comments on commit bdab957

Please sign in to comment.