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

select attr is "reset" with FF #148

Open
albertosantini opened this issue Nov 28, 2017 · 12 comments
Open

select attr is "reset" with FF #148

albertosantini opened this issue Nov 28, 2017 · 12 comments

Comments

@albertosantini
Copy link
Contributor

albertosantini commented Nov 28, 2017

In FF (57+) the selected item toggles between the correct one, bar, and the first one foo.

With Chrome (62.x), it works as expected: bar is always selected (and displayed).

I read again the documentation about boolean attrs. :)
Am I missing anything here?

class Foo {
    static init() {
        const render = hyperHTML.bind(document.querySelector("foo"));

        const state = {
            items: [
                { id: 1, text: "foo" },
                { id: 2, text: "bar" },
                { id: 3, text: "baz" }
            ],
            selectedItem: 2
        };

        render`
            <select>${
                state.items.map(item => hyperHTML.wire()`
                    <option value="${item.id}" selected="${state.selectedItem === item.id}">
                        ${item.text}
                    </option>`)
            }</select>
        `;
    }
}

setInterval(Foo.init, 100);

Live example: https://plnkr.co/edit/evFbsDnoN7iwooJpqw33?p=preview

@WebReflection
Copy link
Owner

WebReflection commented Nov 28, 2017

this is the most horrifying Firefox bug I've ever seen to date:
https://codepen.io/WebReflection/pen/WXaeWj?editors=0010

@WebReflection
Copy link
Owner

Filed a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1421260

@marcoscaceres
Copy link
Contributor

Argh! Will get it prioritized and fixed.

@albertosantini
Copy link
Contributor Author

I saw the bug has been confirmed.
I tested with FF 56-58.beta and it is there: so I suppose it is also in the previous releases.
Hope it will be fixed for the final 58.

In the meantime my ugly workaround is the following one:

class Foo {
    static init() {
        const render = hyperHTML.bind(document.querySelector("foo"));

        const state = {
            items: [
                { id: 1, text: "foo" },
                { id: 2, text: "bar" },
                { id: 3, text: "baz" }
            ],
            selectedItem: 2
        };

        const node = render`
            <select>${
                state.items.map(item => hyperHTML.wire()`
                    <option value="${item.id}">
                        ${item.text}
                    </option>
                `)
            }</select>
        `;
        document.querySelector(`option[value='${state.selectedItem}']`).selected = true;
    }
}

setInterval(Foo.init, 100);

Live example: https://plnkr.co/edit/6Guxg7nEIYPzJmt5IaZR?p=preview

Tested also in my complex use case and it works correctly.

@WebReflection
Copy link
Owner

it's a diffing algorithm issue, if you use majinbuu engine instead, everything is fine without needing workarounds.

https://plnkr.co/edit/IgjYDmRx2doychS6zDnw?p=preview

@albertosantini
Copy link
Contributor Author

albertosantini commented Dec 4, 2017

Bug resolved in FF 58.0b8. :)

P.S. No, I am sorry, I see ghosts. It is not resolved. Sorry for the noise.

@WebReflection
Copy link
Owner

I am planning to implement domdiff as universal solution for hyperHTML so that current engine will go and majinbuu won't be needed.

That should also, hopefully, solve, this issue forever, even on older FF.

@WebReflection
Copy link
Owner

actually ... never mind: https://codepen.io/WebReflection/pen/EbMwwV?editors=0010

this bug affects Vue.js and Preact with keyed elements too ... this is very bad

@WebReflection
Copy link
Owner

P.S. @albertosantini if you used wires properly thought, you wouldn't have experienced any of this. You are trashing options every time. It's still a FF bug, but you should never trash nodes when it's possible.

@ematipico
Copy link

I am planning to implement domdiff as universal solution for hyperHTML so that current engine will go and majinbuu won't be needed.

What is the reason behind this decision?

@WebReflection
Copy link
Owner

WebReflection commented Dec 4, 2017

What is the reason behind this decision?

nobody is writing hyperHTML engines and AFAIK nobody uses hyperhtml-majinbuu but the point is that current default engine doesn't scale in terms of performance and neither does majinbuu.

Instead of having all these hybrid, not fully usable solutions for this or that case, I'd rather use what Vue.js and Preact are using to diff their content (a fork of snabbdom) which apparently performs as good as majinbuu but it scales way more without needing checks on array size and all the caveats one or the other solution has.

On top of that, removing complexity and abstractions with 3rd parts engines, will reduce the library size closer to 4K instead of 5K

@WebReflection
Copy link
Owner

in case anyone is curious about engine-less edition of hyperHTML:
#149

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

4 participants