Skip to content

fix: dead code and operator precedence bug#2

Open
ashkanrdn wants to merge 2 commits intolatestfrom
fix/dead-code-and-bugs
Open

fix: dead code and operator precedence bug#2
ashkanrdn wants to merge 2 commits intolatestfrom
fix/dead-code-and-bugs

Conversation

@ashkanrdn
Copy link
Owner

@ashkanrdn ashkanrdn commented Feb 21, 2026

Summary

  • Fix operator precedence bug: !dataSource === undefined (always false) → dataSource === undefined in dataProcessor.worker.ts
  • Remove dead applyViewStateConstraints() function from MapStory.tsx (defined but never called)
  • Remove duplicate selectedCounty: string from FilterState in filterSlice.ts — shadowed by map.selectedCounty, not consumed by any component; also removes unreachable setSelectedCounty reducer from the filters slice

Test plan

  • npm run build passes with no TypeScript errors
  • Load /map — map renders counties with colors
  • Hover tooltips appear
  • County click flies to county and highlights in right sidebar

🤖 Generated with Claude Code

Summary by Sourcery

Clean up unused code and correct a worker input validation condition.

Bug Fixes:

  • Fix incorrect operator precedence in the worker data validation check so missing dataSource is correctly detected.

Enhancements:

  • Remove an unused map view state constraint helper in MapStory.
  • Simplify filter state by removing an unused selectedCounty field, its initializer, and its reducer.

ashkan and others added 2 commits February 21, 2026 11:20
- Fix !dataSource === undefined (always false) → dataSource === undefined
- Remove dead applyViewStateConstraints() from MapStory (never called)
- Remove duplicate selectedCounty from FilterState (shadowed by map.selectedCounty)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
casi-2 Error Error Feb 21, 2026 7:00pm

@sourcery-ai
Copy link

sourcery-ai bot commented Feb 21, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Cleans up unused state and fixes a worker guard condition by correcting an operator precedence bug, removing dead React view-state code, and deleting an unused county-selection field and reducer from the filters slice.

Sequence diagram for worker message validation in dataProcessor.worker

sequenceDiagram
    participant MainThread
    participant DataProcessorWorker

    MainThread->>DataProcessorWorker: postMessage(geojsonFeatures, filteredData, selectedMetric, dataSource, isPerCapita, populationData)
    DataProcessorWorker->>DataProcessorWorker: onmessage(event)
    DataProcessorWorker->>DataProcessorWorker: extract geojsonFeatures, filteredData, selectedMetric, dataSource, isPerCapita, populationData
    alt Missing_or_invalid_data
        DataProcessorWorker->>DataProcessorWorker: if !geojsonFeatures || !filteredData || !selectedMetric || dataSource === undefined
        DataProcessorWorker->>DataProcessorWorker: log error Invalid data received
        DataProcessorWorker-->>MainThread: postMessage({ error })
    else Valid_data
        DataProcessorWorker->>DataProcessorWorker: process data with selectedMetric, dataSource, isPerCapita, populationData
        DataProcessorWorker-->>MainThread: postMessage({ choroplethData, summaryStats })
    end
Loading

Class diagram for updated FilterState and filterSlice reducers

classDiagram
    class FilterState {
        +string[] activeFilters
        +number[] yearRange
        +string selectedMetric
        +RankedCounty[] rankedCounties
        +DataSourceType selectedDataSource
        +boolean isPerCapita
        +string[] selectedCounties
        +CsvRow[][] csvDataSources
    }

    class RankedCounty {
        +string name
        +number value
        +number rank
    }

    class CsvRow {
        +string county
        +number value
        +number population
        +number year
    }

    class FilterSliceReducers {
        +setRankedCounties(state, rankedCounties)
        +setCsvData(state, csvRows)
        +toggleFilter(state, filterId)
        +setYear(state, year)
        +setYearRange(state, startYear, endYear)
        +setSelectedMetric(state, metricId)
        +setSelectedDataSource(state, dataSource)
        +setIsPerCapita(state, isPerCapita)
        +setSelectedCounties(state, selectedCounties)
        +resetOnDataSourceChange(state, newDataSource)
    }

    FilterSliceReducers o-- FilterState
    FilterState "*" o-- "*" CsvRow
    FilterState "*" o-- "*" RankedCounty
Loading

File-Level Changes

Change Details Files
Remove unused view-state constraint helper from the map widget component.
  • Delete the applyViewStateConstraints useCallback implementation that clamps longitude, latitude, and zoom but is never invoked
  • Leave existing view-state update logic unchanged so map behavior is not affected
app/components/widgets/MapStory.tsx
Simplify filter slice state by dropping an unused selectedCounty field and its reducer.
  • Remove selectedCounty from the FilterState interface and initialState
  • Delete the setSelectedCounty reducer and stop exporting it from the slice
  • Remove resets of selectedCounty during data source changes, relying instead on map.selectedCounty
lib/features/filters/filterSlice.ts
Fix worker input validation by correcting an operator precedence bug in the data processor worker.
  • Change the guard condition to test dataSource === undefined directly instead of using the always-false !dataSource === undefined expression
  • Preserve existing logging and error-posting behavior when inputs are invalid
app/components/workers/dataProcessor.worker.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In dataProcessor.worker.ts, consider simplifying the long guard condition by extracting it into a small isValidMessagePayload helper or by checking each required field with more explicit nullish checks (e.g. dataSource == null) to improve readability and make future changes safer.
  • Since applyViewStateConstraints was removed from MapStory.tsx, double-check that equivalent clamping of longitude/latitude/zoom is now handled elsewhere; if so, a short inline comment near the new logic explaining where constraints are enforced would prevent future reintroduction of similar dead code.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `dataProcessor.worker.ts`, consider simplifying the long guard condition by extracting it into a small `isValidMessagePayload` helper or by checking each required field with more explicit nullish checks (e.g. `dataSource == null`) to improve readability and make future changes safer.
- Since `applyViewStateConstraints` was removed from `MapStory.tsx`, double-check that equivalent clamping of longitude/latitude/zoom is now handled elsewhere; if so, a short inline comment near the new logic explaining where constraints are enforced would prevent future reintroduction of similar dead code.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant