Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'previousSibling' of null #12

Closed
piotrpalek opened this issue Jun 17, 2015 · 7 comments · Fixed by #15
Closed

Uncaught TypeError: Cannot read property 'previousSibling' of null #12

piotrpalek opened this issue Jun 17, 2015 · 7 comments · Fixed by #15

Comments

@piotrpalek
Copy link
Contributor

Hey I was trying to port my app to ember 1.13.1 and started getting this error when transitioning to other routes. I will try to make a jsbin later on, just posting this in case it is something known.
The error occurs here:

    removeRange: function removeRange(firstNode, lastNode) {
      var node = lastNode;
      do {
        var next = node.previousSibling; // <-- error from issue title
@piotrpalek
Copy link
Contributor Author

Ok I didn't manage to replicate it in a jsbin (don't know if/how it's possible to load the addon there) but here's a really simple example app: https://github.com/piotrpalek/wormhole-bug which shows the bug. You have to run the app and click the Second link and it will trigger the error.

@piotrpalek
Copy link
Contributor Author

@lukemelia I saw you looked at a similiar issue (#9) do you think this could be also ember related?

@krisselden
Copy link
Contributor

This should have been fixed with emberjs/ember.js#11425 but you are hitting it in 1.13.1? If so, I'd love some help tracking it down. If you could make a jsbin or fiddle replicating it would be greatly appreciated. Also, if you can set a breakpoint in wormhole willDestroyElement to see if it is being called twice and include the stack trace of both calls that would be helpful.

@piotrpalek
Copy link
Contributor Author

@krisselden yes even in 1.13.2, I provided a link above to an example app, I am not sure how to setup a jsfiddle with an ember-cli addon (in this case ember-wormhole). Do you have some base jsbin (ember+wormhole) where I could show the bug, assuming the above github repo isn't enough?

@piotrpalek
Copy link
Contributor Author

@krisselden so the willDestroyElement method isn't called twice, but I noticed that here:

    willDestroyElement: function willDestroyElement() {
      var _this = this;

      var firstNode = this._firstNode;
      var lastNode = this._lastNode; // <-- the same as firstNode
      run.schedule('render', function () {
        _this.removeRange(firstNode, lastNode);
      });
    }

firstNode and lastNode is the same. So later in removeRange (where the error occurs):

    removeRange: function removeRange(firstNode, lastNode) {
      var node = lastNode;
      do {
        var next = node.previousSibling; // error occurs here, I assume that's because it doesn't have a previousSibling since it's the first node?
        if (node.parentNode) {
          node.parentNode.removeChild(node);
        }
        node = next;
      } while (node !== firstNode);
    }

@krisselden
Copy link
Contributor

@piotrpalek thanks, this is definitely then a wormhole bug. Do you want to submit a PR? I know that this code handles this case https://github.com/krisselden/morph-range/blob/master/lib/morph-range/utils.js#L10-L14

@piotrpalek
Copy link
Contributor Author

@krisselden I've made a PR, but as noted there, I tried to write a test for this but when I bumped the ember version to 1.13 in the addon, other tests were breaking as well. So I couldn't really test this without fixing all of them.
I also will have to maintain a seperate branch with this fix applied to the 0.3.1 version of ember-wormhole, because master doesn't work with https://github.com/yapplabs/ember-modal-dialog which I am also using.

xcambar pushed a commit to xcambar/ember-wormhole that referenced this issue Nov 4, 2016
Move ember-cli-version-checker back to dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants