Open shirakaba opened 2 years ago
I've looked into this for a few hours. As far as I can tell, the DOM algorithm is absolutely correct (I printed out the equivalent HTML for it and it's perfect). Surprisingly, it really is user components that layout is messing up for, as can be seen if you flatten out all your user components into App.svelte.
The only clue I can find as to why user components may be breaking is that they're getting interpreted as SVG by the Svelte compiler. Our preprocessor should specifically prevent this (it sets the namespace for all .svelte files as "foreign"), so I'm really not sure why it's happening.
I've tried updating svelte and svelte-loader to use their new built-in support for foreign namespaces, but now for some reason the GUI is failing to appear after adding the final child component in the hierarchy.
Above all, I have no explanation whatsoever as to why my PR since the last working version could lead to this behaviour. I'm really out of ideas.
How does svelte-nodegui differs from nodegui? What does the svelte-
part do under the hood?
AFAIU, nodegui only offers a Javascript API, so any UI design system on top of it (svelte-
, react-
, vue-
and possibly the support for Qt Designer) will have to generate the corresponding Javascript code under the hood, right?
If this is right, svelte-
part of svelte-nodegui
to SvelteJS is C compiler for x86_64 to C compiler for Arm. One transpiles Svelte code to Javascript code that alters the DOM directly by using use HTML DOM API and the other (this one) transpiles the Svelte code to Javascript code that alters the GUI by using nodegui's API. If this is also right, Svelte transpiler part of SvelteJS and svelte-nodegui have very distinct codebase. If this is also right, then we may take advantage of existing SvelteJS transpiler by implementing a HTML DOM API to NodeGUI API transpiler. How does that sound?
How does svelte-nodegui differs from nodegui? What does the svelte- part do under the hood?
@ceremcem NodeGUI consists of:
So NodeGUI alone does not implement DOM.
React NodeGUI implements all the parts of DOM required for React support, but Svelte β given that it has no dedicated API for custom renderers β requires a few parts of DOM, and a few parts of HTML (like window
, document
, head
, and some bits relating to styling and events). So there are some gaps to fill.
Svelte NodeGUI takes this approach:
It's a chimaera of Svelte Native and NativeScript Vue. I'll admit that the way that it implements is somewhat messy as the code layout could certainly be cleaner.
If this is also right, then we may take advantage of existing SvelteJS transpiler by implementing a HTML DOM API to NodeGUI API transpiler. How does that sound?
So we're basically doing that already, although coupling it to Svelte. Ideally we'd get together and create a dom-nodegui
library that all the renderers can use. But that's a large project to coordinate on and, for my part, my time for open source activities is very limited!
However, this is off-topic. We have a DOM implementation already. Even if we did create a dom-nodegui
library (e.g. by pulling out the DOM implementation from Svelte NodeGUI into a separate project), we'd still face the problem that Svelte is for some reason failing to lay out user components correctly. This is unfortunately a Svelte internals problem that few people will be able to answer.
The path of least resistance at this point might be to go back to the DOM implementation in v0.0.3-alpha.1
... but then I really worry about how to get {#each}
and {#if}
blocks to work (which is obviously something we can't leave broken) without literally rewriting the same PR I wrote that ended up breaking user components :/
Root cause issue for:
65
68
70
After a lot of red herrings involving Node version, environment,
nodegui
version,qode
version, shell, custom elements, etc., I think I finally understand what's going on.v0.0.3-alpha.1
was the last release in which the starter template's layout was seen to be correct. However, in that release,{#each}
and{#if}
blocks didn't work correctly. So I merged the PR #60 inv0.0.4
, changing how child elements were inserted, which seemed to fix that problem in all cases. Unfortunately, this PR brought an unnoticed regression in more complex UIs like that of the starter template.So this is problematic. We don't want to roll back to the DOM algorithm used in
v0.0.3-alpha.1
because it has a subtle problem that stops{#each}
and{#if}
blocks working. We also can't stick with the approach used sincev0.0.4
(still used in the version at the time of writing,v0.1.2
), because it has obvious layout issues.Fixing
{#each}
and{#if}
behaviour was a horribly subtle problem to solve, so I think the way forward is to stick with this current DOM model (rather than rolling back to the old DOM model) and try to fix this obvious layout problem.