Closed chenzx closed 2 years ago
Native elements in JSX cannot begin in upper-case letters, or else the compiler would think it is a component (or it refers to a function). Maybe try text-view
instead of TextView
?
Another thing, the error refers to this line: return globalThis.TextView.create({});
. You are missing new
in my js native ui lib, TextView is a view class name, i just want to map it directly, how can i mitigate this JSX limit? TextView.create
is a class static factory method and it's in createElement(elementName) callback, so i thought should be able to...
Use text-view trick is ok, but since my js native view class name is TextView
style, it seems not very natural...
I wouldn't recommend bypassing the JSX spec (the entire thing is canonical) as well as the entire Pascal-case/lower-case difference is hard-coded, neither there's a way to bypass it, which is why we recommend having the built-in components be in lower-case. React does the same thing as well. But if your intent is in pascal-case then maybe you can export a function component that renders the lower-case element:
function TextView(props) {
return <text-view {...props} />
}
In my js native
ui framework(conceptually like React-Native, but it's targeted on embedded devices, not on desktop env), there is 2 kinds of view components: one is called View
, which is the basic building blocks and cannot be atomically decomposed, to name a little: ScrollView、CompositeView、ImageView、TextView、……;The other is called Widget
which is built upon Views.
I'm just using JSX for a intermediate stage, i. thought JSX is for Web env, not for native render env(which is exactly solid-js/universal built for).
Our team is developing a UI design/editor for the js native ui framework, the UI design result is a json description which combines View tree hierarchies、render/layout properties、data binding(especially the reactive system)、layout,I'm hoping to employ solidjs to build a code genrate module from the UI json desc, to let the UI design/edit result directly run in target embed env...
I'm somewhat familiar with Solidjs's createSignal api... (the reactive engine), but i'm not familiar with the AOT codegen mechanism from JSX(or h...
) to JS functions code, there is not much documentation. Its secrets seems to be in the babel-preset-solid
plugin with dependencies on dom-expressions
It sounds like you don't want to use document.createElement
at all, so should be avoiding <foo>
where foo
is lower case. Then you should probably be defining components, maybe like this:
function TextView(props) {
const textView = globalThis.TextView.create({}); // maybe needs a 'new'?
createEffect(() => {
// Reactively propagate props to TextView interface
textView.setText(props.text); // I'm guessing the interface here
});
return textView;
}
// usage
<TextView text={`${count()}`} />
But we're guessing without an actual link to the js-native framework you're using.
The js native
ui framework is not open sourced... but it's not the point here.
Basically, The js native
ui framework consists of 2 parts: the JS scripting layer, which defines the whole View classes; & the C++ render engine part, depends on OpenGL ES 2.0, skia, freetype, harfbuzz, and so on, which is compiled into a nodejs addon. The later is now also compiled into wasm with embind js bindings, so now it can be run in browser with a 3d
@edemaine I'm somewhat confused: Is the name TextView
in TextView(props)
not conflicted with that in globalThis.TextView
? I guess it's the only way to avoid use <text-view>
in JSX (it's not intuitional,IMO)
Is the name TextView in TextView(props) not conflicted with that in globalThis.TextView?
it doesn't.
Yeah basically there are a couple ways to attack this but the capitalizing in JSX is something all tools (including TypeScript and syntax highlighting) respect. So in generally fighting that isn't worth it. This leaves you with 2 high level choices, universal renderer to treat these as native elements or wrapping them as components without using universal renderer. Both approaches actually work. The difference is with components you will manage the reactivity yourself, need to define each component, and on the usage they's need to be available in scope. Whereas the custom renderer leaves Solid to do the reactivity and you just implement the functions, and assumed as native it does not need to be in scope. But then they need to be lowercase.
I've figured out what to do. Seems i could fork babel-plugin-jsx-dom-expressions
module & let universal dom model can use TextView
model without implementing function component, but this is low-priority work to do. Naming
should be convenient, flexible to allow customization IMO.
now, i need find out how to build a Babel plugin to reduce my json ui view tree desc format to JSX AST form, then pass it to babel-plugin-jsx-dom-expressions...
Yeah I mean it isn't really up to us unless we want to opt into breaking every existing tool for JSX. They expect the convention. I opened an issue with TypeScript for this specific issue oh over 3 years ago and it hasn't budged. Not even a tiny bit: https://github.com/microsoft/TypeScript/issues/31606
Describe the bug
I'm try to build a minimal demo to bridge solid-js/universal to a js native UI framework(my native UI framework is named Caf, and can run in Node.js CLI and Web/wasm env), Follow example from https://codesandbox.io/s/custom-dom-renderer-yu2pj?file=/renderer.js , upon which i made a little modification:
Then app is a simple demo:
However, when try to load test in chrome, DevTools reported error:
solid.js:1157 is:
Here, i found
Comp
is exactly globalThis.TextView which i exported from my js native ui lib, but i meant to useglobalThis.TextView.create
in solid-js/universal createElement callback!Your Example Website or App
--
Steps to Reproduce the Bug or Issue
Info as described above.
Expected behavior
I expect to use solid-js/universal to adapt it to my js native ui framework lib, but failed.
Screenshots or Videos
No response
Platform
Additional context
No response