Skip to content

Conversation

Copy link

Copilot AI commented Sep 11, 2025

  • Implement lazy loading for character builder tabs using local Reagent atom
  • Add tests and documentation for lazy loading implementation
  • Fix linting errors from parentheses mismatch in new-options-column function
  • Fix shadowed function parameter warnings in options.cljc and events.cljs

Fixed Issues

Syntax Errors:

  • ✅ Fixed unmatched parentheses in src/cljs/orcpub/character_builder.cljs (new-options-column function)
  • ✅ Resolved "Found an opening ( with no matching )" error on line 1641

Shadowed Parameter Warnings:

  • ✅ Fixed shadowed source parameter in subrace-option function (renamed to subrace-source)
  • ✅ Fixed shadowed source parameter in race-option function (renamed to race-source)
  • ✅ Fixed shadowed character parameter in set-level-hit-points function (renamed to char)

Validation

All linting errors and warnings have been resolved:

  • ✅ 0 syntax errors
  • ✅ 0 shadowed parameter warnings
  • ✅ Lazy loading functionality preserved and working

The character builder performance improvements are now ready with clean, lint-free code.

This pull request was created as a result of the following prompt from Copilot chat.

The character builder view in src/cljs/orcpub/character_builder.cljs is experiencing significant performance issues, causing the browser to freeze. This is especially noticeable when users load large amounts of custom homebrew content (e.g., 3MB+ files).

The root cause is twofold:

  1. Expensive Rendering: The current implementation renders the UI for all section tabs (Classes, Background, Spells, etc.) at once, even though only one is visible at a time. With extensive homebrew content, this creates an enormous number of DOM elements, overwhelming the browser.
  2. Expensive Computation: Re-frame subscriptions that calculate character options ([:available-selections]) must process a large dataset on every change, blocking the main thread. This is compounded by the rendering of all tabs, which activates numerous unnecessary subscriptions.

This pull request should solve the problem by implementing a lazy loading strategy for the character builder's tabs.

Plan:

  1. Introduce Local State: Modify the character-builder component to use a local Reagent atom (e.g., (r/atom 0)) to track the currently selected tab index. This follows the existing "form-2" component pattern seen elsewhere in the codebase.
  2. Conditionally Render Tab Content: Update the view logic to only render the components and content for the active tab based on the state of the new atom. The content for all other tabs should not be rendered.
  3. Ensure Data Integrity: The solution must rely on Re-frame's subscription model to ensure that all underlying character data remains accurate and that computations for all options are still performed in the background, even when their corresponding views are not rendered. The UI should simply render this pre-computed data when a tab becomes active.

This change will isolate the expensive rendering problem and reduce the number of active subscriptions, providing a significant and immediate performance improvement.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] feat: Optimize Character Builder with Lazy Loading Tabs Fix character builder performance issues with large homebrew content by implementing lazy tab loading Sep 11, 2025
Copilot AI requested a review from codeGlaze September 11, 2025 16:33
@codeGlaze
Copy link
Owner

@copilot src/cljc/orcpub/dnd/e5/options.cljc:1965:31: warning: Shadowed fn param: source
src/cljc/orcpub/dnd/e5/options.cljc:2191:28: warning: Shadowed fn param: source
src/cljs/orcpub/character_builder.cljs:1641:1: error: Found an opening ( with no matching )
src/cljs/orcpub/character_builder.cljs:2097:1: error: Expected a ) to match ( from line 1641
src/cljs/orcpub/dnd/e5/events.cljs:1166:57: warning: Shadowed fn param: character
linting took 7447ms, errors: 2, warnings: 3
Error encountered performing task 'run' with profile(s): 'lint'
Suppressed exit

Copy link
Author

Copilot AI commented Sep 11, 2025

@copilot src/cljc/orcpub/dnd/e5/options.cljc:1965:31: warning: Shadowed fn param: source
src/cljc/orcpub/dnd/e5/options.cljc:2191:28: warning: Shadowed fn param: source
src/cljs/orcpub/character_bui...

Fixed all linting errors and warnings:

Syntax Errors: Resolved unmatched parentheses in new-options-column function
Shadowed Parameters: Fixed 3 shadowed function parameter warnings by renaming:

  • sourcesubrace-source in subrace-option function
  • sourcerace-source in race-option function
  • characterchar in set-level-hit-points function

Commit: 20863bc

@codeGlaze codeGlaze marked this pull request as ready for review September 11, 2025 22:53
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