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

fix(jsx): props are set as properties #999

Draft
wants to merge 1 commit into
base: v3
Choose a base branch
from

Conversation

kasperskei
Copy link
Contributor

Copy link

stackblitz bot commented Jan 6, 2025

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

vercel bot commented Jan 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
reatom ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 14, 2025 10:11am

Copy link
Owner

@artalar artalar left a comment

Choose a reason for hiding this comment

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

LGFM, there only need to do the types changes

let name = ''

DOM.document.head.appendChild(stylesheet)
Copy link
Owner

Choose a reason for hiding this comment

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

If a user will not using css prop there will unnecessary style element in their DOM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this change because dynamically adding a style tag can introduce style order. When changing the order, random bugs with styles can occur.

Copy link
Owner

Choose a reason for hiding this comment

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

Agree. Please, add an option to the fabric to get an ability to disable the element insertion.

Copy link
Contributor Author

@kasperskei kasperskei Jan 13, 2025

Choose a reason for hiding this comment

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

Replaced Record with Map, because Map is more productive when dynamically adding and reading.

@@ -445,38 +439,6 @@ it('css custom property', setup(async (ctx, h, hf, mount, parent) => {
assert.is(component.style.getPropertyValue('--secondProperty'), '')
}))

it('class and className attribute', setup(async (ctx, h, hf, mount, parent) => {
Copy link
Owner

Choose a reason for hiding this comment

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

We need to stay a special case for class and className, it should work without prefixes in both ways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest keeping only className:

  • Supporting only one way to assign classes makes the library's API simpler. If two options (class and className) are available, it can cause confusion and increase the likelihood of errors, such as attempting to use both properties simultaneously.
  • Simplification of internal logic. It eliminates the need to decide which property takes precedence in case of a conflict.
  • Most developers working with JSX are already accustomed to using className. Adding support for class may introduce unnecessary inconsistencies and complicate transitions between projects.
  • Including class increases mental overhead by introducing an exception. It is much easier to understand that a property in JSX corresponds directly to an element's property.

Copy link
Owner

@artalar artalar Jan 13, 2025

Choose a reason for hiding this comment

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

There are a valid points, but it are all controversial.

  • there is no big API overhead for only this special case
  • many developers which didn't know JSX specific may be confused, there are a lot of templates engines (including Preact!) which support "class"
  • I think most part of developers doesn't know \ understand \ remember a difference between attributes and properties.

And also, the change that you want to do it a breaking change and a new major release - it's not worth it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at the preact source code, came across the exception handling and moved it to reatom/jsx
https://github.com/preactjs/preact/blob/main/src/diff/children.js#L101

packages/jsx/src/index.ts Outdated Show resolved Hide resolved
packages/jsx/src/index.ts Outdated Show resolved Hide resolved
packages/jsx/src/index.ts Outdated Show resolved Hide resolved
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.

2 participants