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

feat: allow file editing and updates the preview #762

Closed
wants to merge 33 commits into from

Conversation

6ri4n
Copy link

@6ri4n 6ri4n commented Nov 1, 2024

What changed / motivation ?

WIP Implementing Playground Container

Changed the following web container project structure:

  • Adjusted the build tool to use Vite instead of Rollup
  • Supports hot reloading and JSX syntax
  • Add generateCSS.js script which is make-stylex-sheet.js but with small changes

Changed the following to Playground.js:

  • Allow file editing to app.jsx
  • Preview gets updated

Linked PR/Issues

#732

Additional Context

In Playground.js, if app.jsx changes, the function updateFiles writes the changes to the app.jsx file and then runs the generateCSS.js script which creates stylex.css inside the src directory.

The app.jsx file includes import "./stylex.css"; and if removed then any further changes to the styling won't be applied, it'll use the last stylex.css file that was created.

Screenshots:

Container Running with Vite
stylex-1

Hot Reloading / Applying Changes
stylex-2

Pre-flight checklist

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 1, 2024
@6ri4n 6ri4n marked this pull request as draft November 1, 2024 06:20
@6ri4n
Copy link
Author

6ri4n commented Nov 1, 2024

Hi @nmn, here’s what I have so far. I'd appreciate any feedback or suggestions.

@nmn
Copy link
Contributor

nmn commented Nov 1, 2024

The code makes sense, but it doesn't seem to be working in my testing. See for yourself:

https://stylex-git-fork-6ri4n-dev-better-playground-fbopensource.vercel.app/playground/

Changing the styles just causes the box to lose all styles. It seems like the new CSS file isn't being loaded after being generated. Even if I manually reload the iFrame the new styles are not being loaded. I'll try to pull your PR locally and investigate a bit further.

@nmn
Copy link
Contributor

nmn commented Nov 1, 2024

I pulled the changes down locally and the file update is working correctly, so is the generateCSS script. However, the web preview is broken. I only saw the new styles applied once after a dozen attempts. Most of the time, the CSS simply does not load.

Copy link
Contributor

@nmn nmn left a comment

Choose a reason for hiding this comment

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

The generateCSS script from the docs app is probably not the best approach here.

The best idea would be to setup a standalone Rollup + React + StyleX application and then once that works correctly, re-create that setup within the playground.

Our Rollup plugin is the most reliable, so it should work well.

We can also try a custom Vite plugin, which is what is set up right now and can do Fast Refresh. There are a few examples of Vite plugins used with frameworks like Svelte, Qwik and Remix. One of those should work well as a starting point.

apps/docs/components/Playground.js Outdated Show resolved Hide resolved
apps/docs/components/Playground.js Outdated Show resolved Hide resolved
Comment on lines 27 to 28
flowSyntaxPlugin,
jsxSyntaxPlugin,
Copy link
Contributor

Choose a reason for hiding this comment

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

The StyleX plugin should already be doing this.

apps/docs/components/Playground.js Outdated Show resolved Hide resolved
apps/docs/components/Playground.js Outdated Show resolved Hide resolved
@nmn
Copy link
Contributor

nmn commented Nov 1, 2024

This branch will also need to be rebased again. I just rebased the better-playground branch.

@nmn nmn force-pushed the better-playground branch from e962bf8 to 58bd372 Compare November 1, 2024 08:34
@nmn
Copy link
Contributor

nmn commented Dec 4, 2024

@6ri4n we can show an error message in safari if it doesnt work, and maybe add an explicit reload button for the preview.

@6ri4n
Copy link
Author

6ri4n commented Dec 8, 2024

@nmn I've added the preview reload button, along with an error message that appears if the container fails to load (if the instance or url are invalid) after a certain period of time.

On Safari the preview may get stuck on the gray screen but I believe clicking the reload preview button resolves it as long as the url is valid. I would appreciate your feedback and if everything looks good, would you like me to add these features into #759

@nmn
Copy link
Contributor

nmn commented Dec 10, 2024

Yes. This is looking good functionally. The remaining issues are mostly visual and features which are being done in the other PR.

@nmn
Copy link
Contributor

nmn commented Dec 10, 2024

The one thing to investigate is to figure out why there is syntax highlighting for the code, but I won't block this work for that.

@6ri4n
Copy link
Author

6ri4n commented Dec 10, 2024

The one thing to investigate is to figure out why there is syntax highlighting for the code, but I won't block this work for that.

@nmn To clarify, are you talking about this playground with the vite setup or the playground with the rollup setup because I'm not seeing any syntax highlighting with the vite setup.

@nmn nmn force-pushed the better-playground branch from 58bd372 to 4c7402e Compare December 16, 2024 06:08
@nmn nmn marked this pull request as ready for review December 16, 2024 06:35
@nmn nmn force-pushed the better-playground branch 2 times, most recently from 72fb564 to 8c15b00 Compare December 16, 2024 14:41
@nmn
Copy link
Contributor

nmn commented Dec 16, 2024

This PR has been rebased merged into #12

@nmn nmn closed this Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants