Skip to content

fix: show+hide architecture update#7492

Open
thiessenp-cds wants to merge 24 commits into
mainfrom
show-hide-event
Open

fix: show+hide architecture update#7492
thiessenp-cds wants to merge 24 commits into
mainfrom
show-hide-event

Conversation

@thiessenp-cds

@thiessenp-cds thiessenp-cds commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary | Résumé

This PR moves show+hide to use an event-driven approach that is more performant and maintainable. It separates concerns cleanly and makes the visibility logic testable in isolation. (though UI test would also help -- potential followup PR)

Summary of how the new implementation works:

  1. On form mount, dependency graph (dependent elements) is built showing which elements depend on which
  2. Initial visibility is computed for all elements and cached in a Map
  3. When form values change:
    • System detects which choice-based elements (radio/checkbox/select) changed
    • Filters to only those with dependents (using dependency graph)
    • Recomputes visibility only for affected elements
    • Fires custom event for extensibility
  4. Components simply check the cached visibility map (fast lookup)

Additionally visibilityMap has been moved out of GCFormsContext into its own dedicated VisibilityContext. This scopes re-renders from visibility changes to only components that consume useVisibilityContext. Previously, any change to visibilityMap would trigger a re-render in every component subscribed to useGCFormsContext.

Note:
A follow up PR is needed to add (back?) accessibility semantics (aria-controls + aria-expanded) for show+hide. These semantics are just WCAG related they don't actually do much to help screen reader users. An announcement should also be used, or a similar strategy.

@thiessenp-cds thiessenp-cds marked this pull request as draft July 14, 2026 15:29
@github-actions github-actions Bot added the !! Package Update !! Please ensure packages are built and pushed label Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@thiessenp-cds thiessenp-cds changed the title fix: improve visibility related functions for show+hide update fix: visibility update to help show+hide Jul 14, 2026
@thiessenp-cds thiessenp-cds changed the title fix: visibility update to help show+hide fix: show+hide architecture update Jul 14, 2026
@thiessenp-cds thiessenp-cds linked an issue Jul 14, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors show/hide visibility evaluation to a more incremental, event-driven approach: it precomputes element dependency relationships, caches visibility results, and updates only impacted elements when relevant form values change. It also introduces a custom event (form-values-changed) so UI components can update visibility without re-running full visibility checks.

Changes:

  • Added dependency-graph + cached visibility computation APIs in @gcforms/core (compute-all + recompute-affected).
  • Updated the form context and ConditionalWrapper to use cached visibility and a custom event to propagate visibility changes.
  • Added Vitest coverage for the new visibility helper functions and bumped core version + changelog.

Reviewed changes

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

Show a summary per file
File Description
packages/core/src/visibility.ts Adds dependency graph + cached visibility map computation and incremental recomputation helpers.
packages/core/src/index.ts Re-exports the new visibility APIs/types from core.
packages/core/package.json Bumps @gcforms/core version to 2.2.15.
packages/core/CHANGELOG.md Documents the visibility refactor in the changelog.
lib/vitests/visibility.test.ts Adds unit tests covering new visibility helper behavior.
lib/hooks/useGCFormContext.tsx Computes and maintains a visibility map and fires an event describing visibility diffs on value changes.
lib/hooks/useCustomEvent.tsx Adds form-values-changed key and fixes event listener removal behavior.
components/clientComponents/forms/ConditionalWrapper/ConditionalWrapper.tsx Switches to event-driven local visibility updates via the cached visibility map.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/hooks/useCustomEvent.tsx
Comment thread lib/hooks/useGCFormContext.tsx
Comment thread lib/hooks/useGCFormContext.tsx
Comment thread packages/core/src/visibility.ts
Comment thread components/clientComponents/forms/ConditionalWrapper/ConditionalWrapper.tsx Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread lib/hooks/useCustomEvent.tsx
Comment thread packages/core/src/visibility.ts
Comment thread lib/hooks/useGCFormContext.tsx
thiessenp-cds and others added 2 commits July 15, 2026 14:48
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread packages/core/src/visibility.ts Outdated
Comment thread packages/core/src/visibility.ts
Comment thread packages/core/src/visibility.ts Outdated
Comment thread lib/hooks/useGCFormContext.tsx Outdated
Comment thread packages/core/src/visibility.ts Outdated
thiessenp-cds and others added 2 commits July 15, 2026 15:05
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@thiessenp-cds thiessenp-cds marked this pull request as ready for review July 15, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!! Package Update !! Please ensure packages are built and pushed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show+Hide architecture update

2 participants