Skip to content

♻️ refactor(HostedCart): fix hooks order, extract domain constant and url resolver#772

Merged
acasazza merged 1 commit into
v5.0.0from
feat/771-hosted-cart-refactor
May 22, 2026
Merged

♻️ refactor(HostedCart): fix hooks order, extract domain constant and url resolver#772
acasazza merged 1 commit into
v5.0.0from
feat/771-hosted-cart-refactor

Conversation

@acasazza
Copy link
Copy Markdown
Member

Summary

Refactor HostedCart.tsx to fix bugs and align with the patterns established in CheckoutLink and CartLink.

Changes

  • Fix Rules of Hooks violationuseContext(OrderContext) and useContext(OrderStorageContext) were called after an early return null, violating React's rules of hooks. All hooks now sit above the early return.
  • Extract DEFAULT_DOMAIN constant — removes the two hardcoded 'commercelayer.io' strings
  • Extract resolveCartUrl() helper — deduplicates the getOrganizationConfig + getApplicationLink logic that was repeated in both setOrder and the main useEffect
  • Fix missing customDomain — the direct getApplicationLink call inside useEffect was not forwarding the prop; now it goes through resolveCartUrl
  • Wrap onMessage with useCallback and fix the iframe resizer useEffect dep array ([onMessage] instead of the invalid [ref.current != null])
  • Update JSDoc — replace deprecated <OrderContainer> with <Order>
  • Remove commented-out code// zIndex lines in default styles

Closes #771

… url resolver, use useCallback

- Move all useContext calls above early return to fix Rules of Hooks violation
- Extract DEFAULT_DOMAIN constant to remove hardcoded duplicate strings
- Extract resolveCartUrl() helper to deduplicate getOrganizationConfig + getApplicationLink logic
- Fix missing customDomain in the useEffect getApplicationLink call
- Wrap onMessage with useCallback and fix useEffect dependency ([onMessage] instead of [ref.current != null])
- Update JSDoc: OrderContainer → Order
- Remove commented-out zIndex lines from default styles

Closes #771

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@acasazza acasazza added components Components package refactor labels May 21, 2026
@acasazza acasazza merged commit a3399ac into v5.0.0 May 22, 2026
2 checks passed
@acasazza acasazza deleted the feat/771-hosted-cart-refactor branch May 22, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

components Components package refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant