Skip to content

Decouple common/utils/utils from legacy stores so Storybook can use the real Utils #7360

@talissoncosta

Description

@talissoncosta

Background

In #7100 we set up Storybook for component rendering. To keep stories isolated, we had to stub common/utils/utils because the real module triggers a webpack initialisation error in Storybook:

utils → common/stores/account-store → common/constants → … → utils

The circular chain crashes the bundler at module init time.

The current workaround lives in frontend/.storybook/stubs/utils.js — a hand-rolled subset of Utils with simplified implementations of:

  • colour
  • GUID
  • fromParam
  • escapeHtml
  • getFlagsmithHasFeature / getFlagsmithValue / getPlansPermission
  • isSaas
  • keys.isEscape
  • safeParseEventValue

Problem

Stories render against the stub, not production Utils. Behaviour can drift:

  • The stub's GUID is a Math.random() shim, not whatever production uses (uuid?).
  • The stub's fromParam does a basic URLSearchParams parse and won't handle nested keys, repeat params, or type coercion the same way production does.
  • The stub's colour happens to match production today but won't pick up future changes (dark-mode-aware fallbacks, etc.).
  • Any new Utils.* method added to production has to be manually mirrored in the stub or stories using it will break.

This makes Storybook a less reliable visual reference for components that use Utils.

Proposed fix

Break the circular dependency in production so Storybook can import the real common/utils/utils:

  1. Identify the cycle. The stub comment points at utils → account-store → constants. Map the full chain and decide which edge to cut.
  2. Likely candidates:
    • Move whatever utils.tsx needs from account-store into a small data-only module that doesn't pull constants back in.
    • Or split utils.tsx into a leaf module (no store imports) and a shell that re-exports + adds store-aware helpers — only the shell would be unsafe to import in Storybook, but most stories don't need those helpers.
  3. Once the cycle is gone, drop frontend/.storybook/stubs/utils.js and remove the alias from frontend/.storybook/main.js.
  4. Verify stories still render and that the legacy .js components depending on Utils (Input.js, etc.) still work in stories.

Acceptance criteria

  • frontend/.storybook/stubs/utils.js is deleted.
  • frontend/.storybook/main.js no longer aliases common/utils/utils to a stub.
  • npm run storybook boots cleanly and all stories render.
  • Spot-check stories that use Utils.colour, Utils.GUID, and Utils.fromParam (ToggleChip, Checkbox, Tabs) — same visual behaviour as before.

Notes

Metadata

Metadata

Assignees

Labels

front-endIssue related to the React Front End Dashboardtech-debtTechnical debt issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions