Skip to content

React: Render boolean props set to false in source snippets#34968

Merged
Sidnioulz merged 1 commit into
nextfrom
valentin/patch-react-element-to-jsx-string-false-props
May 29, 2026
Merged

React: Render boolean props set to false in source snippets#34968
Sidnioulz merged 1 commit into
nextfrom
valentin/patch-react-element-to-jsx-string-false-props

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented May 29, 2026

Closes #27127

What I did

Patched react-element-to-jsx-string (the @7rulnik fork we consume) with algolia/react-element-to-jsx-string#733.

That PR removes the branch in formatProp that silently omitted boolean props explicitly set to false when useBooleanShorthandSyntax is enabled (the default). As a result, React auto-generated source snippets dropped false props entirely — e.g. <Component disabled={false} /> rendered as <Component />.

After this patch:

  • A prop set to false renders as disabled={false}.
  • A prop set to true keeps the shorthand syntax (disabled), as before.

This is one of the long-standing source-snippet bugs tracked in #33628.

Implementation notes

  • The fork ships pre-bundled (dist/esm/index.js + dist/cjs/index.js) with no separate src/formatProp.js, so the Yarn patch applies the equivalent change to both bundles.
  • Wired via the dependency locator in code/renderers/react/package.json (mirroring the existing react-aria-components patch), since yarn patch-commit doesn't auto-rewire npm-aliased dependencies.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Added a regression test in jsxDecorator.test.tsx (should render boolean props set to false) that locks the new output. The full @storybook/react renderer suite (617 passed / 8 skipped) was re-run to confirm no existing source snapshot relied on the old false-omission behavior.

Manual testing

  1. Run a sandbox: yarn task --task sandbox --start-from auto --template react-vite/default-ts
  2. Open Storybook in your browser.
  3. Add (or open) a story for a component that receives a boolean prop set to false, e.g. args: { disabled: false }.
  4. Open the Docs tab / Show code for that story.
  5. Confirm the generated snippet now shows disabled={false} instead of omitting the prop. A prop set to true should still render as the shorthand disabled.

Note

This intentionally changes source-snippet output for any React story that passes an explicit false boolean prop, so docs/Chromatic snapshots for those stories will shift — that's the desired fix, not a regression.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update MIGRATION.MD

No documentation changes needed — this restores expected behavior for an existing feature.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Added regression test for boolean prop rendering in JSX decorator to ensure props explicitly set to false render correctly.
  • Chores

    • Updated dependency specification format.

Review Change Stack

Patches react-element-to-jsx-string (the @7rulnik fork) with
algolia/react-element-to-jsx-string#733, which removes the branch that
silently omitted boolean props explicitly set to `false`. React source
snippets now render `foo={false}` instead of dropping the prop, while
`true` props keep the shorthand syntax.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@valentinpalkovic valentinpalkovic moved this to Empathy Queue (prioritized) in Core Team Projects May 29, 2026
@valentinpalkovic valentinpalkovic moved this from Empathy Queue (prioritized) to In Progress in Core Team Projects May 29, 2026
@valentinpalkovic valentinpalkovic self-assigned this May 29, 2026
@valentinpalkovic valentinpalkovic changed the title fix(react): render boolean props set to false in source snippets React: Render boolean props set to false in source snippets May 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ed4f1948-0e66-4c34-9a21-fdf9c746eeb7

📥 Commits

Reviewing files that changed from the base of the PR and between 011d773 and 1295f93.

⛔ Files ignored due to path filters (2)
  • .yarn/patches/@7rulnik-react-element-to-jsx-string-npm-15.0.1-e53b67c4b3.patch is excluded by !**/.yarn/**
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • code/renderers/react/package.json
  • code/renderers/react/src/docs/jsxDecorator.test.tsx

📝 Walkthrough

Walkthrough

This PR patches the react-element-to-jsx-string dependency to fix boolean prop rendering in the React JSX decorator and validates the fix with a regression test confirming that false-valued boolean props render explicitly while true-valued props retain shorthand notation.

Changes

React JSX Boolean Props Handling

Layer / File(s) Summary
Patch react-element-to-jsx-string dependency
code/renderers/react/package.json
Updated devDependency from npm workspace spec to Yarn patch reference, applying a local patch to @7rulnik/react-element-to-jsx-string@15.0.1 to fix boolean prop rendering behavior.
Regression test for boolean prop rendering
code/renderers/react/src/docs/jsxDecorator.test.tsx
Added test case verifying renderJsx renders false-valued boolean props explicitly (hidden={false}) while keeping true-valued props in shorthand form (draggable).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@Sidnioulz Sidnioulz left a comment

Choose a reason for hiding this comment

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

Confirmed fixed.

@Sidnioulz Sidnioulz merged commit f12f3ab into next May 29, 2026
148 of 152 checks passed
@Sidnioulz Sidnioulz deleted the valentin/patch-react-element-to-jsx-string-false-props branch May 29, 2026 09:07
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Core Team Projects May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: @storybook/blocks > <Canvas> > 'Show code' doesn't display props that have false

2 participants