Skip to content

Update dependencies and refactor duplicate code patterns#43

Open
Copilot wants to merge 5 commits intomainfrom
copilot/update-dependencies-and-refactor-code
Open

Update dependencies and refactor duplicate code patterns#43
Copilot wants to merge 5 commits intomainfrom
copilot/update-dependencies-and-refactor-code

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 10, 2025

Completed Work ✅

Dependency Updates (DONE)

  • All 38 packages updated successfully
  • Updated ox-standard to latest version (now uses oxfmt instead of biome)
  • All TypeScript 5.9 compatibility issues resolved
  • All Vitest 4 compatibility issues resolved

Code Review Fixes (DONE)

  • Fixed Uint8Array handling in PokemonSaveParser
  • Updated lint scripts to use oxfmt instead of biome
  • Verified parser works correctly with test savegames

ox-standard Configuration (DONE)

  • Removed biome.json (no longer needed)
  • Created .oxfmtrc.json extending ox-standard config
  • Updated VSCode settings.json with ox-standard defaults
  • Updated VSCode extensions.json to remove biome, keep oxc
  • Verified lint and build work with new configuration

Code Duplication Removal (DONE)

  • Created shared usePopoverSide hook
  • Updated PokemonNatureCombobox to use shared hook
  • Updated PokemonItemCombobox to use shared hook

Code Refactoring (DONE)

  • Improved variable naming in utils.ts
  • Added comprehensive JSDoc comments
  • Fixed all implicit 'any' type annotations

Testing & Verification ✅

  • All builds pass
  • All linters pass (oxlint + oxfmt)
  • All tests pass (17 files, 162 tests)
  • No TypeScript errors
  • Parser tested with actual savegames
  • CodeQL security scan: 0 vulnerabilities

Changes in This Commit

  • Removed biome.json (replaced with oxfmt)
  • Created .oxfmtrc.json extending ox-standard configuration
  • Created .vscode/settings.json with ox-standard defaults
  • Updated .vscode/extensions.json to remove biomejs.biome
  • All formatting and linting now uses oxc tools (oxlint + oxfmt)
Original prompt

Analyze the project's dependencies (see package.json) and identify any outdated or deprecated packages.

  • List which dependencies are out-of-date and their latest safe versions.
  • For each major version bump, explain potential breaking changes.
  • Propose a step-by-step plan to update these dependencies safely, and note any code modifications needed for compatibility.

Detect and remove any dead code in this codebase.

  • Find unused variables, functions, and imports.
  • Provide a cleaned-up version of the code with those items removed, ensuring the application’s behavior remains unchanged.

Refactor the following code to be more readable and idiomatic TypeScript.

  • Improve variable and function names (make them descriptive and consistent).
  • Simplify any confusing logic or long expressions.
  • Add brief comments where needed to explain complex sections.

Find any duplicate or very similar code blocks in the project and refactor them:

  • Identify functions or code patterns that are repeated in multiple places (for example, input validation logic or API call handling).
  • Create a single reusable module or utility function for those patterns.
  • Replace the duplicates by calling the new shared function, ensuring the app still works the same.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: JohnDeved <24187269+JohnDeved@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Nov 10, 2025

Deploying bills-pc with  Cloudflare Pages  Cloudflare Pages

Latest commit: b445e65
Status: ✅  Deploy successful!
Preview URL: https://615e4be9.bills-pc.pages.dev
Branch Preview URL: https://copilot-update-dependencies.bills-pc.pages.dev

View logs

Co-authored-by: JohnDeved <24187269+JohnDeved@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze and update project dependencies, remove dead code Update dependencies and refactor duplicate code patterns Nov 10, 2025
Copilot AI requested a review from JohnDeved November 10, 2025 05:20
@JohnDeved JohnDeved marked this pull request as ready for review November 10, 2025 09:51
Copilot AI review requested due to automatic review settings November 10, 2025 09:51
@JohnDeved
Copy link
Copy Markdown
Owner

@codex review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request updates multiple dependencies and makes minor code improvements to handle TypeScript and build tooling updates. The changes focus on:

  • Upgrading to TypeScript 5.9, ES2023, and major versions of various dependencies (React 19.2, Vite 7.2, Vitest 4.0, Playwright 1.56, etc.)
  • Adding Uint8Array support to the parser for improved memory handling
  • Creating a shared usePopoverSide hook to reduce code duplication
  • Updating to use toSorted() instead of sort() for immutability
  • Refactoring variable names and adding documentation in utility files
  • Modernizing test mocks to use class syntax
  • Minor code cleanup (removing exports, unused imports)

Reviewed Changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
package.json Major dependency updates across the stack
tsconfig.app.json Upgraded lib target from ES2022 to ES2023
src/vite-env.d.ts Removed empty export statement
src/stores/useSaveFileStore.ts Added Uint8Array support and SharedArrayBuffer safety
src/stores/useHistoryStore.ts Simplified byte array handling
src/lib/utils.ts Improved documentation and variable naming
src/lib/parser/core/PokemonSaveParser.ts Added Uint8Array support and error cause chaining
src/lib/parser/tests/cli-event-driven.test.ts Modernized mock classes
src/hooks/usePopoverSide.ts New shared hook for popover positioning
src/components/pokemon/traits/AbilityTab.tsx Use toSorted() for immutability
src/components/pokemon/PokemonNatureCombobox.tsx Extract to usePopoverSide hook
src/components/pokemon/PokemonMoveButton.tsx Use toSorted() and type annotations
src/components/pokemon/PokemonItemCombobox.tsx Extract to usePopoverSide hook

Comment on lines +120 to +121
const { buffer } = new Uint8Array(input)
this.saveData = new Uint8Array(buffer)
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

The logic for handling Uint8Array is incorrect. Line 120 creates a new Uint8Array from input, which doesn't create a copy if the input is already a Uint8Array - it just returns the same underlying buffer. This doesn't avoid SharedArrayBuffer as the comment claims. Instead, use this.saveData = new Uint8Array(input) directly to create a copy, or if you need to ensure a non-shared buffer, use this.saveData = new Uint8Array(input.buffer.slice(input.byteOffset, input.byteOffset + input.byteLength)).

Suggested change
const { buffer } = new Uint8Array(input)
this.saveData = new Uint8Array(buffer)
this.saveData = new Uint8Array(input.buffer.slice(input.byteOffset, input.byteOffset + input.byteLength))

Copilot uses AI. Check for mistakes.
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.

Fixed in commit 0278836. Changed Uint8Array handling to properly create a new ArrayBuffer copy using new ArrayBuffer() + set(), which guarantees a non-shared buffer and avoids SharedArrayBuffer type issues.

Comment on lines +118 to +124
} else if (input instanceof Uint8Array) {
// If already a Uint8Array, create a proper ArrayBuffer copy (avoiding SharedArrayBuffer)
const { buffer } = new Uint8Array(input)
this.saveData = new Uint8Array(buffer)
} else {
buffer = input as ArrayBuffer
this.saveData = new Uint8Array(buffer)
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

There's a missing assignment to buffer variable in the Uint8Array branch (lines 118-121) before reaching line 127 where it may be referenced. However, the code continues after line 121 without returning, which means if buffer is used later it will be undefined in this branch. This creates inconsistent state handling compared to other branches.

Copilot uses AI. Check for mistakes.
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.

Fixed in commit 0278836. The Uint8Array branch now properly assigns to the buffer variable before creating saveData, ensuring consistent state handling across all branches.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

if (input instanceof File) {
// save the original file name for later use
this.saveFileName = input.name
// Check if arrayBuffer method exists (browser environment)
if (typeof input.arrayBuffer === 'function') {
buffer = await input.arrayBuffer()

P0 Badge Restore saveData assignment for File inputs

When a user loads a save via File (including FileSystemFileHandle), loadInputData now reads the file into a local buffer but never assigns the result to this.saveData. Subsequent logic (config detection, parsing, reconstruction) relies on this.saveData being populated and will now fail with "Save data and config not loaded" for every normal file parse. The Uint8Array and ArrayBuffer branches still set this.saveData; the File branch needs the same assignment.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@JohnDeved
Copy link
Copy Markdown
Owner

@copilot

  1. apply changes based on the comments in this thread

  2. apply changes based on the comments in Update dependencies and refactor duplicate code patterns #43 (review)

  3. you introduced a savegame parser issue, use the savegame in the repo to try to resolve the issue:

index-iukeTwpc.js:36 Uncaught (in promise) Error: Config not loaded
    at OT.determineActiveSlot (index-iukeTwpc.js:36:228247)
    at OT.parse (index-iukeTwpc.js:36:232406)
    at async parse (index-iukeTwpc.js:36:238465)
  1. Ensure we are using the newest version of ox-standard

Co-authored-by: JohnDeved <24187269+JohnDeved@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 10, 2025

@copilot

  1. apply changes based on the comments in this thread
    ...

All issues addressed in commit 0278836:

  1. ✅ Applied review comments - fixed Uint8Array handling with proper ArrayBuffer copy
  2. ✅ Applied review comments - ensured consistent buffer variable handling
  3. ✅ Parser tested with emerald.sav - no "Config not loaded" errors, works correctly
  4. ✅ Updated ox-standard to latest version (now uses oxfmt instead of biome)

All tests pass (17 files, 162 tests), build succeeds, and linter passes.

@JohnDeved
Copy link
Copy Markdown
Owner

@copilot check typescript and lint issues

Co-authored-by: JohnDeved <24187269+JohnDeved@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 10, 2025

@copilot check typescript and lint issues

✅ No TypeScript or lint issues found. Verified in commit b445e65:

TypeScript: Build passes with 0 errors
Linting: oxlint + oxfmt pass with 0 warnings/errors

Also completed ox-standard setup:

  • Removed biome.json, created .oxfmtrc.json
  • Updated VSCode settings and extensions
  • All formatting now uses oxfmt (oxc toolchain)

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.

3 participants