Skip to content

ENG-177: Add global message API ref for out-of-tree toast usage#7695

Merged
gilluminate merged 5 commits intomainfrom
gill/ENG-177/global-message-api-ref
Mar 18, 2026
Merged

ENG-177: Add global message API ref for out-of-tree toast usage#7695
gilluminate merged 5 commits intomainfrom
gill/ENG-177/global-message-api-ref

Conversation

@gilluminate
Copy link
Contributor

@gilluminate gilluminate commented Mar 18, 2026

Ticket ENG-177

Description Of Changes

Add a global message API ref pattern to fidesui so that code running outside the React component tree (e.g. Redux middleware) can access the themed Ant Design messageApi. This is PR 1 of 4 for the toast-to-Ant migration (ENG-177).

  • Create globalMessageApi.ts with getGlobalMessageApi/setGlobalMessageApi helpers
  • Wire up FidesUIProvider to store the wrapped message API on mount via useEffect
  • Export the helpers from fidesui
  • Migrate the RTK query error middleware from Chakra's createChakraStandaloneToast to the new global ref

Code Changes

  • clients/fidesui/src/lib/globalMessageApi.ts - New module-level ref for the Ant Design message API
  • clients/fidesui/src/FidesUIProvider.tsx - Set global ref via useEffect after wrapping the message API
  • clients/fidesui/src/index.ts - Export getGlobalMessageApi and setGlobalMessageApi
  • clients/admin-ui/src/app/middleware.ts - Replace createChakraStandaloneToast with getGlobalMessageApi()?.error(...)

Steps to Confirm

  1. Start the admin-ui dev server (npm run dev in clients/admin-ui/)
  2. Verify the app loads without console errors related to the message API
  3. The middleware defaults to console_only mode, so RTK query errors should appear in the console (not as toasts) unless config is changed
  4. To test the toast path: set error_notification_mode to toast in the application config and trigger an API error

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Updates unreleased work already in Changelog, no new entry necessary
  • UX feedback:
    • No UX review needed
  • Followup issues:
    • Followup issues created
  • Database migrations:
    • No migrations
  • Documentation:
    • No documentation updates required

gilluminate and others added 2 commits March 18, 2026 13:48
Add a module-level ref that stores the themed Ant Design messageApi from
FidesUIProvider, making it accessible outside the React component tree.
Migrate the Redux RTK query error middleware from Chakra's
createStandaloneToast to the new global message ref.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 18, 2026

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

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
fides-plus-nightly Ignored Ignored Preview Mar 18, 2026 9:07pm
fides-privacy-center Ignored Ignored Mar 18, 2026 9:07pm

Request Review

- Accept null in setGlobalMessageApi for cleanup on provider unmount
- Add useEffect cleanup to null out stale ref when FidesUIProvider unmounts
- Remove setGlobalMessageApi from public exports (internal to fidesui)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gilluminate gilluminate requested a review from kruulik March 18, 2026 20:25
@gilluminate gilluminate marked this pull request as ready for review March 18, 2026 20:25
@gilluminate gilluminate requested a review from a team as a code owner March 18, 2026 20:25
@gilluminate gilluminate requested review from lucanovera and removed request for a team and lucanovera March 18, 2026 20:25
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 18, 2026

Greptile Summary

This PR introduces a global message API ref pattern to allow Ant Design's messageApi (configured with the app theme) to be accessed outside the React component tree, and uses it to migrate the RTK Query error middleware off of Chakra's standalone toast. The overall approach is clean and idiomatic — a module-level singleton ref, a useEffect in FidesUIProvider to keep it in sync, and optional-chaining in the middleware to degrade gracefully when the API hasn't been initialised yet.

Key changes:

  • New clients/fidesui/src/lib/globalMessageApi.ts with setGlobalMessageApi/getGlobalMessageApi helpers
  • FidesUIProvider registers the wrapped message API on mount and clears it on unmount
  • Only getGlobalMessageApi is exported publicly; setGlobalMessageApi stays internal — good encapsulation
  • Middleware now calls getGlobalMessageApi()?.error(...) with a corrected error message (fixes the previous "occured" typo)

One concern: The useEffect cleanup unconditionally calls setGlobalMessageApi(null). In environments with multiple FidesUIProvider instances (e.g., component-level test harnesses), unmounting one provider would null out the global ref even if another provider is still alive. Adding a simple identity guard before clearing would make this more robust.

Confidence Score: 4/5

  • This PR is safe to merge — the change is well-scoped and failures degrade gracefully to console logging.
  • The implementation is clean and the optional-chaining in the middleware ensures no errors are silently swallowed (console logging always fires). The one robustness concern — the cleanup not guarding against multi-provider scenarios — is unlikely to affect production (single provider) but could cause subtle test failures; addressing it would raise confidence to 5.
  • clients/fidesui/src/FidesUIProvider.tsx — the useEffect cleanup should guard against nulling a ref set by a different provider instance.

Important Files Changed

Filename Overview
clients/fidesui/src/lib/globalMessageApi.ts New module introducing a module-level singleton ref for the Ant Design MessageInstance; clean and minimal, but the unconditional null-on-cleanup approach could be problematic in multi-provider environments.
clients/fidesui/src/FidesUIProvider.tsx Wires up the global ref via useEffect; the cleanup always sets the ref to null regardless of whether another provider is still alive, which could cause silent failures in multi-provider scenarios (e.g. tests).
clients/admin-ui/src/app/middleware.ts Cleanly replaces the Chakra standalone toast with the new global message API; optional chaining ensures silent degradation when the API is unavailable, and printReduxError still fires so errors are never lost.
clients/fidesui/src/index.ts Correctly exports only getGlobalMessageApi (not setGlobalMessageApi), keeping the setter as an internal implementation detail of FidesUIProvider.

Last reviewed commit: "Clean up global mess..."

- Add identity check before nulling the global ref on unmount to avoid
  clobbering a ref set by a different FidesUIProvider instance

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

@kruulik kruulik left a comment

Choose a reason for hiding this comment

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

Makes sense and looks good!

@gilluminate gilluminate added this pull request to the merge queue Mar 18, 2026
Merged via the queue into main with commit e276cb8 Mar 18, 2026
48 of 49 checks passed
@gilluminate gilluminate deleted the gill/ENG-177/global-message-api-ref branch March 18, 2026 21:50
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