Skip to content

Commit 3464f93

Browse files
nadr0github-actions[bot]franknoirot
authored
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>
1 parent f6936f5 commit 3464f93

7 files changed

+1
-41
lines changed

β€Že2e/playwright/testing-settings.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ test.describe('Testing settings', () => {
746746
})
747747
await page.setBodyDimensions({ width: 1200, height: 500 })
748748
await homePage.goToModelingScene()
749+
await expect(toolbar.startSketchBtn).toBeEnabled({ timeout: 15_000 })
749750
await scene.settled(cmdBar)
750751
await page.waitForTimeout(1000)
751752

β€Žsrc/components/FileMachineProvider.tsx

-15
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { settingsActor, useSettings } from 'machines/appMachine'
3434
import { createRouteCommands } from 'lib/commandBarConfigs/routeCommandConfig'
3535
import { useToken } from 'machines/appMachine'
3636
import { createNamedViewsCommand } from 'lib/commandBarConfigs/namedViewsConfig'
37-
import { reportRejection } from 'lib/trap'
3837

3938
type MachineContext<T extends AnyStateMachine> = {
4039
state: StateFrom<T>
@@ -61,20 +60,6 @@ export const FileMachineProvider = ({
6160
[]
6261
)
6362

64-
// Write code mirror content to disk when the page is trying to reroute
65-
// Our logic for codeManager.writeToFile has an artificial 1000ms timeout which
66-
// won't run quickly enough so users can make an edit, exit the page and lose their
67-
// progress within that 1000ms window.
68-
useEffect(() => {
69-
const preventUnload = (event: BeforeUnloadEvent) => {
70-
codeManager.writeToFileNoTimeout().catch(reportRejection)
71-
}
72-
window.addEventListener('beforeunload', preventUnload)
73-
return () => {
74-
window.removeEventListener('beforeunload', preventUnload)
75-
}
76-
}, [])
77-
7863
useEffect(() => {
7964
// TODO: Engine feature is not deployed
8065
if (DEV) {

β€Žsrc/lang/codeManager.ts

-26
Original file line numberDiff line numberDiff line change
@@ -164,32 +164,6 @@ export default class CodeManager {
164164
}
165165
}
166166

167-
// When we unload the page via changing routes we want to instantly write to disk to save their progress
168-
// There is a race condition in the system. writeToFile takes 1000ms to run, if they make an edit and leave within the 1000ms
169-
// window they won't get their content saved. Use this to always save their file before rerouting
170-
async writeToFileNoTimeout() {
171-
if (isDesktop()) {
172-
return new Promise((resolve, reject) => {
173-
if (!this._currentFilePath)
174-
return reject(new Error('currentFilePath not set'))
175-
176-
// Wait one event loop to give a chance for params to be set
177-
// Save the file to disk
178-
window.electron
179-
.writeFile(this._currentFilePath, this.code ?? '')
180-
.then(resolve)
181-
.catch((err: Error) => {
182-
// TODO: add tracing per GH issue #254 (https://github.com/KittyCAD/modeling-app/issues/254)
183-
console.error('error saving file', err)
184-
toast.error('Error saving file, please check file permissions')
185-
reject(err)
186-
})
187-
})
188-
} else {
189-
safeLSSetItem(PERSIST_CODE_KEY, this.code)
190-
}
191-
}
192-
193167
async updateEditorWithAstAndWriteToFile(ast: Program) {
194168
// We clear the AST when there it cannot be parsed, so if we are trying to write an empty AST, its
195169
// probably because of an earlier error. That's a bad state to be in and it's not going to be

0 commit comments

Comments
Β (0)