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

React Native Web: Add framework, CLI integration, sandboxes #29520

Merged
merged 25 commits into from
Nov 18, 2024

Conversation

shilman
Copy link
Member

@shilman shilman commented Nov 3, 2024

Closes #

What I did

Barebones Vite-based React Native Web framework, @storybook/react-native-web-vite, based on https://github.com/storybookjs/addon-react-native-web/

  • New framework
  • Basic CLI integration with storybook init --type react_native_web
  • Sandboxes for RN CLI and Expo
  • CLI templates for example RN Button/Header/Page components/stories
  • Figure out JSX settings
  • Docgen / auto-generated controls
  • Remove CLI-generated .css files
  • Test sandboxes daily
  • Documentation

Follow-up work

  • Improved CLI integration that prompts user
  • Debug RN-CLI sandbox
  • Set up react-native-web renderer docs
  • Debug storybook add @storybook/experimental-addon-test (if needed)

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

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

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

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-29520-sha-c92aa93a. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-29520-sha-c92aa93a
Triggered by @shilman
Repository storybookjs/storybook
Branch shilman/react-native-web-vite
Commit c92aa93a
Datetime Sat Nov 16 14:54:44 UTC 2024 (1731768884)
Workflow run 11871015323

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=29520

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 78.5 MB 78.5 MB 0 B 1.36 0%
initSize 144 MB 144 MB 791 B 1.37 0%
diffSize 65.2 MB 65.2 MB 791 B 1.58 0%
buildSize 6.87 MB 6.87 MB 0 B -1.36 0%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B - 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.9 MB 1.9 MB 0 B 1.18 0%
buildSbPreviewSize 271 kB 271 kB 0 B - 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.88 MB 3.88 MB 0 B 1.18 0%
buildPreviewSize 2.99 MB 2.99 MB 0 B -1.36 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 7.4s 23.8s 16.3s 1.29 🔺68.5%
generateTime 22.5s 20.1s -2s -410ms -0.45 -12%
initTime 14.8s 15.7s 946ms 0.45 6%
buildTime 9s 8s -952ms -0.8 -11.8%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6.3s 5.1s -1s -211ms -0.84 -23.4%
devManagerResponsive 4s 3.2s -827ms -0.83 -25.7%
devManagerHeaderVisible 601ms 506ms -95ms -0.8 -18.8%
devManagerIndexVisible 637ms 538ms -99ms -1.09 -18.4%
devStoryVisibleUncached 927ms 1s 139ms 0.36 13%
devStoryVisible 631ms 536ms -95ms -1.13 -17.7%
devAutodocsVisible 606ms 516ms -90ms 0.11 -17.4%
devMDXVisible 633ms 439ms -194ms -1.06 -44.2%
buildManagerHeaderVisible 610ms 501ms -109ms -0.91 -21.8%
buildManagerIndexVisible 624ms 523ms -101ms -0.84 -19.3%
buildStoryVisible 607ms 491ms -116ms -1.02 -23.6%
buildAutodocsVisible 510ms 428ms -82ms -0.94 -19.2%
buildMDXVisible 501ms 440ms -61ms -0.13 -13.9%

Greptile Summary

Added React Native Web Vite framework to Storybook with CLI integration, sandboxes, and test coverage, focusing on proper Vite configuration and React Native Web component support.

  • Added @storybook/react-native-web-vite framework with Vite-specific configuration in code/frameworks/react-native-web-vite/src/preset.ts
  • Added CLI templates with TypeScript/JavaScript examples in code/frameworks/react-native-web-vite/template/cli/
  • Updated framework detection to handle React Native Web projects in code/core/src/cli/detect.ts and code/core/src/cli/project_types.ts
  • Added test skips for React Native Web specific behaviors in e2e tests (onPress vs onClick, CSS differences)
  • Added sandbox templates for Expo and RN CLI in code/lib/cli-storybook/src/sandbox-templates.ts

Copy link

nx-cloud bot commented Nov 3, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 38c6859. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@shilman shilman force-pushed the shilman/react-native-web-vite branch from 539cc58 to ff61894 Compare November 4, 2024 01:17
@shilman shilman force-pushed the shilman/react-native-web-vite branch from ff61894 to 6f9594f Compare November 4, 2024 05:54
@shilman shilman changed the title React Native: RNW-Vite framework, sandboxes, and CLI integration React Native: RNW-Vite framework, CLI integration Nov 9, 2024
@shilman shilman changed the title React Native: RNW-Vite framework, CLI integration React Native Web: Add framework, CLI integration, sandboxes Nov 10, 2024
@shilman shilman force-pushed the shilman/react-native-web-vite branch from 627893b to ea86393 Compare November 10, 2024 14:19
@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Nov 10, 2024

Package Benchmarks

Commit: 38c6859, ran on 18 November 2024 at 10:29:39 UTC

The following packages have significant changes to their size or dependencies:

@storybook/react-native-web-vite

Before After Difference
Dependency count 0 109 🚨 +109 🚨
Self size 0 B 37 KB 🚨 +37 KB 🚨
Dependency size 0 B 18.69 MB 🚨 +18.69 MB 🚨
Bundle Size Analyzer Link Link

@storybook-bot
Copy link
Contributor

Failed to publish canary version of this pull request, triggered by @shilman. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/11870905006

@shilman shilman added ci:daily Run the CI jobs that normally run in the daily job. and removed ci:normal labels Nov 17, 2024
@shilman shilman force-pushed the shilman/react-native-web-vite branch 3 times, most recently from d787436 to 751085b Compare November 17, 2024 09:46
@shilman shilman force-pushed the shilman/react-native-web-vite branch from 751085b to ee7b69f Compare November 17, 2024 15:10
@shilman shilman marked this pull request as ready for review November 17, 2024 15:49
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

56 file(s) reviewed, 48 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -0,0 +1,3 @@
# Storybook for React Native Web & Vite

See [documentation](https://storybook.js.org/docs/get-started/frameworks/react-native-web-vite?renderer=react-native-web) for installation instructions, usage examples, APIs, and more.
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Documentation URL uses 'react-native-web' as renderer but framework uses 'react' renderer internally. Consider aligning these or documenting the difference.

{
"name": "@storybook/react-native-web-vite",
"version": "8.5.0-alpha.5",
"description": "Develop react-native components an isolated web environment with hot reloading.",
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: typo in description: 'an isolated' should be 'in an isolated'

Comment on lines +5 to +7
"targets": {
"build": {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Build target is empty. Consider adding standard NX build configuration like executor, options, and configurations for proper build integration.

Comment on lines +1 to +2
// @ts-expect-error FIXME
import { viteFinal as reactViteFinal } from '@storybook/react-vite/preset';
Copy link
Contributor

Choose a reason for hiding this comment

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

style: TODO needs to be addressed - ts-expect-error should be removed by properly typing the import

Comment on lines +26 to +27
include: [],
esbuildOptions: {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: empty include array may cause optimization issues - consider adding common dependencies


* ⚛️ React Native components
* 🧑‍💻 Shareable on the web
* 🪄 Zero confg
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Typo in 'confg', should be 'config'


### In a project with Storybook `addon-react-native-web`

The [React Native Web addon](https://github.com/storybookjs/addon-react-native-web), `@storybook/addon-react-native-web` was Webpack-based precursor the React Native Web Vite framework `@storybook/react-native-web-vite`.
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Missing word 'to' after 'precursor'


[Storybook for React Native](https://github.com/storybookjs/react-native) is a framework that runs in a simulator or on your mobile device.

It's possible to run React Native Web alongside React Native, but we are still working on a seamless integration. In the mantime, we recommend running one or the other. If you're not sure what's right for you, read our [comparison](#react-native-vs-react-native-web).
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Typo in 'mantime', should be 'meantime'

**Web.** You should choose Web if you want:

- [**Sharing](https://storybook.js.org/docs/sharing).** Publish to the web and share with your team or publicly.
- [**Documentation](https://storybook.js.org/docs/writing-docs). A**uto-generated component docs or rich markdown docs in MDX.
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Formatting error: 'A**uto-generated' should be 'Auto-generated'


{/* prettier-ignore-start */}

<CodeSnippets path="react-vite-add-framework.md" />
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Incorrect snippet reference 'react-vite-add-framework.md', should likely be 'react-native-web-vite-add-framework.md'

code/frameworks/react-native-web-vite/src/types.ts Outdated Show resolved Hide resolved
code/frameworks/react-native-web-vite/package.json Outdated Show resolved Hide resolved
code/frameworks/react-native-web-vite/package.json Outdated Show resolved Hide resolved
code/frameworks/react-native-web-vite/package.json Outdated Show resolved Hide resolved
code/frameworks/react-native-web-vite/package.json Outdated Show resolved Hide resolved
"vite": "^4.0.0 || ^5.0.0"
},
"engines": {
"node": ">=18.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for the allowed engine. Since this is a new framework, let's not support Node 18 anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm more comfortable making the switch along with all the other frameworks.

*
* @default false
*/
legacyRootApi?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we support legacy api in a new framework?

"@vitejs/plugin-react": "^3.0.1",
"@vitejs/plugin-react": "^4.3.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does @vitejs/plugin-react have to be in code or can we remove it from here?

@shilman shilman merged commit 0e1c9a5 into next Nov 18, 2024
111 of 112 checks passed
@shilman shilman deleted the shilman/react-native-web-vite branch November 18, 2024 12:23
@github-actions github-actions bot mentioned this pull request Nov 18, 2024
7 tasks
@shilman shilman self-assigned this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:daily Run the CI jobs that normally run in the daily job. feature request react-native-web
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants