-
Notifications
You must be signed in to change notification settings - Fork 309
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
base: better-playground
Are you sure you want to change the base?
Conversation
… into dev-better-playground
Hi @nmn, here’s what I have so far. I'd appreciate any feedback or suggestions. |
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. |
I pulled the changes down locally and the file update is working correctly, so is the |
There was a problem hiding this 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.
flowSyntaxPlugin, | ||
jsxSyntaxPlugin, |
There was a problem hiding this comment.
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.
This branch will also need to be rebased again. I just rebased the |
e962bf8
to
58bd372
Compare
Co-authored-by: Naman Goel <[email protected]>
Co-authored-by: Naman Goel <[email protected]>
Co-authored-by: Naman Goel <[email protected]>
Co-authored-by: Naman Goel <[email protected]>
@nmn, I don't think I have the abilities to get the Can you also take a look at the latest deployment, it seems to be working for me. If the latest deployment is also working for you, would you still want me to try and setup a custom |
It does mostly work for me as well. Every edit of the file refreshes the preview twice, which is what I saw as well. Regarding a custom Vite plugin, I have many examples on the Ecosystem page that should work well. I will try to get a standalone project going and make sure it works outside of a WebContainer first. I'll try Rollup first because it's easier to setup. |
I have a project with Rollup working properly here:
Using this project, you should be able to have a four tab design with the following tabs:
You can probably skip the eslint and typescript parts of the project for now. That should make the setup fairly small. I made a mistake and shared this on the other PR yesterday. |
- note: rollup command not generating dist directory and associated files
fe2c706
to
66a0a37
Compare
@nmn, I adjusted the project to exclude typescript and eslint and got the entire However, only when running the project inside the web container it's unable to create the |
This is strange because the link I shared is running on Stackblitz which runs within a webcontainer itself... |
I'm not sure what I'm doing wrong, do you have any suggestions on what I should do?. I also tried setting up the project to include typescript and eslint, matching the structure in the stackblitz link you shared but I got the same issue of the |
@6ri4n let me try it on my end and get back to you. Maybe there are some config options needed for webcontainers. |
Do you have any suggestions on other good first issues I can possibly work on in the meantime? I also found that when the container first loads, the preview is black but when you modify the jsx and let it apply the changes the preview shows the results however it's not behaving as intended. |
@nmn, I got the preview working by adding back the setTimeout in the 'server-ready' listener to wait for the project to fully load. However, currently it's set to 5 seconds and works on Chrome but I found that on other browsers like FireFox it requires a longer delay, otherwise the preview will be black. The preview also renders twice for some reason (you can see this if you remove the I added a setTimeout that |
What changed / motivation ?
WIP Implementing Playground Container
Changed the following web container project structure:
Vite
instead ofRollup
generateCSS.js
script which is make-stylex-sheet.js but with small changesChanged the following to Playground.js:
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 thegenerateCSS.js
script which createsstylex.css
inside thesrc
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
Hot Reloading / Applying Changes
Pre-flight checklist
Contribution Guidelines