-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prevent dev
from infinitely restarting
#183
Conversation
🦋 Changeset detectedLatest commit: b702124 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -678,6 +680,8 @@ function useProxy({ | |||
}, | |||
}); | |||
|
|||
console.log(`⬣ Listening at http://localhost:${port}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this message here because it just makes more sense here.
08cb3d5
to
30982b8
Compare
In #164, we added `token` to `useWorker`'s `useEffect` array that detects when to start the server process. However, the effect itself sets `token`, so the build would inifinitely restart on every run. We could potentially fix this by using `useMemo` or something, but that's overkill for the reason we use `token` - to detect whether it's the first or subsequent time we've started the server, and what message to log to the terminal. So we introduce a ref `startedRef` to play that role, and mark it as true when we log the message the first time. This fixes the infinite loop. This bug shows how urgent it is to write tests for everything else. We'll get there.
30982b8
to
5a5c6ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good fix!
|
||
// This is the most reliable way to reliably detect whether | ||
// something's "happened" in our system; We make a ref and | ||
// mark it once we log our initial message. Refs are vars! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this comment! Very helpful.
Co-authored-by: Pete Bacon Darwin <[email protected]>
In #164, we added
token
touseWorker
'suseEffect
array that detects when to start the server process. However, the effect itself setstoken
, so the build would inifinitely restart on every run.We could potentially fix this by using
useMemo
or something, but that's overkill for the reason we usetoken
- to detect whether it's the first or subsequent time we've started the server, and what message to log to the terminal. So we introduce a refstartedRef
to play that role, and mark it as true when we log the message the first time. This fixes the infinite loop.This bug shows how urgent it is to write tests for everything else. We'll get there.