Skip to content

feat: direct ws connection fallback#4474

Merged
chenjiahan merged 7 commits intoweb-infra-dev:mainfrom
wxiaoyun:feat/direct-ws-connection-fallback
Feb 4, 2025
Merged

feat: direct ws connection fallback#4474
chenjiahan merged 7 commits intoweb-infra-dev:mainfrom
wxiaoyun:feat/direct-ws-connection-fallback

Conversation

@wxiaoyun
Copy link
Copy Markdown
Contributor

@wxiaoyun wxiaoyun commented Feb 2, 2025

Summary

  • Fallback to direct ws connection similar to Vite

Related Links

Resolves #4466

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 2, 2025

CLA assistant check
All committers have signed the CLA.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 2, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 7bb52e8
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/67a0d1cc358bae00082da4a7
😎 Deploy Preview https://deploy-preview-4474--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 82 (🟢 up 18 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

nodeResult.family === dnsResult.family &&
nodeResult.address === dnsResult.address;
return isSame ? undefined : nodeResult.address;
}
Copy link
Copy Markdown
Contributor Author

@wxiaoyun wxiaoyun Feb 2, 2025

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice if we could do some refactoring based on Rsbuild's needs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there any special needs you would like?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the current version is LGTM 👍

@wxiaoyun
Copy link
Copy Markdown
Contributor Author

wxiaoyun commented Feb 2, 2025

HMR successful on Tauri iOS
CleanShot 2025-02-02 at 22 57 56@2x

connection = null;
reconnectCount++;
setTimeout(connect, 1000 * 1.5 ** reconnectCount);
setTimeout(() => connect(true), 1000 * 1.5 ** reconnectCount);
Copy link
Copy Markdown
Member

@chenjiahan chenjiahan Feb 3, 2025

Choose a reason for hiding this comment

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

I am worried that changing the default fallback logic here will cause some cases to fail to connect.

In Vite, each connect will use the host of the current page first, and then use the direct host if it fails. (https://github.com/vitejs/vite/blob/main/packages/vite/src/client/client.ts#L53-L71)

However, this PR forces all re-connects to use only the direct host, but it is obvious that it cannot be connected in some scenarios, such as on Cloud IDE.

Copy link
Copy Markdown
Contributor Author

@wxiaoyun wxiaoyun Feb 3, 2025

Choose a reason for hiding this comment

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

I have changed to onError instead of onClose so that it wont break existing reconnect logic. Would this be better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, using onError looks good to me 👍

]);

export async function resolveHostname(
optionsHost: string | boolean | undefined,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rsbuild's server.host only supports string type, maybe we can remove boolean type here.

@@ -0,0 +1,75 @@
import { promises as dns } from 'node:dns';
import { DevConfig, ServerConfig } from 'src/types/config';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Prefer to use relative path

let name = host === undefined || wildcardHosts.has(host) ? 'localhost' : host;

if (host === 'localhost') {
// See #8647 for more details.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to update this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lets remove it

Copy link
Copy Markdown
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

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

👍

@chenjiahan chenjiahan merged commit 8ec8eed into web-infra-dev:main Feb 4, 2025
8 checks passed
@wxiaoyun wxiaoyun deleted the feat/direct-ws-connection-fallback branch February 4, 2025 02:08
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.

[Bug]: HMR Not Working with Rsbuild in Tauri iOS Project

3 participants