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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-candles-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: prevent `useWorker`'s inifinite restarts during `dev`
17 changes: 12 additions & 5 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,12 @@ function useWorker(props: {
port,
} = props;
const [token, setToken] = useState<CfPreviewToken>();

// This is the most reliable way to reliably detect whether
threepointone marked this conversation as resolved.
Show resolved Hide resolved
// 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.

const startedRef = useRef(false);

useEffect(() => {
async function start() {
if (!bundle) return;
Expand All @@ -569,10 +575,11 @@ function useWorker(props: {
return;
}

if (token) {
console.log("⎔ Detected changes, restarting server...");
} else {
if (!startedRef.current) {
console.log("⎔ Starting server...");
startedRef.current = true;
} else {
console.log("⎔ Detected changes, restarting server...");
}

const assets = sitesFolder
Expand Down Expand Up @@ -624,7 +631,6 @@ function useWorker(props: {
apiToken,
})
);
console.log(`⬣ Listening at http://localhost:${port}`);
}
start().catch((err) => {
// we want to log the error, but not end the process
Expand All @@ -644,7 +650,6 @@ function useWorker(props: {
usageModel,
bindings,
modules,
token,
]);
return token;
}
Expand Down Expand Up @@ -681,6 +686,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.


const server = proxy.listen(port);

// TODO(soon): refactor logging format into its own function
Expand Down