fix: revert quick file write on refresh (#5943)

* fix: REVERT REVERT REVERT

* fix: one more unused remove

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* Make sure connection is established before advancing settings theme test

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

* A snapshot a day keeps the bugs away! 📷🐛

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frankjohnson1993@gmail.com>
This commit is contained in:
Kevin Nadro
2025-03-21 19:33:43 -05:00
committed by GitHub
parent f6936f55d6
commit 3464f93a30
7 changed files with 1 additions and 41 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

After

Width:  |  Height:  |  Size: 69 KiB

View File

@ -746,6 +746,7 @@ test.describe('Testing settings', () => {
}) })
await page.setBodyDimensions({ width: 1200, height: 500 }) await page.setBodyDimensions({ width: 1200, height: 500 })
await homePage.goToModelingScene() await homePage.goToModelingScene()
await expect(toolbar.startSketchBtn).toBeEnabled({ timeout: 15_000 })
await scene.settled(cmdBar) await scene.settled(cmdBar)
await page.waitForTimeout(1000) await page.waitForTimeout(1000)

View File

@ -34,7 +34,6 @@ import { settingsActor, useSettings } from 'machines/appMachine'
import { createRouteCommands } from 'lib/commandBarConfigs/routeCommandConfig' import { createRouteCommands } from 'lib/commandBarConfigs/routeCommandConfig'
import { useToken } from 'machines/appMachine' import { useToken } from 'machines/appMachine'
import { createNamedViewsCommand } from 'lib/commandBarConfigs/namedViewsConfig' import { createNamedViewsCommand } from 'lib/commandBarConfigs/namedViewsConfig'
import { reportRejection } from 'lib/trap'
type MachineContext<T extends AnyStateMachine> = { type MachineContext<T extends AnyStateMachine> = {
state: StateFrom<T> state: StateFrom<T>
@ -61,20 +60,6 @@ export const FileMachineProvider = ({
[] []
) )
// Write code mirror content to disk when the page is trying to reroute
// Our logic for codeManager.writeToFile has an artificial 1000ms timeout which
// won't run quickly enough so users can make an edit, exit the page and lose their
// progress within that 1000ms window.
useEffect(() => {
const preventUnload = (event: BeforeUnloadEvent) => {
codeManager.writeToFileNoTimeout().catch(reportRejection)
}
window.addEventListener('beforeunload', preventUnload)
return () => {
window.removeEventListener('beforeunload', preventUnload)
}
}, [])
useEffect(() => { useEffect(() => {
// TODO: Engine feature is not deployed // TODO: Engine feature is not deployed
if (DEV) { if (DEV) {

View File

@ -164,32 +164,6 @@ export default class CodeManager {
} }
} }
// When we unload the page via changing routes we want to instantly write to disk to save their progress
// There is a race condition in the system. writeToFile takes 1000ms to run, if they make an edit and leave within the 1000ms
// window they won't get their content saved. Use this to always save their file before rerouting
async writeToFileNoTimeout() {
if (isDesktop()) {
return new Promise((resolve, reject) => {
if (!this._currentFilePath)
return reject(new Error('currentFilePath not set'))
// Wait one event loop to give a chance for params to be set
// Save the file to disk
window.electron
.writeFile(this._currentFilePath, this.code ?? '')
.then(resolve)
.catch((err: Error) => {
// TODO: add tracing per GH issue #254 (https://github.com/KittyCAD/modeling-app/issues/254)
console.error('error saving file', err)
toast.error('Error saving file, please check file permissions')
reject(err)
})
})
} else {
safeLSSetItem(PERSIST_CODE_KEY, this.code)
}
}
async updateEditorWithAstAndWriteToFile(ast: Program) { async updateEditorWithAstAndWriteToFile(ast: Program) {
// We clear the AST when there it cannot be parsed, so if we are trying to write an empty AST, its // We clear the AST when there it cannot be parsed, so if we are trying to write an empty AST, its
// probably because of an earlier error. That's a bad state to be in and it's not going to be // probably because of an earlier error. That's a bad state to be in and it's not going to be