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: do not convert boolean to string #190

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

damiennl
Copy link

Hello 👋,

I've just removed the boolean convert to string in order to write some JSX code like this:

<>
  {flash.has('error'} && <span>{flash.get('error')}</span>}
</>

Because it could shows false which is not expected

It is by the way a regression because it was the behavior in v3.1.2

Thx 🙏

Copy link

changeset-bot bot commented Apr 17, 2024

🦋 Changeset detected

Latest commit: 781c73c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kitajs/html Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@arthurfiorette
Copy link
Member

arthurfiorette commented Apr 17, 2024

Hey @damiennl this was a regression of v3 because in v4 it now follows the exactly same behavior as React.

You implementation also ignores true which leads to other unexpected behaviors too

@arthurfiorette arthurfiorette self-assigned this Apr 17, 2024
@arthurfiorette
Copy link
Member

@JacopoPatroclo what's you thoughts on this?

@JacopoPatroclo
Copy link

@arthurfiorette The changes are sane. I agree with @damiennl that if you want to write something like this it's important that the boolean values are not rendered as strings. It makes the library more similar to React (and other jsx renderers) and I think it's a good thing.

I will also advise @damiennl to make sure to never put untrusted strings inside flash messages and/or escape them (using the primitive that this library gives you).

Thanks for the contribution @damiennl !

@arthurfiorette
Copy link
Member

arthurfiorette commented Apr 18, 2024

It was indeed a regression/breaking change, that's why we are at 4.0.0 now.

The only requirement is to follow what React does because React is a "baseline" for every JSX runtime. Does this regression follows react? If it doesn't then it's a bug and I'll merge this pr.

Can someone create a test / reproducible example so that we can test it out?

Kita/Html doesn't have to actually follow react, but I assume most of the devs who will try Kita/Html comes from a background with React and having different behaviors from React for simple thins such as how we transform values to html strings will be a bad thing long term.

I'm also open to new suggestions @JacopoPatroclo & @damiennl

@arthurfiorette arthurfiorette added help wanted Extra attention is needed question Further information is requested html-runtime Related to @kitajs/html labels Apr 18, 2024
@tqhoughton
Copy link

Is there any update on this? This behavior makes it annoying to do conditional rendering in templates since all of your condition && <Component /> conditions have to be condition ? <Component /> : null instead.

@arthurfiorette
Copy link
Member

Sadly, I do not have enough time to implement this right now.

In case someone wants to help me out, these are the functions doing the "fauly" work:

function contentsToString(contents, escape) {

function contentToString(content, safe) {

Copy link

codecov bot commented Jun 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.56%. Comparing base (5f68ce5) to head (781c73c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #190   +/-   ##
=======================================
  Coverage   99.56%   99.56%           
=======================================
  Files           5        5           
  Lines         456      456           
=======================================
  Hits          454      454           
  Misses          2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tqhoughton
Copy link

I may have some time to address this sometime this week, seems like at initial glance the issue is this line in each function:

case 'boolean':

where boolean variables are getting automatically converted to strings without regard for the false case.

@damiennl
Copy link
Author

damiennl commented Jun 3, 2024

Hey guys 👋
This is a MR, I already do the changes, please check it
I fixed the two functions and updated the unit tests

@arthurfiorette
Copy link
Member

Can someone create a test / reproducible example so that we can test it out?

#190 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed html-runtime Related to @kitajs/html question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants