fix: auto-refresh web preview after saving files in Code panel - Reso…
Resolves issue #2071
Description
This PR fixes a bug where changes made in the Code panel were not automatically applied to the web preview after saving. Users had to manually refresh the preview to see their code changes, which disrupted the development workflow.
Changes made:
- Added
refreshPreviewAfterSave()method toIDEManagerthat automatically reloads the web preview after successful file saves - Added
shouldRefreshPreview()method to only refresh for web-relevant file types (.js,.jsx,.ts,.tsx,.css,.scss,.sass,.less,.html) - Implemented a 100ms delay to ensure file write operations complete before triggering the preview reload
- Enhanced code formatting and added proper error handling
The fix ensures that when users save code changes in the Code panel, they immediately see the results in the web preview, creating a smooth development experience as intended.
Related Issues
Fixes #2071
Type of Change
- [x] Bug fix
- [ ] New feature
- [ ] Documentation update
- [ ] Release
- [ ] Refactor
- [ ] Other (please describe):
Testing
To test this fix:
- Open a project in Onlook
- Navigate to the Code panel (Dev tab) in the right panel
- Open any web-relevant file (
.js,.tsx,.css, etc.) - Make visible changes to the code (e.g., modify styles, add text, change colors)
- Save the file using Ctrl+S (Cmd+S on Mac) or the Save button
- Expected behavior: The web preview should automatically refresh within ~100ms and display the changes
- Previous behavior: Changes would not appear until manual refresh
Edge cases tested:
- Saving non-web files (
.md,.json, etc.) should not trigger unnecessary refreshes - Multiple rapid saves should work correctly
- Sandbox disconnection should not cause errors
Screenshots (if applicable)
https://github.com/user-attachments/assets/d26679d7-6d26-4a93-816e-025f1bd65bd3
Additional Notes
- The solution only affects manual saves from the Code panel, avoiding interference with other code-writing workflows (AI code application, undo/redo, etc.)
- File type checking prevents unnecessary reloads for non-web files
[!IMPORTANT] Adds auto-refresh functionality to web preview after saving web-relevant files in
IDEManager.
- Behavior:
- Adds
refreshPreviewAfterSave()toIDEManagerto auto-refresh web preview after saving files.- Introduces
shouldRefreshPreview()to check if file types affect the preview (e.g.,.js,.css).- Implements a 100ms delay to ensure file write completion before refresh.
- Edge Cases:
- Non-web files (e.g.,
.md,.json) do not trigger refresh.- Handles multiple rapid saves and sandbox disconnection without errors.
- Misc:
- Enhanced error handling and code formatting in
index.ts.This description was created by
for 3b925d842f04802ef520d7c98668029199bb4848. You can customize this summary. It will automatically update as commits are pushed.
@Rish-it is attempting to deploy a commit to the Onlook Team on Vercel.
A member of the Team first needs to authorize it.
Awesome thanks for the continued good work @Rish-it ! I removed the comments since your naming is very self-explanatory
I’ll definitely keep that in mind for future PRs. Appreciate the feedback!