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

lose focus after inputing one key in newitem input box with firefox browser #54

Closed
steven88888 opened this issue Feb 16, 2016 · 8 comments

Comments

@steven88888
Copy link

open https://preact-todomvc.surge.sh in Firefox Browser (ESR 38.5.0 for Linux) and check adding item of the example, after inputing any key, the focus will lose.

But it works well without the same issue in Chrome Browser.

@developit developit added the bug label Feb 16, 2016
@steven88888
Copy link
Author

add one new issue:
In Firefox, edit function can not work well. After appending some chars in editing status and pressing enter key, rendered result is the original value instead of new value.

@developit
Copy link
Member

Hi @steven88888 - apologies for the delayed reply. Definitely a bug and something I'm looking into. It seems like something is invalidating the root node of the todomvc example, blurring the input. I'll keep you posted on progress.

@c58
Copy link

c58 commented Feb 20, 2016

Just removed from app/index.js

<Router onChange={this.handleRoute}><Noop path="/" /></Router>

and all works fine.

@developit
Copy link
Member

@c58 Ah yeah, that makes sense. That was a hack at best anyway, I should have just parsed the URL without pulling in preact-router.

@c58
Copy link

c58 commented Feb 20, 2016

I think i found the problem. Router's nodeType is 3 (text dom node), but it is not a "string" vnode, as expected in isSameNodeType.

// attempt to pluck a node of the same type from the existing children
            if (!child && min<childrenLen) {
                for (let j=min; j<childrenLen; j++) {
                    let c = children[j];
                    if (c && isSameNodeType(c, vchild)) {
                        child = c;
                        children[j] = null;
                        if (j===childrenLen-1) childrenLen--;
                        if (j===min+1) min++;
                        break;
                    }
                }
            }

In this case every update will make a redraw from the root, because new children is never equals to previous children.

@developit
Copy link
Member

@c58 Hmm - this must be using the old version of preact-router that was not using High Order components to render children? The package.json for preact-todomvc has preact-router@1.1.0 though, which was using High Order (switchover was 1.0.0).

How are you checking the nodeType value of Router?

Also heads up: the child diffing algo is a bit different in 4.0. Still working on getting my branch pushed!

@c58
Copy link

c58 commented Feb 20, 2016

How are you checking the nodeType value of Router?

Just debug in a browser :) Open page, write some letters in input, set a pointer in a line:

if (c && isSameNodeType(c, vchild)) {

and write some letter in an input. And here we are, "c" is a dom node of a Router, vchild is a Router object. c.nodeType is 3.

In my research im using preact 3.4.0 and router 1.2.3

@c58
Copy link

c58 commented Feb 21, 2016

If change isSameNodeType to:

  function isSameNodeType(node, vnode) {
    if (isString(vnode)) return node.nodeType === 3;
    if (isFunctionalComponent(vnode)) return true;
    var nodeName = vnode.nodeName;
    if (isFunction(nodeName)) return node._componentConstructor === nodeName;
    return toLowerCase(node.nodeName) === nodeName;
  }

then issues will be fixed

@developit developit added this to the 4.0 milestone Feb 22, 2016
marvinhagemeister added a commit that referenced this issue Mar 2, 2019
Golf: diffLevel -» isRootDiff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants