Skip to content

Commit

Permalink
Log an error for duplicate namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdixon committed Nov 21, 2024
1 parent 4cfab7e commit 0ba0725
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/hydrogen/src/pagination/Pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export function Pagination<NodesType>({
}: PaginationProps<NodesType>): ReturnType<FC> {
const transition = useNavigation();
const isLoading = transition.state === 'loading';
const location = useLocation();

const {
endCursor,
hasNextPage,
Expand All @@ -120,7 +122,19 @@ export function Pagination<NodesType>({
previousPageUrl,
startCursor,
} = usePagination<NodesType>(connection, namespace);
const location = useLocation();

// Throw error for duplicate namespace
if (
location.state?.pagination &&
namespace in location.state.pagination &&
transition.state === 'idle'
) {
console.warn(
`Warning: Multiple <Pagination /> components are using the same namespace${
namespace ? `"${namespace}"` : ''
}. This will cause state conflicts. Each <Pagination /> component should have a unique namespace.`,
);
}

const state = useMemo(
() => ({
Expand Down

0 comments on commit 0ba0725

Please sign in to comment.