Skip to content

frontend: avoid unnecessary dev-server bridge calls in production - #4627

Open
thisconnect wants to merge 1 commit into
BitBoxSwiss:masterfrom
thisconnect:frontend-dev-server
Open

thisconnect wants to merge 1 commit into
BitBoxSwiss:masterfrom
thisconnect:frontend-dev-server

Conversation

@thisconnect

@thisconnect thisconnect commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Dev servers are only used during development, so querying the go backend for their status in production is unnecessary.

Use Vite's build-time environment flag to return false in production, allowing the bundler to eliminate the dev-server bridge call entirely. This avoids unnecessary communication between the frontend and go backend while preserving the existing behavior in development.

Before asking for reviews, here is a check list of the most common things you might need to consider:

  • updating the Changelog
  • writing unit tests
  • checking if your changes affect other coins or tokens in unintended ways
  • testing on multiple environments (Qt, Android, ...)
  • having an AI review your changes

@thisconnect

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

AppProvider now obtains development-server state through the new useDevServers hook. The hook loads getDevServers outside production and uses false in production. It also supplies false as the default value.

Merge Risk: Minimal · up to 9c41c

This change skips the dev-server status call in production builds and leaves development behavior unchanged. No concrete merge-blocking risk was found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a165a3b2-177d-4412-bf20-8d92e003805a
Commits

Reviewing files that changed from the base of the PR and between 676d80e and 9c41c06.

Files selected for processing: 2

  • frontends/web/src/contexts/AppProvider.tsx
  • frontends/web/src/hooks/environment.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@thisconnect
thisconnect marked this pull request as ready for review November 24, 2026 07:31
@thisconnect
thisconnect requested a review from a team as a code owner November 24, 2026 07:31
export const useDevServers = () => {
const isDevServers = useDefault(
useLoad(
import.meta.env.PROD

@sutterseba sutterseba Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When running make webserve alongside make servewallet-mainnet, Bitrefill and BTC Direct widgets fail to initialize (because PROD=true but Go still defaults to devservers=true).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Correct, frontend and backend need to run in same mode.

So for make webserve you'll need to run the backend in prod mode with make servewallet-prodservers or make servewallet-mainnet-prodservers. With this Pocket, BTCDirect and Bitrefill iframes load, howerver Moonpay still refuses to connect but for a different reason (also on master I beleive it needs some referrer headers or similar).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This came up in a codex review as a regression, probably because the requirement to match front and backend is not really documented anywhere? Previously the frontend followed the backend’s flag regardless of build mode, so this requirement wasn’t obvious imo.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should I add something to the readme?

for example:

Run the UI in production mode

Run make webserve to build and serve the production version of the UI in a web browser.
This is useful for testing production-specific behavior without building the native app.

In a separate terminal, run make servewallet-prodservers (testnet) or
make servewallet-mainnet-prodservers (mainnet) to start the backend using production servers.

Unlike make webdev, changes to the frontend code are not automatically rebuilt.

Dev servers are only used during development, so querying the go
backend for their status in production is unnecessary.

Use Vite's build-time environment flag to return false in production,
allowing the bundler to eliminate the dev-server bridge call entirely.
This avoids unnecessary communication between the frontend and go
backend while preserving the existing behavior in development.
@thisconnect

Copy link
Copy Markdown
Collaborator Author

rebased

@sutterseba sutterseba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants