Skip to content
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

Merged
merged 2 commits into from
Jan 3, 2022

Conversation

threepointone
Copy link
Contributor

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.

@changeset-bot
Copy link

changeset-bot bot commented Jan 2, 2022

🦋 Changeset detected

Latest commit: b702124

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

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}`);
Copy link
Contributor Author

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.

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.
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix!

packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved

// 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!
Copy link
Contributor

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]>
@threepointone threepointone merged commit 3426c13 into main Jan 3, 2022
@threepointone threepointone deleted the fix-inifinite-restart branch January 3, 2022 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants