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

PM2 doesn't seem to work with Fresh #2562

Open
saeho opened this issue Jun 30, 2024 · 8 comments
Open

PM2 doesn't seem to work with Fresh #2562

saeho opened this issue Jun 30, 2024 · 8 comments

Comments

@saeho
Copy link

saeho commented Jun 30, 2024

Screen.Recording.2024-06-30.at.7.08.04.AM.mov

Related issue & better video: #2564

In this video, the app works. Half way through the video, I ran a command in terminal like this:
deno task build && pm2 start main.ts --name=\"APP NAME\" --interpreter=\"deno\" --interpreter-args=\"run -A main.ts\" && pm2 save basically using PM2 to serve main.ts. That's when the app crashes.

Able to duplicate 100% by deploying a new build using PM2 to serve main.ts.

Cannot duplicate if deploying a new build WITHOUT PM2 to serve main.ts manually.

I cannot read deduce if this error is coming from Fresh, or a Socket.io or possibly my code, but reading the production minified code, I don't think it's my code. I could be wrong though.

I'd like to investigate this error more by deploying using PM2. the dev.ts file instead. But I can't, because serving dev.ts causes the browser to refresh on reconnect to $fresh. So I need some way to disable initial app refresh when dev.ts runs.

If someone understands why PM2 causes Deno Fresh to break, I'd like some input.

Update: This issue is not tied to PM2, serving the app without PM2 is equally a severe problem.

@marvinhagemeister marvinhagemeister changed the title Fresh app breaks for all users after a new deployment (PM2) PM2 doesn't seem to work with Fresh Jun 30, 2024
@marvinhagemeister
Copy link
Collaborator

What are the steps needed to reproduce the error on our machines?

@saeho
Copy link
Author

saeho commented Jun 30, 2024

What are the steps needed to reproduce the error on our machines?

Before that, I would really like to know how I can disable initial browser refresh (NOT hot code refreshes) in dev.ts so I can deploy dev.ts and see the error in non-minified version.

@saeho
Copy link
Author

saeho commented Jun 30, 2024

Steps to reproduce:

  1. Create a signal() as a constant, outside a React component (might be duplicatable using useSignal() too)
  2. Route somewhere and attempt to go back.
  3. It will crash either when you route or when you press back.

https://github.com/saeho/fresh-signal-bug

@saeho
Copy link
Author

saeho commented Jun 30, 2024

More tests have allowed me to deduce that this is caused by Signals, possibly global constant signals, but might be duplicatable using useSignal() too.

I need to see the error in non-minified form to get more info, but dev.ts makes that impossible with initial browser refresh.

Edit:
Further tests allowed me to duplicate the error using useSignal() without anything global in a minimal codebase (same repo above)

@rschristian
Copy link
Contributor

Before that, I would really like to know how I can disable initial browser refresh (NOT hot code refreshes) in dev.ts so I can deploy dev.ts and see the error in non-minified version.

Just a drive-by suggestion, but is your issue that the devtools console is getting cleared because of the refresh? Both FireFox and Chrome (and I'd imagine Safari too) have an option in the devtools to persist logs which you can enable to get around this.

@saeho
Copy link
Author

saeho commented Jun 30, 2024

Before that, I would really like to know how I can disable initial browser refresh (NOT hot code refreshes) in dev.ts so I can deploy dev.ts and see the error in non-minified version.

Just a drive-by suggestion, but is your issue that the devtools console is getting cleared because of the refresh? Both FireFox and Chrome (and I'd imagine Safari too) have an option in the devtools to persist logs which you can enable to get around this.

Thank you, I can't believe I didn't know about this option before.

Well, after looking into it it's a default "WebSocket connection to _frsh/alive failed" which is normal since the old fresh app died.

In development, this isn't an issue because the app is force refreshed by dev script. But in production this is an issue because the app does not force refresh, causing existing users to be stranded.

I actually think this is a Signal related issue because I was able to reproduce it with minimal code base in the repo I attached above.

@saeho
Copy link
Author

saeho commented Jun 30, 2024

Reproduced without PM2, using a single line of code.

#2564

@saeho
Copy link
Author

saeho commented Jul 3, 2024

More info/discussion in this PreactJS Signal thread: preactjs/signals#581

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

No branches or pull requests

3 participants