facebook / react-strict-dom

React Strict DOM (RSD) standardizes the development of styled React components for web and native.
https://facebook.github.io/react-strict-dom
MIT License
3.18k stars 161 forks source link

Update Expo SDK in example #236

Open necolas opened 1 week ago

necolas commented 1 week ago

Update the Expo SDK

We use Expo to power the example / visual regression testing app. Keeping this up-to-date is important for the following reasons:

  1. We validate the experience of using RSD with the latest OSS RN releases.
  2. We do most RSD development in this repo, using OSS RN first.
  3. We want RSD to be easy to adopt when using Expo - the recommended OSS RN framework, and a React framework that is explicitly aligned with the goals of RSD.

The current challenges

  1. We are missing developer docs for process of upgrading Expo in the RSD repo. Make it easy for anyone to improve and follow the Expo upgrade process in the RSD repo.
  2. We don't have a working style extraction plugin for Metro on web. Make it so that Expo-based RSD apps can deliver static CSS files.

Action items

cc @ecreeth @javascripter

javascripter commented 6 days ago

I'm happy to help advance Expo CSS extraction sitaution! Regarding the approach used by my plugin, here's the quick summary and the thinking behind the plugin:

Overview:

Watch Mode:

  1. Dependency Tracking: Watches entire directories that may contain files needing transformation, not just those matching the glob pattern. This broader watching ensures reliable detection of added or deleted files during development (PostCSS CLI can't reliably detect new files added in watch mode)
    • Expo Web uses its own dependency tracking (uses source code dependencies I think) so it doesn't use PostCSS file dependencies, but Step 2 and below apply the same)
    • For a glob pattern ./src/*/.{ts,tsx}, the PostCSS plugin watches the entire ./src directory to trigger Step 2
  2. Re-globbing: Upon detecting changes, the plugin re-globs all files matching the pattern.
  3. File change detection: Compares Last-Modified timestamps to identify new or changed files since the last run and re-runs Babel for those files.
  4. Recompilation: Re-compiles the collected styles and updates the CSS placeholder with the new styles.
  5. Re-subscribing: Continues watching the same dependencies for subsequent changes.

Design Considerations:

necolas commented 6 days ago

Thanks, that explanation is very helpful. It looks like a pretty good approach. I'm happy to use it in the example app. Does postcss automatically get run during the Expo and Next build process?

javascripter commented 6 days ago

Thanks, that explanation is very helpful. It looks like a pretty good approach. I'm happy to use it in the example app. Does postcss automatically get run during the Expo and Next build process?

Yes, both Expo and Next.js run PostCSS automatically, so the generated CSS will be bundled automatically on builds/dev.

It isn't relevant to Expo Web usage but Next.js has a known next/babel compatibility issue with App Dir so my plugin usage with Next.js is more experimental.

I'll look into configuring the example app to use my plugin and send a PR!

necolas commented 6 days ago

One thing I noticed is that it would be good if the plugin internally included the RSD package in its "include" paths array so users don't have to point to internals

necolas commented 5 days ago

Thank you very much @ecreeth @javascripter for the quick help and excellent work! I'll work on the last piece, the extra docs, and let you know when that's ready for review

necolas commented 5 days ago

One more thing I'd like to do is make the Expo example a proper Expo app, e.g., using whatever universal routing system they ship these days. We could even have a create-react-strict-dom package that can be used to set up a working RSD/Expo project using npm create