Skip to content

feat(sistent): refactor pagination to use dynamic GraphQL routing and remove content.js#7587

Open
rishiraj38 wants to merge 5 commits intolayer5io:masterfrom
rishiraj38:feat/sistent-dynamic-pagination
Open

feat(sistent): refactor pagination to use dynamic GraphQL routing and remove content.js#7587
rishiraj38 wants to merge 5 commits intolayer5io:masterfrom
rishiraj38:feat/sistent-dynamic-pagination

Conversation

@rishiraj38
Copy link
Copy Markdown
Member

Description

This PR fixes #7585 by replacing the hardcoded content.js array with a dynamic GraphQL useStaticQuery to automatically handle Sistent pagination.

This ensures that any newly added component or tab (overview, guidance, code) is instantly indexed and correctly ordered in the pagination workflow without requiring developers to manually update boilerplate arrays.

Changes Made

  • Deleted src/components/SistentNavigation/content.js to remove technical debt.
  • Updated SistentPagination to dynamically fetch all Sistent MDX nodes.
  • Implemented JS-filtering to ignore drafts (published: false), while successfully pulling grouped tabs (overview -> guidance -> code) belonging to published components.
  • Enforced a strict algebraic sort via componentSlug to guarantee proper alphabetical sequencing.

Signed commits

  • Yes, I signed my commits.

Signed-off-by: Rishi Raj <rishiraj438gt@gmail.com>
Copy link
Copy Markdown
Contributor

@YASHMAHAKAL YASHMAHAKAL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @rishiraj38

@arjunmehta-git
Copy link
Copy Markdown

Solid refactoring, @rishiraj38. Replacing the hardcoded content.js array with a dynamic useStaticQuery GraphQL call is the right long-term approach — it eliminates an entire class of "forgot to update the nav" bugs when new Sistent components are added.

One coordination item to flag: #7582 (Card component docs) added entries to content.js as part of its review cycle. Since this PR deletes content.js entirely, these two PRs are on a collision course. Whoever merges second will need to make sure the Card entries are reflected in the new dynamic query behavior. Please coordinate with @abhay1999 to confirm the Card MDX pages will be picked up correctly by the new GraphQL routing before either PR merges.

Also worth confirming:

  • The draft filtering (published: false) works as expected and doesn't accidentally hide any currently-published components
  • The alphabetical sort via componentSlug produces the same ordering as the old content.js array (a quick side-by-side comparison would be reassuring)

Good work eliminating that technical debt.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR refactors Sistent pagination to derive component/tab routes dynamically from Sistent MDX nodes via Gatsby useStaticQuery, removing the large manually-maintained content.js list.

Changes:

  • Replace static content.js pagination data with a GraphQL allMdx query + derived route list.
  • Filter pagination to only include pages for components whose overview page is published: true, and order tabs (overview → guidance → code).
  • Remove src/components/SistentNavigation/content.js and inline remaining stable routes in pagination.js.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
src/components/SistentNavigation/pagination.js Adds useStaticQuery and runtime route derivation/sorting for pagination, plus a small stable-route prefix list.
src/components/SistentNavigation/content.js Deletes the hardcoded pagination array previously used by Sistent pagination.

Comment on lines +83 to +91
const fullContentArray = [...STABLE_ROUTES, ...dynamicRoutes];

useEffect(() => {
const path = window.location.pathname;
const index = content.findIndex((x) => x.link === path);
// Handle trajectory slashes
const cleanPath = path.endsWith("/") && path.length > 1 ? path.slice(0, -1) : path;
const index = fullContentArray.findIndex((x) => x.link === cleanPath);
setCurrentPage(index);
}, []);
}, [fullContentArray]);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fullContentArray is rebuilt on every render, so the effect will re-run on every render as well. Even if setCurrentPage bails out when the value is unchanged, this still adds unnecessary work and can become noticeable as the MDX node count grows. Suggestion (mandatory): memoize dynamicRoutes and fullContentArray with useMemo (based on data.allMdx.nodes) so the dependency is stable, or change the effect dependency to something stable (e.g., memoized array + pathname).

Copilot uses AI. Check for mistakes.
);
});

const fullContentArray = [...STABLE_ROUTES, ...dynamicRoutes];
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging STABLE_ROUTES and dynamicRoutes without de-duplication can produce duplicate entries if any of the “stable” pages are also present in the MDX collection (same link). This can break findIndex (it will pick the first match) and can cause incorrect previous/next navigation due to duplicated items in the array. Suggestion (mandatory): de-duplicate by link when building fullContentArray (e.g., build a map/set keyed by link and preserve the desired precedence/order).

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +10
{ link: "/projects/sistent/getting-started/about", text: "About" },
{ link: "/projects/sistent/getting-started/installation", text: "Installation" },
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items in fullContentArray have inconsistent shapes: stable routes use text, while dynamic routes use name (and include extra fields). This makes the merged array harder to reason about and increases the chance of future regressions if UI later starts using the label field. Suggestion (mandatory): normalize to a single label key (e.g., text) across both stable and dynamic routes before merging.

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +72
.map((node) => ({
componentSlug: node.frontmatter.component,
name: node.frontmatter.name || node.frontmatter.component,
link: node.fields.slug,
pageType: node.fields.pageType,
}))
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items in fullContentArray have inconsistent shapes: stable routes use text, while dynamic routes use name (and include extra fields). This makes the merged array harder to reason about and increases the chance of future regressions if UI later starts using the label field. Suggestion (mandatory): normalize to a single label key (e.g., text) across both stable and dynamic routes before merging.

Copilot uses AI. Check for mistakes.
useEffect(() => {
const path = window.location.pathname;
const index = content.findIndex((x) => x.link === path);
// Handle trajectory slashes
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says 'trajectory slashes' but it looks like this is handling trailing slashes. Consider correcting the wording for clarity.

Copilot uses AI. Check for mistakes.
Comment on lines 95 to +105
{currentPage > 0 ? (
<Button $secondary $url={content[currentPage - 1]?.link}>
<Button $secondary $url={fullContentArray[currentPage - 1]?.link}>
&larr; Previous
</Button>
) : null}
) : <div />}

{currentPage < content.length - 1 ? (
<Button $primary $url={content[currentPage + 1]?.link}>
{currentPage !== -1 && currentPage < fullContentArray.length - 1 ? (
<Button $primary $url={fullContentArray[currentPage + 1]?.link}>
Next &rarr;
</Button>
) : null}
) : <div />}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rendering empty <div /> placeholders can add extra non-semantic nodes to the DOM; depending on styling and assistive tech, these can be confusing or at least unnecessary noise. Suggestion (optional): either render null and handle spacing with CSS in PaginationWrapper, or mark placeholders as presentational (e.g., add aria-hidden="true" and ensure they don’t get focus).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Sistent] Make Sistent navigation and pagination dynamic from MDX content

5 participants