Commit f1eaac5c authored by Paul Slaughter's avatar Paul Slaughter

Handle entry not found in changeFileContent action

This fixes some console errors being thrown
because of mystereious monaco race conditions.
parent debbf645
......@@ -166,6 +166,13 @@ export const getRawFileData = ({ state, commit, dispatch, getters }, { path }) =
export const changeFileContent = ({ commit, state, getters }, { path, content }) => {
const file = state.entries[path];
// It's possible for monaco to hit a race condition where it tries to update renamed files.
// See issue https://gitlab.com/gitlab-org/gitlab/-/issues/284930
if (!file) {
return;
}
commit(types.UPDATE_FILE_CONTENT, {
path,
content,
......
---
title: Fix console error being thrown when file is renamed
merge_request: 48275
author:
type: fixed
......@@ -510,8 +510,6 @@ describe('IDE store file actions', () => {
describe('changeFileContent', () => {
let tmpFile;
const callAction = (content = 'content\n') =>
store.dispatch('changeFileContent', { path: tmpFile.path, content });
beforeEach(() => {
tmpFile = file('tmpFile');
......@@ -521,11 +519,23 @@ describe('IDE store file actions', () => {
});
it('updates file content', () => {
return callAction().then(() => {
const content = 'content\n';
return store.dispatch('changeFileContent', { path: tmpFile.path, content }).then(() => {
expect(tmpFile.content).toBe('content\n');
});
});
it('does nothing if path does not exist', () => {
const content = 'content\n';
return store
.dispatch('changeFileContent', { path: 'not/a/real_file.txt', content })
.then(() => {
expect(tmpFile.content).toBe('\n');
});
});
it('adds file into stagedFiles array', () => {
return store
.dispatch('changeFileContent', {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment