Comments (4)
It won't convert a single expression to a Document Fragment. I do it to shortcut what I consider the common case. Originally I had the children as arrays but an array of nodes is less efficient as far as my benchmarking shows. I wondered about this precise case but since I had never actually hit it ever using React and the benefits for shortcutting the renderer beneficial I went that way. The main reason is I create nodes by cloning templates. An array would take an otherwise singular template and split it into multiple templates that'd all be cloned separately.
Consider:
<MyComponent>
<div>Hello</div>
<div>World</div>
</MyComponent>
With a change to get the single node effect I would need to write it as:
<MyComponent>{
<>
<div>Hello</div>
<div>World</div>
</>
}</MyComponent>
Whereas for the Data Array you can just currently write:
<MyComponent>{
[1, 2, 3]
}</MyComponent>
I'm not sure there is any case that needs multiple expression children to pass data. It's sort of pure overhead.
It's quite possible the types are incorrect. I am yet to use the JSX types in a project and I made the change to the child operation around the same time the types were contributed. What should be happening is any single expression is left untouched to handle (passing data, render props etc) and anything with multiple children is made into a document fragment. That way children is always a single non-array value (unless you pass an array), that can be either used directly or appended to the DOM without further consideration.
from solid.
👍 the single array argument example solves this use case in my opinion.
The only question is if fixing the types is actually possible. It might be part of the JSX language specs requiring that multiple arguments become an array. Even if it's not possible to fix the type it might be enough to just document it as a small deviation from the JSX specs (with a hint that type casts are required in TS).
from solid.
We do set up our own types so maybe there is something to be done there?
https://github.com/ryansolid/babel-plugin-jsx-dom-expressions/blob/master/types/index.d.ts
Is it that these types only extend to Intrinsic Elements? And not Custom Elements? I guess this is my TypeScript issue of the week. Can't seem to go a week without finding some new fun surprise.
Help would be very much appreciated to know whether there is a TypeScript solution for this.
from solid.
microsoft/TypeScript#30918 is sort of the opposite issue. Looks like TypeScript won't play ball. I've updated documentation. Seems like that is all I can do.
from solid.
Related Issues (20)
- Exports from ./dist do not include corresponding type declarations
- strange hydration mismatch HOT 3
- Typescript - Components created via JSX "forget"/erase their type HOT 3
- Custom elements using `is` not recognized as custom elements HOT 3
- onCleanup is called on the server and it breaks the astro app HOT 1
- [Bug?]: SuspenseList hydration error HOT 2
- computations created outside a `createRoot` or `render` will never be disposed HOT 3
- [Astro] `createResource` results get mixed up when rendering server only components with Suspense HOT 4
- Hydration Mismatch error HOT 6
- [Bug] Repeated call syntax in JSX breaks reactivity HOT 1
- [Astro] resource and signal rendering is mixed up on the client HOT 2
- Refs don't work correctly when using dynamic
- Refs don't work when optional on a component HOT 4
- Cannot use istanbul ignore comments for generated code HOT 2
- setting element reference in `setStore` modifies the values in the array HOT 13
- `this` inside jsx-template inside a constructor of a derived class causes transformation-bug HOT 2
- The update of props is not granular enough. HOT 4
- No value attribute on CSR, but present in SSR
- Cannot properly bind numbers to Select HOT 1
- Double mounting for children element. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solid.