Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 6, 2025

Problem

DI migration left backward-compatibility shims (legacy named exports and wrapper functions) that add runtime indirection, hide module boundaries, and increase maintenance overhead. This PR begins systematic removal of all shims.

Changes

Completed: 4 of 19 modules (21%)

Phase 1: Utility Modules

  • Telemetry - Removed shim, updated 3 entry points to instantiate factory
  • CachedSearch - Removed shim and legacy named exports (isSearchCached, markSearchAsCached, etc.)
  • Profile - Removed shim, updated 2 UI components to instantiate factory

Phase 2a: RecentFood

  • Removed shim and legacy exports (fetchUserRecentFoods, deleteRecentFoodByReference, etc.)
  • Updated 4 consumers including test mocks

Pattern

Before (with shim):

// Module exports both factory and shim
export function createFoo(deps) { return { method() {...} } }
const _default = createFoo()
export const method = _default.method  // Shim

// Consumer uses shim
import { method } from './foo'
method()

After (factory only):

// Module exports only factory
export function createFoo(deps) { return { method() {...} } }
export type Foo = ReturnType<typeof createFoo>

// Consumer instantiates
import { createFoo } from './foo'
const foo = createFoo()
foo.method()

Remaining

15 modules across 5 phases:

  • Measure & TemplateSearch (3)
  • Recipe & MacroProfile (3)
  • Day-Diet modules (4, high-risk: 16+ consumers)
  • Auth & User (2)

Deferred:

  • Toast (45 consumers)
  • Clipboard (circular dependency)

Final phase: integrate all factories into src/di/container.tsx and remove src/di/useCases.ts global instance.

Original prompt

This section details on the original issue you should resolve

<issue_title>Refactor(di): Remove all DI backward-compatibility shims and complete migration plan</issue_title>
<issue_description># Refactor Template

Title:
Refactor(di): Remove all DI backward-compatibility shims and complete migration plan

Description:
Over the past weeks several migration batches moved module factories and use-cases into the DI container while leaving short-lived backward-compatibility "shims" (legacy named exports, helper re-exports, and runtime indirection) in place. Those shims increase runtime indirection, hide module boundaries, and create testing and maintenance friction. This refactor finishes the DI migration by removing all remaining shims, consolidating factories and exports in the DI container, and updating consumers and tests to use the container/factories directly.

This issue codifies a step-by-step migration plan, lists all affected modules/files discovered in the last 50 commits, and defines acceptance criteria to safely remove the shims and keep CI/tests passing.

Scope:
Affected modules and files (collected from the last 50 commits — review each for leftover shims and migration impact):

  • src/di/container.tsx
  • src/di/useCases.ts
  • DI-migration-plan.md
  • src/modules/diet/day-diet/application/usecases/createBlankDay.ts
  • src/modules/diet/day-diet/application/usecases/dayUseCases.ts
  • src/modules/diet/day-diet/application/usecases/dayEditOrchestrator.ts
  • src/modules/diet/day-diet/application/usecases/useCopyDayOperations.ts
  • src/modules/diet/day-diet/tests/application/createBlankDay.test.ts
  • src/modules/diet/day-diet/tests/application/dayEditOrchestrator.test.ts
  • src/modules/diet/macro-profile/application/usecases/macroProfileState.ts
  • src/modules/diet/macro-profile/application/usecases/macroProfileUseCases.ts
  • src/modules/diet/macro-profile/application/service/macroProfileCrudService.ts
  • src/modules/diet/macro-target/application/macroTargetUseCases.ts
  • src/modules/diet/macro-nutrients/application/macroOverflow.ts
  • src/modules/diet/meal/application/meal.ts
  • src/modules/diet/food/application/usecases/foodCrud.ts
  • src/modules/diet/food/infrastructure/api/infrastructure/supabase/supabaseFoodRepository.ts
  • src/modules/diet/recipe/application/usecases/recipeCrud.ts
  • src/modules/measure/application/usecases/measureCrud.ts
  • src/modules/measure/application/usecases/measureState.ts
  • src/modules/observability/application/telemetry.ts
  • src/modules/profile/application/profile.ts
  • src/modules/recent-food/application/usecases/recentFoodCrud.ts
  • src/modules/recent-food/infrastructure/recentFoodRepository.ts
  • src/modules/search/application/usecases/cachedSearchCrud.ts
  • src/modules/template-search/application/usecases/templateSearchState.ts
  • src/modules/toast/application/toastManager.ts
  • src/modules/user/application/usecases/userUseCases.ts
  • src/modules/weight/application/chart/weightChartUseCases.ts
  • src/modules/weight/application/weight/usecases/weightUseCases.ts
  • src/modules/clipboard/application/usecases/clipboardUseCases.ts
  • src/modules/clipboard/README.md
  • src/sections/clipboard/components/ClipboardPanel.tsx
  • src/sections/clipboard/components/ClipboardToggleButton.tsx
  • src/sections/common/components/ClipboardActionButtons.tsx
  • src/sections/ean/components/EANSearch.tsx
  • src/sections/item/components/ItemView/ItemEdit/ItemChildrenEditor.tsx
  • src/sections/item/components/ItemView/ItemEdit/ItemEditModal.tsx
  • src/sections/item/components/ItemView/ItemEdit/ItemEditBody.tsx
  • src/sections/item/components/ItemView/ItemViewMacros.tsx
  • src/sections/meal/components/MealEditView.tsx
  • src/sections/recipe/components/RecipeEditView.tsx
  • src/sections/search/components/TemplateSearchModal.tsx
  • src/sections/day-diet/components/DayMeals.tsx
  • src/sections/weight/components/WeightChartTooltip.tsx
  • src/sections/weight/components/WeightEvolution.tsx
  • src/sections/weight/components/WeightView.tsx
  • src/sections/profile/components/MacroEvolution.tsx
  • src/sections/profile/components/MacroProfile.tsx
  • src/sections/profile/measure/components/BodyMeasureChart.tsx
  • .github/copilot-instructions.md

