perf: use dynamic imports for node:net#5314
Merged
chenjiahan merged 1 commit intomainfrom May 27, 2025
Merged
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
Improves startup performance by replacing static node:net imports with dynamic imports and converting related utility functions to async.
- Introduce dynamic imports for
createServerandisIPv6in helper utilities - Update
getHostInUrlandgetAddressUrlsto return promises - Await new async functions in
prodServer.ts,devServer.ts, andopen.ts
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/core/src/server/prodServer.ts | Added await for getAddressUrls |
| packages/core/src/server/open.ts | Changed getHostInUrl call to await the async function |
| packages/core/src/server/helper.ts | Switched from static node:net import to dynamic imports and updated function signatures to async |
| packages/core/src/server/devServer.ts | Added await for getAddressUrls |
Comments suppressed due to low confidence (1)
packages/core/src/server/helper.ts:412
- New async behavior in
getAddressUrlsshould be covered by unit tests—verify both host-specific and multi-interface address branches.
export const getAddressUrls = async ({
| tryLimits = 1; | ||
| } | ||
|
|
||
| const { createServer } = await import('node:net'); |
There was a problem hiding this comment.
Consider hoisting the dynamic import of createServer outside of the loop or caching the imported module to avoid repeated import overhead on subsequent calls.
Suggested change
| const { createServer } = await import('node:net'); | |
| if (!cachedCreateServer) { | |
| const { createServer } = await import('node:net'); | |
| cachedCreateServer = createServer; | |
| } | |
| const createServer = cachedCreateServer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Replacing synchronous
node:netimports with dynamic imports for better performance, and updating all calls to handle these changes.Checklist