feat(shopify-app-remix): allow overriding linkComponent on AppProvider#3215
Open
SinhSinhAn wants to merge 1 commit into
Open
feat(shopify-app-remix): allow overriding linkComponent on AppProvider#3215SinhSinhAn wants to merge 1 commit into
SinhSinhAn wants to merge 1 commit into
Conversation
`AppProvider` previously hardcoded `RemixPolarisLink` as the link
component passed to the underlying Polaris provider. Apps that wanted
to drive active-route styling with `NavLink`, or use any other custom
Remix link wrapper, had no way to do it without giving up the Shopify
AppProvider entirely.
Add an optional `linkComponent` prop that forwards through to Polaris,
keeping `RemixPolarisLink` as the default so the change is fully
backwards-compatible.
```tsx
import {NavLink} from '@remix-run/react';
<AppProvider apiKey={apiKey} linkComponent={NavLink}>
<Outlet />
</AppProvider>
```
Closes Shopify/shopify-app-template-remix#486
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.
What
Adds an optional
linkComponentprop to<AppProvider>so apps can override the defaultRemixPolarisLink. When omitted, behaviour is identical to today (existingRemixPolarisLinkis used), so this is a non-breaking minor.Why
Closes Shopify/shopify-app-template-remix#486. The issue author (@blanklob) wants Polaris components that render links to use Remix's
NavLink(or any custom wrapper) so they can pick up navigation state likeisActive. Until nowAppProviderOmit-strippedlinkComponentfrom its public prop surface and hardcodedRemixPolarisLink, which left no escape hatch short of forking the provider.This mirrors how
i18nis already exposed: omit the Polaris prop, then re-declare a typed wrapper that defaults to the in-package value. The change is a single destructured default plus a new JSDoc-documented prop, so reviewers can audit it in one read.What changed
packages/apps/shopify-app-remix/src/react/components/AppProvider/AppProvider.tsxlinkComponent?: PolarisAppProviderProps['linkComponent']toAppProviderPropswith JSDoc. Destructured withRemixPolarisLinkas the default. Forwarded to<PolarisAppProvider>.packages/apps/shopify-app-remix/src/react/components/AppProvider/__tests__/AppProvider.test.tsxRemixPolarisLink)..changeset/app-provider-custom-link-component.md@shopify/shopify-app-remixwith a usage snippet.Test plan
AppProvidertests still pass (npx jest --testPathPatterns AppProvider)linkComponentreaches<PolarisAppProvider>)linkComponent: RemixPolarisLinkassertion in the existing i18n test continues to pass unchanged)Notes
customLink, butlinkComponentmatches the existing Polaris convention (and is the prop we forward to anyway), so I went with that to avoid two names for the same thing. Happy to rename if maintainers prefer.NavLink, which is the headline use case from the issue's Loom.