diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js index d96c245d91282cd5b77dd70dfde4f72b708823b1..8b43c7238fd9951266fd196520f212f2d9f10f91 100644 --- a/app/assets/javascripts/ide/stores/actions/file.js +++ b/app/assets/javascripts/ide/stores/actions/file.js @@ -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, diff --git a/changelogs/unreleased/284930-fix-entry-not-found-change-file-content.yml b/changelogs/unreleased/284930-fix-entry-not-found-change-file-content.yml new file mode 100644 index 0000000000000000000000000000000000000000..8194806f9c05696f74a5d308f8edfa86326765c0 --- /dev/null +++ b/changelogs/unreleased/284930-fix-entry-not-found-change-file-content.yml @@ -0,0 +1,5 @@ +--- +title: Fix console error being thrown when file is renamed +merge_request: 48275 +author: +type: fixed diff --git a/spec/frontend/ide/stores/actions/file_spec.js b/spec/frontend/ide/stores/actions/file_spec.js index cc290fc526eef804e6db7d9be0525ed84d76b793..744ac086b5f6eb6e3ed537d4f1c2c0db97347527 100644 --- a/spec/frontend/ide/stores/actions/file_spec.js +++ b/spec/frontend/ide/stores/actions/file_spec.js @@ -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', {