refactor(gatsby-node): simplify page creation logic and remove redundant redirects#7634
Open
Abmarne wants to merge 2 commits intolayer5io:masterfrom
Open
refactor(gatsby-node): simplify page creation logic and remove redundant redirects#7634Abmarne wants to merge 2 commits intolayer5io:masterfrom
Abmarne wants to merge 2 commits intolayer5io:masterfrom
Conversation
…ant redirects - Removed creation of redundant redirects for page paths during CI builds ref-actor Simplified(gatsby-node): simplify page creation and remove lite mode redirects env CreatePage wrapper to directly call createPage - Removed legacy lite mode redirects and related placeholder pages - Simplified env- Retained all page templates andCreate GraphQL queries without modification -Page function to directly call createPage without redirects Kept collection filtering and pagination- Removed redundant slug slash redirects in CI environment logic intact - Kept existing GraphQL queries and page creation- No logic intact - Maintained excluded collections handling and functional changes to node field creation or schema customization full site build flag - Ensured dev - Improved code clarity 404 page caching and webpack config remain unchanged by removing unnecessary redirect side effects Signed-off-by: Abmarne <abhirajmarne11@gmail.com>
Contributor
|
Preview deployment for PR #7634 removed. This PR preview was automatically pruned because we keep only the 6 most recently updated previews on GitHub Pages to stay within deployment size limits. If needed, push a new commit to this PR to generate a fresh preview. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Removes CI-only redirect creation in gatsby-node.js that conflicted with the site’s trailingSlash: "never" setting, eliminating warnings about paths matching both a page and a redirect.
Changes:
- Deleted CI-specific trailing-slash redirect logic in
envCreatePage. - Simplified
envCreatePageto directly callcreatePagewith the provided props.
Comment on lines
56
to
58
| const envCreatePage = (props) => { | ||
| const pageProps = { | ||
| ...props, | ||
| }; | ||
|
|
||
| if (process.env.CI === "true") { | ||
| const { path } = pageProps; | ||
| createRedirect({ | ||
| fromPath: `/${path}/`, | ||
| toPath: `/${path}`, | ||
| redirectInBrowser: true, | ||
| isPermanent: true, | ||
| }); | ||
| } | ||
|
|
||
| return createPage(pageProps); | ||
| return createPage(props); | ||
| }; |
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.
Fix: #7606
The problem was in gatsby-node.js where the code was creating redirects from paths with trailing slashes to paths without trailing slashes when running in CI mode. This conflicted with the
trailingSlash: "never"configuration in gatsby-config.jsWhat I Changed
I removed the redirect creation logic in the
envCreatePagefunction (lines 56-72) that was causing the conflicts. The code was attempting to create redirects like:/learn/learning-paths/mastering-kubernetes-for-engineers//learn/learning-paths/mastering-kubernetes-for-engineersSince your Gatsby configuration already specifies
trailingSlash: "never", these redirects were redundant and caused warnings because Gatsby was creating both the pages and the redirects for the same paths.Result
The build should now be clean without the warnings about routes matching both page and redirect. The pages will continue to work correctly without trailing slashes as configured in your gatsby-config.js.
The fix has been applied successfully. The build warnings about conflicting page and redirect routes should now be resolved. The change removes the redundant redirect creation that was conflicting with your
trailingSlash: "never"configuration.