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

Transpiler error when Boolean value is assigned to class prop during SSR #392

Closed
axel-habermaier opened this issue Jan 10, 2025 · 1 comment

Comments

@axel-habermaier
Copy link

axel-habermaier commented Jan 10, 2025

Consider the following code:

function Crash() {
  return (
    <div class={true} />
  );
}

This causes a transpiler error in SSR-mode:

438 | function trimWhitespace(text) {
439 |   text = text.replace(/\r/g, "");
                    ^
TypeError: /home/axel/hytts/src/jsx/jsx.test.tsx: text.replace is not a function. (In 'text.replace(/\r/g, "")', 'text.replace' is undefined)
 code: "BABEL_TRANSFORM_ERROR",

      at trimWhitespace (/home/axel/hytts/node_modules/babel-plugin-jsx-dom-expressions/index.js:439:15)
      at <anonymous> (/home/axel/hytts/node_modules/babel-plugin-jsx-dom-expressions/index.js:2598:16)
      at forEach (1:11)
      at transformAttributes$1 (/home/axel/hytts/node_modules/babel-plugin-jsx-dom-expressions/index.js:2484:14)
      at transformElement$2 (/home/axel/hytts/node_modules/babel-plugin-jsx-dom-expressions/index.js:2287:3)
      at transformJSX (/home/axel/hytts/node_modules/babel-plugin-jsx-dom-expressions/index.js:3570:18)
      ...

Obviously, the code is somewhat questionable and doesn't really make sense. Nevertheless, such a transpiler error is unexpected.

The code above should either compile to <div class="true" /> or a sensible error message should be raised.

@axel-habermaier axel-habermaier changed the title Transpiler crashes when Boolean value is assigned to class prop Transpiler error when Boolean value is assigned to class prop Jan 10, 2025
@axel-habermaier axel-habermaier changed the title Transpiler error when Boolean value is assigned to class prop Transpiler error when Boolean value is assigned to class prop during SSR Jan 10, 2025
@titoBouzout
Copy link
Contributor

I cannot reproduce the error, so I will leave it like that for now till other PRs get merged as theres some handling of true and false. BTW, what should be doing is adding an empty attribute, as <div class/> instead of <div class="true"/>, if you want true to be the value of the attribute you should be using a string.

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

No branches or pull requests

2 participants