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(remix-dev): re-use REMIX_DEV_SERVER_WS_PORT when reloading config #3206

Merged
merged 5 commits into from
May 17, 2022

Conversation

mcansh
Copy link
Collaborator

@mcansh mcansh commented May 16, 2022

closes REM-1091

closes #2958

Signed-off-by: Logan McAnsh [email protected]

  • Docs
  • Tests

Testing Strategy:

I opened up a new playground (npm run playground:new) with a basic node server running on port 8002 and then created a few new files to trigger the config reload while logging the current REMIX_DEV_SERVER_WS_PORT.
image

@MichaelDeBoey MichaelDeBoey changed the title fix(remix-dev): re-use REMIX_DEV_SERVER_WS_PORT when reloading config fix(remix-dev): re-use REMIX_DEV_SERVER_WS_PORT when reloading config May 16, 2022
@tessellator
Copy link

I think this can still get you in trouble wrt #296. If you set REMIX_DEV_SERVER_WS_PORT to the same value in two different projects, you would lose the advantage of using getPort. I will test to verify. I provided a similar solution in #3202 that will work in two projects simultaneously.

@tessellator
Copy link

tessellator commented May 16, 2022

Confirmed, but on second thought this behavior might be desirable. This PR makes REMIX_DEV_SERVER_WS_PORT explicit and will fail fast if the port is already taken, whereas the other PR is a "best effort" and will rewrite REMIX_DEV_SERVER_WS_PORT if the port is already taken.

(Note that you still get the advantage of getPort if REMIX_DEV_SERVER_WS_PORT is not explicitly set.)

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thanks! What do you think about this?

packages/remix-dev/config.ts Outdated Show resolved Hide resolved
@mcansh mcansh force-pushed the logan-rem-1091-fix-livereload branch from 97d385e to 9b9ad25 Compare May 16, 2022 23:41
if (process.env.REMIX_DEV_SERVER_WS_PORT) {
try {
devServerPort = Number(process.env.REMIX_DEV_SERVER_WS_PORT);
} catch (error: unknown) {

Choose a reason for hiding this comment

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

I'm unsure if Number ever throws an error. In most cases it will return NaN instead.

In this part of the code, it would mean that someone explicitly set the env var to an invalid value. If it wasn't set explicitly, then it would either 1) fall through to getPort on the initial load, or 2) have been set to the output of getPort on a previous load.

Is getPort as default the right thing to do if someone explicitly sets the env var to an invalid value? (Genuinely curious as to the philosophy of the Remix team.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup, you're right on the NaN, Mondays amirite 😅. i'll wait for @kentcdodds' thoughts on the default behavior, i could see throwing an error as the desired behavior

Choose a reason for hiding this comment

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

Awesome. :) Thanks so much for working on this. I'm excited to see LiveReload working again!

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Another thought

packages/remix-dev/config.ts Outdated Show resolved Hide resolved
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Sweet! Thanks 👏👏

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Whoops 😅 Ok, should be good now!

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

I really shouldn't use our CI as my development environment 😅

@kentcdodds kentcdodds merged commit 1ab9745 into dev May 17, 2022
@kentcdodds kentcdodds deleted the logan-rem-1091-fix-livereload branch May 17, 2022 15:37
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v1.5.0-pre.1 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v1.5.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@EkaanshArora
Copy link

Hi team,

This breaks out of the box hot-reload with some of the templates (eg: just the basics + express) as the used port is different from the expected 8002 default port for these configurations. (#3237)

This is because the new code gets a random available port if the environment variable isn't set - it's undefined for the templates as remix.config.js does not include a devServerPort.

Should the templates be updated to have "devServerPort": 8002 in the remix.config.js?

@kentcdodds
Copy link
Member

@EkaanshArora, thanks. @mcansh is going to look into this.

@danditomaso
Copy link

Any updates on this issue?

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

Successfully merging this pull request may close these issues.

7 participants