olmokramer / atom-tree-view-git-branch

Switch git branches from the tree view
MIT License
9 stars 2 forks source link

Cannot read property 'classList' of null TypeError: Cannot read property 'classList' of null #4

Closed mpfilbin closed 9 years ago

mpfilbin commented 9 years ago

I am receiving this error in the console of the developer tools:

This seems related to #2, so let me know if I need to close this issue and append onto that one.

Window load time: 820ms
Cannot read property 'classList' of null TypeError: Cannot read property 'classList' of null
    at getProjectRootEl (/Users/mfilbin/.atom/packages/tree-view-git-branch/lib/main.js:71:12)
    at /Users/mfilbin/.atom/packages/tree-view-git-branch/lib/main.js:60:29
    at process._tickCallback (node.js:365:9)

The exception is raised by this line of code:

let projectRootEl = getProjectRootEl(treeViewEl, projectPath);

Specifically when looping to find the project root element for the Tree View.

function getProjectRootEl(treeViewEl, path) {
  // treeViewEl comes in an instance of HTMLDivElement
  // path comes in as a String.
  var el = treeViewEl.querySelector(`[data-path="${path}"]`);
  // el is null here
  while(!el.classList.contains('project-root')) el = el.parentNode;
  return el;
}

I am running Atom 1.0.19 on Mac OS 10.10.5 (Yosemite).

How else can I help to troubleshoot and fix this?

karrots commented 9 years ago

I also get this error. Works fine on my Linux machine but Windows 7 its getting this error.

olmokramer commented 9 years ago

I'm sorry for the late reply, I missed this one. Thanks for the report, I'll look into it when I have some time.

yoohahn commented 9 years ago

It looks like there is an issue with \ on windows. path in my end is D:\project but to be able to match \ we need to escape them. So I changed line 78; var el = treeViewEl.querySelector([data-path="${path}"]); to look like var el = treeViewEl.querySelector([data-path*="${path.replace(/\\/g, '\\\\')}"]); (This is not a good solution, but it works for me since im only using windows at the office )

The reason for me addin the * in the selector is that in a few project I work in im opening a folder deep in the folder hierarchy.

olmokramer commented 9 years ago

@yoohahn Thanks for finding that out! I don't have windows installed, so I probably wouldn't have thought of that... I'll patch it right away!

I didn't even know about the subdirectories as the project root, very cool!

olmokramer commented 9 years ago

Version 0.0.4 is up. Please let me know if it solves your issues

yoohahn commented 9 years ago

That worked! Was about to create a PR but you was faster :)

Another thing that you could do is to make a check for the platform, but should not make any difference from the solution you posted :) if ( process.platform.toLowerCase().indexOf("win") !== -1 ) path = path.replace(/\/g, '\');

olmokramer commented 9 years ago

I don't think that's necessary, and in case some other platform can have a \ in directory names they would have to be escaped there as well...