-
-
Notifications
You must be signed in to change notification settings - Fork 926
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
Standardise vnode text representation #2669
Comments
I'm game. Simplifies the hyperscript factory, too, and honestly, if we can get rid of a vnode field, all the better. |
First pass on step 1 and a whole chunk of the component test suite is failing because it’s manually constructing vnodes. I’m going to take the opportunity to refactor these to use hyperscript. |
Just thought I'd let you know I've wanted to do this for literal years. Not just for the component test suite, but everything. |
In Mithril 2.2+, text vnodes are consistently represented as child nodes and the `text` attribute seems to be undefined. MithrilJS/mithril.js#2669
In Mithril 2.2+, text vnodes are consistently represented as child nodes and the `text` attribute seems to be undefined. MithrilJS/mithril.js#2669
In Mithril 2.2+, text vnodes are consistently represented as child nodes and the `text` attribute seems to be undefined. MithrilJS/mithril.js#2669
In Mithril 2.2+, text vnodes are consistently represented as child nodes and the `text` attribute seems to be undefined. MithrilJS/mithril.js#2669
In Mithril 2.2+, text vnodes are consistently represented as child nodes and the `text` attribute seems to be undefined. MithrilJS/mithril.js#2669
The problem
Mithril currently produces unpleasantly different vnode shapes for elements depending on their text content, forcing us to consider different sources of truth for the representation of what ought to be a single thing. As a result we end up with some leaf element vnodes having a populated
text
value, some having achildren
property, and some having both, while text vnodes ironically end up overloadingchildren
to represent their atomic text value.This ambiguity manifests as convoluted logic in hyperscript.js & render.js and makes it unnecessarily difficult to parse vdom procedurally; as attested in #1838 it adds to the difficulty of producing robust infrastructure for SSR hydration — my current prototype is stymied by the difficulty of producing a virtual node tree walker that can reconcile with natively parsed HTML.
Considerations
The only practical import of the forked logic is to special case hyperscript expressions of DOM elements containing 1 single text child expression of 1 or more characters in length, so that the renderer skips children iteration and applies text immediately as
textContent
assignment. I contend whatever marginal performance benefit this may afford doesn’t warrant the logical complexity of applying it, let alone the headache of procedurally interpreting virtual tree structures as a consequence — which is a blocker to robust integration tooling.@StephanHoyer says these distinctions are immaterial to Mithril Query & Mithril Node Render, which makes me confident any change in this area wouldn’t have any adverse effect on existing tooling.
Proposal
As a first step, remove special casing for element vnodes containing 1 non-0-length text node, such that all text is represented as text vnodes.
Then, decide to either: remove the
text
field from the vnode interface completely; or use it exclusively to represent thenodeValue
of text nodes, thus ensuring the vnodechildren
field is always nullish or an array, and used exclusively to represent child nodes of the vnode.The text was updated successfully, but these errors were encountered: