Skip to content

Commit

Permalink
console: disable autosave when loading content for monaco editor
Browse files Browse the repository at this point in the history
  • Loading branch information
TattdCodeMonkey committed May 8, 2024
1 parent 5669d36 commit f6e7321
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface SetInitialValueParams {
/**
* Util function for reading the load_from parameter from the current url.
*/
const readLoadFromParam = () => {
export const readLoadFromParam = () => {
const [, queryString] = (window.location.hash || window.location.search || '').split('?');

const queryParams = parse(queryString || '', { sort: false }) as Required<QueryParams>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { useEffect, useRef } from 'react';
import { useSaveCurrentTextObject } from '../../../hooks';
import { readLoadFromParam } from './use_set_initial_value';

interface SetupAutosaveParams {
/** The current input value in the Console editor. */
Expand Down Expand Up @@ -38,6 +39,12 @@ export const useSetupAutosave = (params: SetupAutosaveParams) => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}

const loadFromParam = readLoadFromParam();
if (loadFromParam) {
// If we pre-loaded content we want to skip saving the state of the editor
return;
}
timerRef.current = window.setTimeout(saveCurrentState, saveDelay);

return () => {
Expand Down

0 comments on commit f6e7321

Please sign in to comment.