Commit a05542a
committed
fix(files): fix Monaco stale closure, XLSX Ctrl+S data loss, and async workbook mutation
Three bugs from Cursor Bugbot follow-up review:
1. Stale closure in handleEditorMount (Medium): useCallback([], []) captured
content='' at first render. When Monaco mounts after content loads (e.g.
switching from preview to editor mode), lastSyncedContentRef was never
initialized and external content changes stopped syncing. Fixed by keeping
a contentRef updated on every render and reading it inside handleEditorMount.
2. XLSX Ctrl+S discards active cell edit (Medium): handleSave read from
workbookRef.current before DataTable's in-progress editValue was committed.
Fixed by exposing commitEdit() from DataTable via useImperativeHandle
(using an always-current editStateRef so the handle stays stable) and
calling it at the top of handleSave.
3. Async workbook mutation fragility (Low): handleCellChange / handleHeaderChange
updated the workbook inside import('xlsx').then(), creating microtask-order
coupling with handleSave. Fixed by caching the xlsx module in xlsxModuleRef
on first parse and using it synchronously in both handlers.1 parent e794eeb commit a05542a
2 files changed
Lines changed: 60 additions & 20 deletions
File tree
- apps/sim/app/workspace/[workspaceId]/files/components/file-viewer
Lines changed: 33 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
23 | 52 | | |
24 | 53 | | |
25 | 54 | | |
| |||
121 | 150 | | |
122 | 151 | | |
123 | 152 | | |
| 153 | + | |
| 154 | + | |
Lines changed: 27 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
658 | 659 | | |
659 | 660 | | |
660 | 661 | | |
| 662 | + | |
661 | 663 | | |
662 | 664 | | |
663 | 665 | | |
| |||
700 | 702 | | |
701 | 703 | | |
702 | 704 | | |
| 705 | + | |
703 | 706 | | |
704 | 707 | | |
705 | 708 | | |
| |||
841 | 844 | | |
842 | 845 | | |
843 | 846 | | |
844 | | - | |
845 | | - | |
846 | | - | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
847 | 851 | | |
848 | 852 | | |
849 | 853 | | |
| |||
1887 | 1891 | | |
1888 | 1892 | | |
1889 | 1893 | | |
| 1894 | + | |
| 1895 | + | |
1890 | 1896 | | |
1891 | 1897 | | |
1892 | 1898 | | |
| |||
1904 | 1910 | | |
1905 | 1911 | | |
1906 | 1912 | | |
| 1913 | + | |
1907 | 1914 | | |
1908 | 1915 | | |
1909 | 1916 | | |
| |||
1966 | 1973 | | |
1967 | 1974 | | |
1968 | 1975 | | |
1969 | | - | |
1970 | | - | |
1971 | | - | |
1972 | | - | |
1973 | | - | |
1974 | | - | |
1975 | | - | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
1976 | 1982 | | |
1977 | 1983 | | |
1978 | 1984 | | |
1979 | | - | |
| 1985 | + | |
1980 | 1986 | | |
1981 | 1987 | | |
1982 | 1988 | | |
| |||
1993 | 1999 | | |
1994 | 2000 | | |
1995 | 2001 | | |
1996 | | - | |
1997 | | - | |
1998 | | - | |
1999 | | - | |
2000 | | - | |
2001 | | - | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
2002 | 2008 | | |
2003 | | - | |
| 2009 | + | |
2004 | 2010 | | |
2005 | 2011 | | |
2006 | 2012 | | |
| |||
2013 | 2019 | | |
2014 | 2020 | | |
2015 | 2021 | | |
| 2022 | + | |
| 2023 | + | |
2016 | 2024 | | |
2017 | 2025 | | |
2018 | 2026 | | |
| |||
2116 | 2124 | | |
2117 | 2125 | | |
2118 | 2126 | | |
| 2127 | + | |
2119 | 2128 | | |
2120 | 2129 | | |
2121 | 2130 | | |
| |||
0 commit comments