Skip to content

refactor: migrate LayoutsContext to query module pattern#18069

Closed
adamhaeger wants to merge 3 commits intorefactor/entrypoint-to-loaderfrom
refactor/layout-query
Closed

refactor: migrate LayoutsContext to query module pattern#18069
adamhaeger wants to merge 3 commits intorefactor/entrypoint-to-loaderfrom
refactor/layout-query

Conversation

@adamhaeger
Copy link
Copy Markdown
Contributor

Description

Migrates layout data fetching from the legacy LayoutsContext (context + provider pattern) to the nextsrc query module pattern at core/queries/layouts/.

What changed:

  • New LayoutApi static class in core/api-client/layout.api.ts — replaces fetchLayouts/fetchLayoutsForInstance from useAppQueries
  • New query module core/queries/layouts/ with layoutQueryDef(), typed query keys, and public hooks (useLayouts, useLayoutLookups, useLayoutLookupsLax, useHiddenLayoutsExpressions, useExpandedWidthLayouts)
  • ~80 consumer files updated to import hooks from the new module instead of LayoutsContext
  • LayoutsContext.tsx reduced from 190 lines to ~50 lines — now a thin loading gate (blocks rendering until layout query resolves, no context)
  • Processing logic (processLayouts, removeDuplicateComponentIds, addLikertItemToLayout) moved into the query module's queryFn
  • Layout lookups computed via module-level cache to avoid redundant makeLayoutLookups calls across consumers

Backward compatibility:

  • LayoutsProvider remains in FormContext provider tree as a loading gate (validation layer requires layout data before rendering)
  • layoutQueryDef accepts optional fetch functions parameter — hooks pass useAppQueries() functions preserving test mock infrastructure
  • LayoutContextValue type alias preserved for e2e tests and devtools

Verification

  • Related issues are connected (if applicable)
  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Extract layout data fetching from context/provider pattern into
a dedicated query module at core/queries/layouts/.

- Create LayoutApi static class in core/api-client/
- Create layout query module with queryOptions, query keys, and hooks
- Migrate ~80 consumer files to import from new module
- Reduce LayoutsContext.tsx to a thin loading gate (no context)
- Processing logic (cleanLayout, dedup, likert) moved to query module

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added skip-releasenotes Issues that do not make sense to list in our release notes skip-second-approval Pull requests that only need one approval from a reviewer. labels Mar 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 6, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5223c8e2-7e67-4555-b14b-afdf33be671a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/layout-query

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

🔍 Lighthouse Report

URL Performance LCP CLS TBT Link to Report
/ttd/component-library/ 25/100 🟢 31387 ms 🟢 0 🟢 7471 ms 🔴 Report

@adamhaeger adamhaeger closed this Mar 9, 2026
@adamhaeger adamhaeger deleted the refactor/layout-query branch March 9, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-releasenotes Issues that do not make sense to list in our release notes skip-second-approval Pull requests that only need one approval from a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant