-
Notifications
You must be signed in to change notification settings - Fork 780
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
diff and patching nodes with contentEditable='inherit' #176
Comments
Sounds like a virtualize bug. |
This gist exhibits the same problem without virtualize: http://requirebin.com/?gist=d96693e487580d462d4f var h = require('virtual-dom/h'),
diff = require('virtual-dom/diff'),
patch = require('virtual-dom/patch'),
createElement = require('virtual-dom/create-element'),
domify = require('domify'),
html = '<div id="App">Before</div>',
element = document.body.appendChild(domify(html)),
oldTree = h('div', { id: 'App', contentEditable: 'inherit' }, 'Before'),
newTree = h('div', { id: 'App' }, 'After'),
patches = diff(oldTree, newTree);
element = patch(element, patches); |
@RGBboy does it work if you explicitly provide the new value for |
@neonstalwart it works if you do something like the following: var h = require('virtual-dom/h'),
diff = require('virtual-dom/diff'),
patch = require('virtual-dom/patch'),
createElement = require('virtual-dom/create-element'),
domify = require('domify'),
html = '<div id="App">Before</div>',
element = document.body.appendChild(domify(html)),
oldTree = h('div', { id: 'App', contentEditable: 'inherit' }, 'Before'),
newTree = h('div', { id: 'App', contentEditable: true }, 'After'),
patches = diff(oldTree, newTree);
element = patch(element, patches); The issue is that the following two nodes will map to a dom element with var nodeA = h('div');
var nodeB = h('div', { contentEditable: 'inherit' }); Anyone trying to convert existing dom elements back to vnodes will get a |
This is a bug in virtual-dom. Virtual-dom will set a property to @Matt-Esch we need to either:
|
Wouldn't the try/catch option mean it would happen on every redraw? If so I think one of the whitelist options is a better way to go. |
Why can't we just call removeAttribute? Why set attribute that are specified as being removed by a patch operation as |
I have tried using There can be 2 solutions to this:
|
I have a pull request ready for You can try it using |
@bitinn I do not think that is the proper way to solve this because the bug occurs without using I think the proper solution is that virtual-dom must keep a whitelist of which DOM node properties are attributes and which aren't, and unfortunately, which modifications are legal in some cases. |
Sure it is not the simplest solution, but I think it is the proper one. We can't escape not dealing with the DOM's intricacies when working with it - as ugly as it is. The try/catch approach is not proper either because it just sweeps these issues under the rug and dings performance. This is the same approach React uses for the same reasons. See this list: https://github.com/facebook/react/blob/0.13-stable/src/browser/ui/dom/HTMLDOMPropertyConfig.js |
@alexmingoia yeah I would also prefer a fix from |
+1 for this issue. What shall we do about it? |
@egasimus Both vdom-virtualize and vdom-parser should have workaround this problem, how did you run into it? (edited: sorry for the garbled message, office 365 doesn't work too well with github email reply it seems.) |
@bitinn I'm not using either of those (at least not directly -- I don't know if they're actually the underlying components of the workflow centered around |
Andy news on this bug? I encountered it too:
|
For others encountering the same issue, I found a workaround. What I did is change a DOM structure like this: <div>
<div contentEditable="true">B</div>
</div> to something like this: <div>
<div>A</div>
<div contentEditable="true">B</div>
</div> Which gives trouble since in some cases virtual-dom tries to set contentEditable of the div To work around this, you have to make sure all siblings of the div's having a <div>
<div contentEditable="false">A</div>
<div contentEditable="true">B</div>
</div> |
If the contentEditable property is not specified on a node to update and the existing node has it, virtual-dom tries to set it to a blank string. This throws the following error in Chrome and Firefox:
Here is my setup that produces the error:
I also put together a requirebin to show the problem: http://requirebin.com/?gist=d96693e487580d462d4f
When vdom-virtualize creates the tree it finds the contentEditable property is set to
inherit
. Then when the new tree is created contentEditable is not specified so a patch is created to remove it. This then causes the error because contentEditable must be set to one oftrue
,false
,plaintext-only
, orinherit
.inherit
is the default value.There are a couple of solutions to this. Either when a node is created, if contentEditable is undefined it is set to
inherit
or when nodes are diffed if one node has contentEditable set toinherit
and the other undefined then the diff is nothing.The text was updated successfully, but these errors were encountered: