Skip to content

Commit

Permalink
fix(DMX): Fixes a memory leak that causes the DMX system to slow down…
Browse files Browse the repository at this point in the history
… and crash after several minutes of use. Closes #3042
  • Loading branch information
alexanderson1993 committed Dec 2, 2020
1 parent 54a3bda commit 67a249f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion server/processes/clientPing.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ const clientPing = () => {
pubsub.publish("clientPing", c);
}
});
setTimeout(clientPing, 5000);
setTimeout(clientPing, 1000 * 60);
};
clientPing();
38 changes: 24 additions & 14 deletions src/helpers/hooks/useLocalStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,30 @@ export default function useLocalStorage(key, initialValue) {

// Return a wrapped version of useState's setter function that ...
// ... persists the new value to localStorage.
const setValue = value => {
try {
// Allow value to be a function so we have same API as useState
const valueToStore =
value instanceof Function ? value(storedValue) : value;
// Save state
setStoredValue(valueToStore);
// Save to local storage
window.localStorage.setItem(key, JSON.stringify(valueToStore));
} catch (error) {
// A more advanced implementation would handle the error case
console.error(error);
}
};
const setValue = React.useCallback(
value => {
try {
// Allow value to be a function so we have same API as useState
// Save state
setStoredValue(storedValue => {
try {
const valueToStore =
value instanceof Function ? value(storedValue) : value;

window.localStorage.setItem(key, JSON.stringify(valueToStore));
return valueToStore;
} catch {
return storedValue;
}
});
// Save to local storage
} catch (error) {
// A more advanced implementation would handle the error case
console.error(error);
}
},
[key],
);

return [storedValue, setValue];
}

0 comments on commit 67a249f

Please sign in to comment.