Skip to content

Commit a6ed618

Browse files
committed
Use useSignalsEffect, not effect, because wasmInitFailed is initially true
Which broke the web app
1 parent a5aabfc commit a6ed618

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@million/lint": "^1.0.14",
3737
"@msgpack/msgpack": "^3.1.2",
3838
"@preact/signals-core": "^1.12.1",
39+
"@preact/signals-react": "^3.6.1",
3940
"@react-hook/resize-observer": "^2.0.1",
4041
"@replit/codemirror-interact": "^6.3.1",
4142
"@ts-stack/markdown": "^1.5.0",

src/App.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
MlEphantManagerReactContext,
6363
MlEphantManagerTransitions2,
6464
} from '@src/machines/mlEphantManagerMachine2'
65+
import { useSignalEffect } from '@preact/signals-react'
6566

6667
if (window.electron) {
6768
maybeWriteToDisk(window.electron)
@@ -191,8 +192,14 @@ export function App() {
191192
authToken,
192193
])
193194

194-
useEffect(() => {
195-
const needsWasmInitFailedToast = !isDesktop() && kclManager.wasmInitFailed
195+
// This is, at time of writing, the only spot we need @preact/signals-react,
196+
// because we can't use the core `effect()` function for this signal, because
197+
// it is initially set to `true`, and will break the web app.
198+
// TODO: get the loading pattern of KclManager in order so that it's for real available,
199+
// then you might be able to uninstall this package and stick to just using signals-core.
200+
useSignalEffect(() => {
201+
const needsWasmInitFailedToast =
202+
!isDesktop() && kclManager.wasmInitFailedSignal.value
196203
if (needsWasmInitFailedToast) {
197204
toast.success(
198205
() =>
@@ -209,7 +216,7 @@ export function App() {
209216
)
210217
}
211218
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: blanket-ignored fix me!
212-
}, [kclManager.wasmInitFailed])
219+
})
213220

214221
// Only create the native file menus on desktop
215222
useEffect(() => {

0 commit comments

Comments
 (0)