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: wait for actual port before opening browser with --port=0 #5033

Merged
merged 2 commits into from
Feb 16, 2024

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Feb 16, 2024

Fixes part of #3907.

What this PR solves / how to test:

When running wrangler dev --port=0, Wrangler doesn't know the port the dev server started up on until the onReady callback is called. In --remote mode, this can take a while meaning there's a significant period of time where pressing b opens localhost:0. This change ensures we wait until the first onReady call before opening the browser with the correct port.

Author has addressed the following:

  • Tests
    • Included
    • Not necessary because: should ideally have some, but the hotkeys are only testable when stdin is a TTY, meaning we'd need to write these in interactive-dev-tests. But the behaviour is only observable when using --remote mode which requires Cloudflare account credentials. We could write a unit test for this, but again this is tricky because useHotkeys() relies on the useInput() hook from Ink, which we'd need to mock. This behaviour also relies on module-level variables. 😬
  • Changeset (Changeset guidelines)
    • Included
    • Not necessary because:
  • Associated docs
    • Issue(s)/PR(s):
    • Not necessary because: fixing a regression

Note for PR author:

We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label highlight pr review so future reviewers can take inspiration and learn from it.

@mrbbot mrbbot requested a review from a team as a code owner February 16, 2024 14:12
Copy link

changeset-bot bot commented Feb 16, 2024

🦋 Changeset detected

Latest commit: 00147c8

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

Copy link
Contributor

github-actions bot commented Feb 16, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7933801579/npm-package-wrangler-5033

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5033/npm-package-wrangler-5033

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7933801579/npm-package-wrangler-5033 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7933801579/npm-package-create-cloudflare-5033 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7933801579/npm-package-cloudflare-kv-asset-handler-5033
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7933801579/npm-package-miniflare-5033
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7933801579/npm-package-cloudflare-pages-shared-5033

Note that these links will no longer work once the GitHub Actions artifact expires.


wrangler@3.28.2 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240129.2
workerd 1.20240129.0 1.20240129.0
workerd --version 1.20240129.0 2024-01-29

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a751489) 70.42% compared to head (00147c8) 70.37%.
Report is 10 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5033      +/-   ##
==========================================
- Coverage   70.42%   70.37%   -0.05%     
==========================================
  Files         297      297              
  Lines       15425    15458      +33     
  Branches     3952     3966      +14     
==========================================
+ Hits        10863    10879      +16     
- Misses       4562     4579      +17     

see 14 files with indirect coverage changes

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.

Pulled this down and tested locally, given that we don't have any tests for user interactions in wrangler dev.

@petebacondarwin
Copy link
Contributor

The only thing I would note is that we are not told that Wrangler is waiting for the port to become available.
So I ended up pressing b multiple times, thinking it had not worked. And so subsequently got about 5 browsers all pop up at once!

@mrbbot mrbbot merged commit b1ace91 into main Feb 16, 2024
17 checks passed
@mrbbot mrbbot deleted the bcoll/wait-for-port-before-open-browser branch February 16, 2024 18:54
@mrbbot
Copy link
Contributor Author

mrbbot commented Feb 16, 2024

Fixed in 0147c8, bs are ignored if there's currently a browser open pending, and we log Waiting for port... if pressed while we don't have one. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants