stylex icon indicating copy to clipboard operation
stylex copied to clipboard

Docs: Add proper playground

Open nmn opened this issue 2 years ago • 11 comments

https://stylex-docusaurus-nxsbvzf80-nmn.vercel.app

For now, this is a proof of concept. I have used a webcontainer to successfully compile and show the output of a file.

The next step is to make improvements until there is a minimal viable experience.

nmn avatar Nov 29 '23 12:11 nmn

compressed-size: runtime library

Size change: 0.00 kB Total size: 2.36 kB

View unchanged
Filename: gzip (minify) kB size kB change % change
./packages/stylex/lib/stylex.js 1.02 (3.53) 0.00 (0.00) 0.0% (0.0%)
./packages/stylex/lib/StyleXSheet.js 1.34 (3.41) 0.00 (0.00) 0.0% (0.0%)

github-actions[bot] avatar Nov 29 '23 12:11 github-actions[bot]

compressed-size: e2e bundles

Size change: 0.00 kB Total size: 1119.56 kB

View unchanged
Filename: gzip (minify) kB size kB change % change
./apps/rollup-example/.build/bundle.js 1005.35 (9859.61) 0.00 (0.00) 0.0% (0.0%)
./apps/rollup-example/.build/stylex.css 114.22 (456.05) 0.00 (0.00) 0.0% (0.0%)

github-actions[bot] avatar Nov 29 '23 12:11 github-actions[bot]

Nice! This direction is definitely better IMO.

Seeing all this JS to null out properties is kinda 😬 Still think the RN way is objectively better, esp for perf.

image

Maybe we should also remove the inject calls from the playground output, because it might confuse people after the docs talk about "no runtime style injection"

necolas avatar Nov 29 '23 18:11 necolas

Yup. Need to tweak some settings to remove the inject calls and add a settings screen to tweak the resolution mode.

nmn avatar Nov 29 '23 22:11 nmn

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
stylex ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 29, 2023 11:03pm

vercel[bot] avatar Nov 29 '23 22:11 vercel[bot]

Much better output: https://stylex-6piprzpqr-fbopensource.vercel.app/playground/

nmn avatar Nov 29 '23 23:11 nmn

This output is interesting. We often focus on gzip/br size over the wire, but once unpacked by the browser the minified size matters, and patterns like this minify worse than patterns that don't duplicate the common strings. Not to mention we're creating more objects here too

  const props = {
    0: {
      className: "xjyslct xng3xce x1t391ir x1awj2ng x12oqio5 x12ulsxz xdqyycr"
    },
    1: {
      className: "xjyslct xng3xce x1t391ir x1awj2ng x12oqio5 x12ulsxz xdqyycr x4zgh4k"
    }
  }[!!em << 0];

necolas avatar Nov 29 '23 23:11 necolas

How do we test this locally? I get this error that prevents the output showing

image

necolas avatar Nov 29 '23 23:11 necolas

How do we test this locally? I get this error that prevents the output showing

I finally figured this out. As long as you npm run build && npm run serve, it is not testable locally.

nmn avatar Dec 05 '23 19:12 nmn

once unpacked by the browser the minified size matters

We can pack this into smaller string expressions, but it's hard to do that while maintaining className order. We used to do that in the past.

nmn avatar Dec 06 '23 11:12 nmn

Seeing all this JS to null out properties is kinda 😬

Here are the plans to improve this situation:

  1. More fine-grained pre-computation. Currently the entire styles constant is removed or none of it. We can remove just the rules within that can be pre-compiled.
  2. We can detect objects that are used within the same file and figure out which null values can be removed. e.g. any object that is always used as the first argument to stylex.props doesn't need any null values.
  3. We can detect which properties are never used in the entire project and remove the null values for those properties globally.

nmn avatar Dec 06 '23 12:12 nmn