Skip to content
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

vanjs-jsx fixes #329

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

damienflament
Copy link

Fixes #325, #328 and other issues.

When the *children* and *ref* properties don't exist in the properties object, destructuring initialize those variables to *undefined*.

If the given *jsxTag* is a function (a component declared by the user), passing those properties make the resulting HTML element have those attributes rendered but with no value.
@Tao-VanJS
Copy link
Member

@cqh963852, FYI

@thednp
Copy link

thednp commented May 20, 2024

@damienflament does this fix also help with the Fragment error?

@damienflament
Copy link
Author

damienflament commented May 20, 2024

@thednp No. I just started using Vite and JSX on my VanJS app. But I have some place where I put elements on a <div> to allow my component to return an array. I recently discovered in the React documentation about JSX that Fragments are made for that.

I read your ticket #324 about the missing Fragment implementation. I will take a look later.

@thednp
Copy link

thednp commented May 22, 2024

@damienflament question: will the jsx runtime support custom VanJS components?

EG: function MyComp() { return div({}, 'some text')} with <MyComp /> syntax?

@damienflament
Copy link
Author

@thednp Actually, that's how I use it.

MyComp() {
  return <div>Some text</>
}
<MyComp />
// transformed by the parser to:
jsx(MyComp)

In vanjs-jsx, jsx() is aliased to createElement().

Because MyComp is your custom function, it is called with properties as parameters.

But this function is also transformed by the parser:

MyComp() {
  return jsx("div", {children: "Some text"})
}

Now, createElement() is called with a tag name. The tag is created using van.tags as usual.

@thednp
Copy link

thednp commented May 22, 2024

Thank you @damienflament for the explanation, how's the fix coming in? When can we test?

@@ -0,0 +1 @@
export * from "./index";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be fixed by adjusting the configuration of package.json.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this file may cause the vscode editor's smart import to carry a special path.

For example

import {} from "van_jsx/jsx_runtime";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[vanjs-jsx] Add missing ./src/jsx-runtime.js
4 participants