Skip to content

Components: Providers

Small client providers mounted in the root layout: text direction (RTL) and scroll restoration.

Generated from apps/theme/src/components/providers/: 2 files, 2 components. Import a component through the @/components/… path shown, so a fork can override it in src/custom/.

@/components/providers/direction-provider

apps/theme/src/components/providers/direction-provider.tsx client component

<DirectionProvider>

Client wrapper around Radix's DirectionProvider. The bare Radix package has no "use client" directive, so importing it straight into the server-component root layout makes its React.createContext call run on the server and crash the build. This shim establishes the client boundary so Radix components (and our useDirection() consumers) read the active dir.

Every Radix import in this app now goes through the radix-ui umbrella, including this one. That is deliberate and load-bearing: the app used to import some primitives from the umbrella and others from scoped @radix-ui/react-* packages, which meant the scoped ones had to be pinned to exactly what the umbrella pinned. If they ever drifted apart — as they did on every umbrella bump — npm installed a SECOND copy, giving two DirectionContexts, and this provider silently stopped reaching Popover: RTL would just quietly stop flipping align/side, with no error and nothing in CI to catch it. Same hazard for Sheet vs Popover sharing a dismissable-layer stack.

One import source means one copy of every primitive, so bumping radix-ui is now a one-line change. Keep it that way: do not reintroduce a scoped @radix-ui/* dependency.

PropTypeDescription
dir"ltr" | "rtl"
childrenReact.ReactNode

@/components/providers/scroll-to-top

apps/theme/src/components/providers/scroll-to-top.tsx client component

<ScrollToTop>

Resets the window scroll position to the top on every forward soft navigation. Next's App Router is supposed to do this on <Link> navigation, but with this app's streamed/PPR routes (the page commits a short loading.tsx shell, then grows as content streams in) the automatic scroll-to-top lands before the new page has its final height and the previous page's scroll offset is visibly preserved — the user lands mid-page on the freshly opened route. Forcing the reset on each pathname change fixes it.

Two deliberate details:

  • behavior: "instant" overrides the global scroll-behavior: smooth (set in globals.css for the PDP "#reviews" anchor) so navigation jumps immediately instead of animating.
  • Back/forward navigations are skipped (guarded by the popstate flag) so the browser's / Next's scroll restoration for history moves is left intact — we only reset on genuine forward navigations.

usePathname (not useSearchParams) is used so this needs no Suspense boundary; hash links (#reviews) don't change the pathname, so they keep their smooth in-page scroll.

No props.