Commit c24fdc88 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '284930-fix-entry-not-found-change-file-content' into 'master'

Handle entry not found in changeFileContent action

See merge request gitlab-org/gitlab!48275
parents 4e612b80 f1eaac5c
...@@ -166,6 +166,13 @@ export const getRawFileData = ({ state, commit, dispatch, getters }, { path }) = ...@@ -166,6 +166,13 @@ export const getRawFileData = ({ state, commit, dispatch, getters }, { path }) =
export const changeFileContent = ({ commit, state, getters }, { path, content }) => { export const changeFileContent = ({ commit, state, getters }, { path, content }) => {
const file = state.entries[path]; 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, { commit(types.UPDATE_FILE_CONTENT, {
path, path,
content, 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', () => { ...@@ -510,8 +510,6 @@ describe('IDE store file actions', () => {
describe('changeFileContent', () => { describe('changeFileContent', () => {
let tmpFile; let tmpFile;
const callAction = (content = 'content\n') =>
store.dispatch('changeFileContent', { path: tmpFile.path, content });
beforeEach(() => { beforeEach(() => {
tmpFile = file('tmpFile'); tmpFile = file('tmpFile');
...@@ -521,11 +519,23 @@ describe('IDE store file actions', () => { ...@@ -521,11 +519,23 @@ describe('IDE store file actions', () => {
}); });
it('updates file content', () => { 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'); 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', () => { it('adds file into stagedFiles array', () => {
return store return store
.dispatch('changeFileContent', { .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