Skip to content

transform-react-constant-elements: using mutable variable doesn't lead to deoptimization #10522

@Hypnosphi

Description

@Hypnosphi

Bug Report

Current Behavior
When a React component uses a let variable, hoisting of the returned React Element leads to incorrect behavior

Input Code

let foo = 'hello';

export const Component = () => {
  foo = 'goodbye';
  return <span>{foo}</span>;
};

Expected output

let foo = 'hello';

export const Component = () => {
  foo = 'goodbye';
  return React.createElement("span", null, foo);
};

Actual output

let foo = 'hello';

var _ref =
/*#__PURE__*/
React.createElement("span", null, foo);

export const Component = () => {
  foo = 'goodbye';
  // renders "hello" instead of "goodbye"
  return _ref;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: jsxoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions