Skip to content

Commit

Permalink
fix null reference crashing ide during e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
joeizang committed Sep 18, 2023
1 parent 4cd4460 commit 6bad4eb
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions libs/remix-ui/workspace/src/lib/reducers/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ const fetchDirectoryContent = (
: state[state.mode].files
if (state.mode === 'browser') {
if (payload.path === ROOT_PATH) {
let files = normalize(payload.fileTree, ROOT_PATH, payload.type, state)
let files = normalize(payload.fileTree, state, ROOT_PATH, payload.type)
files = _.merge(files, state.browser.files[ROOT_PATH])
if (deletePath) delete files[deletePath]
return {[ROOT_PATH]: files}
Expand All @@ -975,7 +975,7 @@ const fetchDirectoryContent = (

if (prevFiles) {
prevFiles.child = _.merge(
normalize(payload.fileTree, payload.path, payload.type, state),
normalize(payload.fileTree, state, payload.path, payload.type),
prevFiles.child
)
if (deletePath) {
Expand All @@ -990,17 +990,17 @@ const fetchDirectoryContent = (
files = {
[payload.path]: normalize(
payload.fileTree,
state,
payload.path,
payload.type,
state
payload.type
)
}
}
return files
}
} else {
if (payload.path === ROOT_PATH) {
let files = normalize(payload.fileTree, ROOT_PATH, payload.type)
let files = normalize(payload.fileTree, state, ROOT_PATH, payload.type)
files = _.merge(files, state.localhost.files[ROOT_PATH])
if (deletePath) delete files[deletePath]

Expand All @@ -1012,7 +1012,7 @@ const fetchDirectoryContent = (

if (prevFiles) {
prevFiles.child = _.merge(
normalize(payload.fileTree, payload.path, payload.type, state),
normalize(payload.fileTree, state, payload.path, payload.type),
prevFiles.child
)
if (deletePath) {
Expand All @@ -1027,9 +1027,9 @@ const fetchDirectoryContent = (
files = {
[payload.path]: normalize(
payload.fileTree,
state,
payload.path,
payload.type,
state
)
}
}
Expand All @@ -1042,16 +1042,16 @@ const fetchWorkspaceDirectoryContent = (
state: BrowserState,
payload: {fileTree; path: string}
): {[x: string]: Record<string, FileType>} => {
const files = normalize(payload.fileTree, ROOT_PATH, null, state)
const files = normalize(payload.fileTree, state, ROOT_PATH, null)

return {[ROOT_PATH]: files}
}

const normalize = (
filesList,
state: BrowserState,
directory?: string,
newInputType?: 'folder' | 'file',
state?: BrowserState
newInputType?: 'folder' | 'file'
): Record<string, FileType> => {
let folders = {}
let files = {}
Expand Down Expand Up @@ -1098,8 +1098,9 @@ const normalize = (
type: 'file'
}
}
folders = sortFilesFetched(folders, state.browser.sort)
files = sortFilesFetched(files, state.browser.sort)

folders = sortFilesFetched(folders, state.browser?.sort)
files = sortFilesFetched(files, state.browser?.sort)
return Object.assign({}, folders, files)
}

Expand Down

0 comments on commit 6bad4eb

Please sign in to comment.