fix: show+hide architecture update#7492
Open
thiessenp-cds wants to merge 24 commits into
Open
Conversation
Contributor
🧪 Review environmenthttps://pmbxcmt23xm2a5uctuqiqbyaei0kgcoo.lambda-url.ca-central-1.on.aws/ |
Contributor
There was a problem hiding this comment.
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
ConditionalWrapperto 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Additionally
visibilityMaphas been moved out ofGCFormsContextinto its own dedicatedVisibilityContext. This scopes re-renders from visibility changes to only components that consumeuseVisibilityContext. Previously, any change tovisibilityMapwould trigger a re-render in every component subscribed touseGCFormsContext.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.