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

Scripts: coerce live reload port to integer #29196

Merged
merged 2 commits into from Feb 23, 2021

Conversation

emilio-martinez
Copy link
Contributor

Description

Attempting to use process.env.WP_LIVE_RELOAD_PORT was not working for me. After some debugging, I realized webpack-livereload-plugin must not expect to receive a port argument of a string type, failing silently to take the desired port, and per process.env docs:

Assigning a property on process.env will implicitly convert the value to a string.

Additionally, the use of the logical OR operator would prevent passing a 0 value, precluding the use of the following webpack-livereload-plugin functionality:

If you define port 0, an available port will be searched for, starting from 35729.

This PR aims to remedy this by parsing process.env.WP_LIVE_RELOAD_PORT before passing the value to webpack-livereload-plugin.

How has this been tested?

Validated by running these changes against a local project. Before the change, running wp-scripts start would always log one of the two below:

  • Live Reload listening on port 35729
  • Live Reload disabled: listen EADDRINUSE: address already in use :::35729 (for parallel processes run)

After the changes in this PR, the appropriate port will be used — including the use of a 0 value.

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @emilio-martinez! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Feb 22, 2021
@gziolo gziolo added this to Needs review in Core JS Feb 22, 2021
@gziolo gziolo added [Type] Bug An existing feature does not function as intended [Package] Scripts /packages/scripts labels Feb 22, 2021
@gziolo
Copy link
Member

gziolo commented Feb 22, 2021

Thank you for your contribution. The proposed change makes sense. I had only a minor styling comment.

Side note: Live reload will eventually get replaced by React Fast Refresh as explored in #28273.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Nice, it's ready to go. Thank you!

@gziolo gziolo merged commit e9ab152 into WordPress:master Feb 23, 2021
@gziolo gziolo moved this from Needs review to Done in Core JS Feb 23, 2021
@github-actions
Copy link

Congratulations on your first merged pull request, @emilio-martinez! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 10.1 milestone Feb 23, 2021
@emilio-martinez emilio-martinez deleted the fix/scripts-live-reload-port branch February 23, 2021 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
No open projects
Core JS
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants