Skip to content

Conversation

zardoy
Copy link
Owner

@zardoy zardoy commented Jul 18, 2025

FYI @Phoenix616 this changes a bit how autoConnect is handled. While it works the same, now technically UI is never opened at all.

Summary by CodeRabbit

  • New Features

    • Added support for filtering Minecraft data versions and skipping certain data types based on environment variables.
    • Introduced a function to detect download interest from URL query parameters.
    • Added new environment variables for finer build and UI configuration.
  • Improvements

    • Centralized and streamlined game entry and connection logic for more robust startup behavior.
    • Improved error handling for server info retrieval to better handle connection failures.
    • Enhanced localization by updating button labels to use translation functions.
    • Improved safety in inventory recipe lookups to prevent errors with missing data.
  • Bug Fixes

    • Prevented potential errors when accessing recipes if data is missing.
  • Chores

    • Updated and reorganized environment variable type declarations for clarity and specificity.

…ion data, this does not affect assets though

env:
MIN_MC_VERSION
MAX_MC_VERSION
new SKIP_MC_DATA_RECIPES - if recipes are not used in game
fix: refactor QS params handling to ensure panorama & main menu never loaded when immedieate game enter action is expected (eg ?autoConnect=1)
Copy link

coderabbitai bot commented Jul 18, 2025

Walkthrough

This update refactors startup logic for game entry, enhances environment variable typing and build configuration, adds version filtering and data skipping to Minecraft data processing, improves error handling in server info retrieval, and introduces a utility for download interest detection. Several props and auto-connect logic are removed from React components.

Changes

File(s) Change Summary
rsbuild.config.ts, scripts/genLargeDataAliases.ts, src/env.d.ts Enhanced build configuration: added/typed new environment variables, adjusted plugin logic for large data aliasing, and improved chunk naming for dynamic imports.
scripts/makeOptimizedMcData.mjs Added version filtering, conditional skipping of data types, and refined collision shape handling in Minecraft data optimization script.
src/index.ts Consolidated and refactored startup logic into a single function, improving game entry flow and modal handling.
src/downloadAndOpenFile.ts Added new exported function isInterestedInDownload to detect download-related query parameters.
src/inventoryWindows.ts Added nullish coalescing guards for safe access to loadedData.recipes.
src/react/AddServerOrConnect.tsx Removed allowAutoConnect prop and auto-connect logic; updated button labels for localization.
src/react/ServersListProvider.tsx Wrapped server info retrieval in try-catch for error handling; removed allowAutoConnect prop from modal.

Sequence Diagram(s)

sequenceDiagram
    participant App as App Startup
    participant FS as Filesystem & Config
    participant UI as UI Modals
    participant Game as Game Logic
    participant DL as Download Handler

    App->>FS: Wait for fsReady & appConfig
    alt Reconnect options exist
        App->>Game: Connect using reconnect options
    else If reconnect param in dev
        App->>Game: Connect using last saved options
    else If singleplayer param
        App->>Game: Load singleplayer
    else If save param
        App->>Game: Load save (if exists)
    else If ip/proxy param
        App->>Game: Auto-connect or show connect modal
    else If connectPeer param
        App->>UI: Prompt username if needed
        UI->>Game: Connect to peer
    else If viewerConnect param
        App->>Game: Connect as viewer
    else If modal param
        App->>UI: Show specified modal
    else If serversList param
        App->>UI: Show servers list modal
    else If download param
        App->>DL: Trigger download and open file
    end
    App->>Game: Possibly handle state variable
Loading

Possibly related PRs

  • feat: single file build #181: Adds single file build support and related environment variable handling, which directly connects to changes in build configuration and large data alias logic in this PR.

Suggested labels

Review effort 3/5

Suggested reviewers

  • Phoenix616

Poem

A bunny hopped through code today,
Tidying startup in a single array.
With configs neat and logic clear,
Version checks bring data near.
If downloads call, or servers fail,
The rabbit’s fixes will prevail!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@zardoy zardoy merged commit 5bd33a5 into next Jul 18, 2025
2 of 3 checks passed
@zardoy zardoy deleted the better-builds branch July 18, 2025 01:39
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9c7840 and 5385018.

📒 Files selected for processing (9)
  • rsbuild.config.ts (3 hunks)
  • scripts/genLargeDataAliases.ts (2 hunks)
  • scripts/makeOptimizedMcData.mjs (8 hunks)
  • src/downloadAndOpenFile.ts (1 hunks)
  • src/env.d.ts (1 hunks)
  • src/index.ts (4 hunks)
  • src/inventoryWindows.ts (3 hunks)
  • src/react/AddServerOrConnect.tsx (3 hunks)
  • src/react/ServersListProvider.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.ts

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/vars-usage.mdc
🧠 Learnings (5)
📓 Common learnings
Learnt from: zardoy
PR: zardoy/minecraft-web-client#373
File: renderer/viewer/three/entities.ts:1120-1120
Timestamp: 2025-06-23T13:33:14.776Z
Learning: In the minecraft-web-client project, team information for entities should be inlined into entity update events from the world data emitter rather than accessing the global bot object from renderer code. This maintains better separation of concerns between the data layer and renderer.
Learnt from: zardoy
PR: zardoy/minecraft-web-client#373
File: renderer/viewer/three/entities.ts:1120-1120
Timestamp: 2025-06-23T13:33:14.776Z
Learning: In the minecraft-web-client project, files under renderer/ directory must not access the global `bot` variable directly according to .cursor/rules/vars-usage.mdc. The updateNameTagVisibility method in renderer/viewer/three/entities.ts currently violates this rule by accessing bot.teamMap and bot.username. Team information should be passed through entity update events from the world data emitter instead.
Learnt from: zardoy
PR: zardoy/minecraft-web-client#391
File: renderer/viewer/three/threeJsUtils.ts:56-56
Timestamp: 2025-07-10T16:03:10.838Z
Learning: The minecraft-web-client project uses core-js auto polyfill injection, which means newer JavaScript features like Promise.withResolvers() are automatically polyfilled for compatibility across different environments.
src/react/ServersListProvider.tsx (1)
Learnt from: zardoy
PR: zardoy/minecraft-web-client#373
File: renderer/viewer/three/entities.ts:1120-1120
Timestamp: 2025-06-23T13:33:14.776Z
Learning: In the minecraft-web-client project, files under renderer/ directory must not access the global `bot` variable directly according to .cursor/rules/vars-usage.mdc. The updateNameTagVisibility method in renderer/viewer/three/entities.ts currently violates this rule by accessing bot.teamMap and bot.username. Team information should be passed through entity update events from the world data emitter instead.
scripts/makeOptimizedMcData.mjs (2)
Learnt from: zardoy
PR: zardoy/minecraft-web-client#373
File: renderer/viewer/three/entities.ts:1120-1120
Timestamp: 2025-06-23T13:33:14.776Z
Learning: In the minecraft-web-client project, files under renderer/ directory must not access the global `bot` variable directly according to .cursor/rules/vars-usage.mdc. The updateNameTagVisibility method in renderer/viewer/three/entities.ts currently violates this rule by accessing bot.teamMap and bot.username. Team information should be passed through entity update events from the world data emitter instead.
Learnt from: zardoy
PR: zardoy/minecraft-web-client#391
File: renderer/viewer/three/threeJsUtils.ts:56-56
Timestamp: 2025-07-10T16:03:10.838Z
Learning: The minecraft-web-client project uses core-js auto polyfill injection, which means newer JavaScript features like Promise.withResolvers() are automatically polyfilled for compatibility across different environments.
src/env.d.ts (1)
Learnt from: CR
PR: zardoy/minecraft-web-client#0
File: .cursor/rules/vars-usage.mdc:0-0
Timestamp: 2025-07-02T02:50:46.443Z
Learning: Some other global variables that can be used without window prefixes are listed in src/globals.d.ts.
src/index.ts (2)
Learnt from: CR
PR: zardoy/minecraft-web-client#0
File: .cursor/rules/vars-usage.mdc:0-0
Timestamp: 2025-07-02T02:50:46.443Z
Learning: Applies to src/**/*.ts : You may use the global variable `bot` directly in any file under the `src/` directory (e.g., `src/mineflayer/playerState.ts`).
Learnt from: CR
PR: zardoy/minecraft-web-client#0
File: .cursor/rules/vars-usage.mdc:0-0
Timestamp: 2025-07-02T02:50:46.443Z
Learning: Applies to renderer/**/*.ts : Do not use the global variable `bot` directly in any file under the `renderer/` directory or its subfolders (e.g., `renderer/viewer/three/worldrendererThree.ts`).
🧬 Code Graph Analysis (2)
src/downloadAndOpenFile.ts (1)
src/appParams.ts (2)
  • appQueryParams (81-90)
  • appQueryParamsArray (92-101)
rsbuild.config.ts (1)
scripts/genLargeDataAliases.ts (1)
  • genLargeDataAliases (3-29)
🪛 Biome (1.9.4)
src/index.ts

[error] 924-924: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🔇 Additional comments (20)
src/inventoryWindows.ts (3)

525-525: LGTM! Good defensive programming.

The nullish coalescing operator prevents runtime errors when loadedData.recipes is null or undefined.


553-553: LGTM! Consistent error prevention.

This follows the same defensive pattern as the other recipe access points in the file.


598-598: LGTM! Completes the defensive programming pattern.

All three recipe data access points in the file now have proper null/undefined guards.

src/downloadAndOpenFile.ts (1)

14-18: LGTM! Clean utility function for download detection.

This function centralizes the logic for determining download interest based on query parameters. The implementation is clear and follows good practices by checking all relevant parameters in one place.

scripts/genLargeDataAliases.ts (2)

19-20: LGTM! Good webpack optimization practices.

The explicit chunk naming will improve bundle analysis and debugging by providing meaningful names for the generated chunks.


34-34: LGTM! Global pako access for compatibility.

Making pako.inflate globally available likely supports existing code patterns or library compatibility requirements.

src/react/AddServerOrConnect.tsx (2)

34-34: LGTM! Good architectural refactoring.

Removing the allowAutoConnect prop aligns with centralizing auto-connect logic elsewhere in the application, which improves separation of concerns.


226-226: No import needed for translate
The translate function is provided as an ambient global in src/globals.d.ts (see lines 33–37), so no import is required. Please ignore this suggestion.

Likely an incorrect or invalid review comment.

rsbuild.config.ts (3)

142-148: LGTM! Preparing for performance optimization.

The commented-out prefetch configuration shows good planning for future performance improvements targeting the large data chunks.


164-164: LGTM! Environment variable refactoring.

The change from DEPS_VERSIONS to ALWAYS_MINIMAL_SERVER_UI appears to be part of a broader environment variable reorganization.


200-200: LGTM! Enhanced build configuration flexibility.

The expanded condition for large data compression provides more granular control over when compression should be applied, supporting both single file builds and explicit compression requests.

src/react/ServersListProvider.tsx (1)

159-175: Good error handling for WebSocket server info retrieval!

The try-catch block properly handles connection failures by providing a fallback data object with appropriate default values, preventing unhandled promise rejections and ensuring the UI can gracefully display connection failures.

src/env.d.ts (1)

5-35: Excellent type safety improvements for environment variables!

The narrowing of boolean-like environment variables to literal union types 'true' | 'false' provides better compile-time type checking. The new variables are well-organized under clear sections, making the configuration structure more maintainable.

scripts/makeOptimizedMcData.mjs (4)

46-66: Well-implemented version filtering feature!

The version clipping logic correctly filters Minecraft versions based on the environment variables, with proper numeric comparison and informative logging of the applied range.


85-87: Good optimization for conditional data skipping!

The implementation cleanly allows skipping language and recipes data processing using environment variables, which can significantly reduce bundle size when these data types aren't needed.

Also applies to: 166-168


274-300: Better handling of ignored collision shapes!

Injecting empty data structures instead of skipping entirely is a safer approach that prevents potential undefined access errors while maintaining consistent data structure.


277-277: Clearer function naming!

Renaming getData to getRealData better distinguishes this function's purpose of retrieving raw data from files.

src/index.ts (3)

170-170: Good state management for reconnect UI!

Explicitly setting showReconnect to false at the start of connection ensures the UI state is properly reset.


922-1068: Excellent refactoring of startup logic!

The maybeEnterGame function successfully consolidates all fragmented startup flows into a single, well-organized function. The waitForConfigFsLoad helper ensures proper initialization order while providing appropriate loading feedback.


1056-1058: Clean integration with download detection utility!

Good use of the isInterestedInDownload function to encapsulate download-related query parameter detection logic.

// immediate game enter actions: reconnect or URL QS
const maybeEnterGame = () => {
const waitForConfigFsLoad = (fn: () => void) => {
let unsubscribe: () => void | undefined
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix confusing void in union type

The static analysis correctly identifies that void in a union type is confusing. The type should indicate that unsubscribe is either a function or undefined.

-    let unsubscribe: () => void | undefined
+    let unsubscribe: (() => void) | undefined
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let unsubscribe: () => void | undefined
let unsubscribe: (() => void) | undefined
🧰 Tools
🪛 Biome (1.9.4)

[error] 924-924: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🤖 Prompt for AI Agents
In src/index.ts at line 924, the variable unsubscribe is typed as a union of a
function returning void or undefined, which is confusing. Change the type
annotation so that unsubscribe is either a function with no parameters returning
void or undefined, explicitly indicating it is a function or undefined, not a
union with void.

@Phoenix616
Copy link

Thanks for letting me know!

@coderabbitai coderabbitai bot mentioned this pull request Oct 10, 2025
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