(Note: Some files above were already migrated in batches; this list is exhaustive for the last 50 commits and helps verify no leftover shims remain.)

Motivation:

  • Remove runtime indirection and legacy compatibility layers that hide true module boundaries.
  • Improve maintainability and testability by making DI explicit and centralized.
  • Reduce bundle/hydration surprises by avoiding implicit exports and runtime shims.
  • Align codebase with repository rules (no barrel files, explicit DI wiring) and finalized migration plan.

Migration Plan (step-by-step):

  1. Inventory and classify shims
    • For each file listed in Scope, open and categorize the shim type: legacy named export, re-export helper, runtime proxy, or test-only shim.
    • Produce a small matrix: file → shim type → migra...

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link

vercel bot commented Dec 6, 2025

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

Project Deployment Preview Comments Updated (UTC)
macroflows Error Error Dec 10, 2025 9:49pm

…ile modules

Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com>
Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor DI to remove backward-compatibility shims refactor(di): Remove backward-compatibility shims from telemetry, search, profile, and recentFood modules Dec 6, 2025
Copilot AI requested a review from marcuscastelo December 6, 2025 19:51
@marcuscastelo marcuscastelo marked this pull request as ready for review December 10, 2025 21:04
Copilot AI review requested due to automatic review settings December 10, 2025 21:04
Copy link
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 PR removes backward-compatibility shims from 4 modules (Telemetry, CachedSearch, Profile, and RecentFood) as part of the ongoing DI migration. The refactor eliminates legacy named exports and requires consumers to explicitly instantiate factories. While the direction is correct and aligns with the migration plan, there is a critical bug in the Profile module changes where two components create separate instances of stateful reactive signals, breaking state synchronization.

Key changes:

  • Removed shims from Telemetry, CachedSearch, Profile, and RecentFood modules
  • Updated 13 consumers to instantiate factories directly at module level
  • Updated test mocks to work with factory pattern instead of named exports

Critical Issue:
The Profile module uses createRoot() to create reactive signals. When UserInfo.tsx and UserInfoCapsule.tsx each create their own profile instance at module level, they get completely isolated state that won't stay synchronized. This breaks the expected behavior where both components should share the same profile state.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/modules/observability/application/telemetry.ts Removed backward-compatible shim; consumers now call factory directly
src/entry-client.tsx Updated to instantiate telemetry factory
src/entry-server.tsx Updated to instantiate telemetry factory
src/instrument.server.ts Updated to instantiate telemetry factory
src/modules/search/application/usecases/cachedSearchCrud.ts Removed shim and legacy named exports
src/modules/diet/food/application/usecases/foodCrud.ts Updated to instantiate cachedSearchCrud factory
src/modules/diet/food/infrastructure/api/application/apiFood.ts Updated to instantiate cachedSearchCrud factory
src/modules/profile/application/profile.ts Removed backward-compatible shim ⚠️
src/sections/profile/components/UserInfo.tsx Creates separate profile instance at module level (broken state)
src/sections/profile/components/UserInfoCapsule.tsx Creates separate profile instance at module level (broken state)
src/modules/recent-food/application/usecases/recentFoodCrud.ts Removed shim and legacy named exports
src/sections/search/components/TemplateSearchModal.tsx Updated to instantiate recentFoodCrud factory (creates duplicate instance)
src/sections/common/components/buttons/RemoveFromRecentButton.tsx Updated to instantiate recentFoodCrud factory (creates duplicate instance)
src/sections/common/components/buttons/RemoveFromRecentButton.test.tsx Updated test mocks to work with factory pattern
src/modules/template-search/application/usecases/templateSearchState.ts Updated to accept RecentFoodCrud dependency via factory

@marcuscastelo marcuscastelo merged commit 305c96f into marcuscastelo/issue1447-remove-shims Dec 10, 2025
2 of 3 checks passed
@marcuscastelo marcuscastelo deleted the copilot/remove-di-backward-compatibility-shims branch December 10, 2025 21:55
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.

Refactor(di): Remove all DI backward-compatibility shims and complete migration plan

2 participants