-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(sistent): honour the contents prop in IntraPage #8003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ayush-1812
wants to merge
1
commit into
layer5io:master
Choose a base branch
from
Ayush-1812:fix/sistent-intra-page-contents
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+19
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 13140
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 17752
🌐 Web query:
Gatsby Link componenttoprop SSR href behavior relative URL fragment official documentation💡 Result:
The official Gatsby documentation recommends using the standard HTML
<a>element for fragment links (e.g.,<a href="#section">) and internal links that do not target a specific page handled by Gatsby [1][2]. While the Gatsby<Link>component is designed for internal navigation between Gatsby pages, it is not intended for anchor/fragment links on the same page or external URLs [3][1][4]. When using the<Link>component, thetoprop is primarily used for defining the pathname of internal pages [3][1]. If you attempt to use the<Link>component with a fragment (e.g.,<Link to="/page#fragment">), behavior can be inconsistent regarding Server-Side Rendering (SSR) and client-side routing. Community and developer discussions emphasize that the<Link>component's internal logic processes thetoprop to determine if a route is internal and to apply path prefixes [3][5]. Because of this, it is considered a best practice to avoid using<Link>for anchor/fragment navigation to prevent potential routing issues, hydration mismatches, or unexpected back-button behavior [2].Citations:
🌐 Web query:
site:github.com/gatsbyjs/gatsby v5.16.1 packages/gatsby-link/src/index.js Link href to prop💡 Result:
In the Gatsby
Linkcomponent (provided bygatsby-link), thetoprop is used instead of the standard HTMLhrefattribute to define the navigation target [1][2]. In the source code forgatsby-link(including version 5.16.1), theLinkcomponent is designed specifically for internal navigation within a Gatsby site [3][4]. When you provide atoprop, Gatsby's internal logic processes the path—applying prefixes if necessary—and then uses it to manage navigation through the underlying router (historically Reach Router) [3]. Key points regarding the use oftoversushref: 1. Usage: Always use thetoprop for internal Gatsby links [1][2]. If you need to link to an external site or a page not handled by your Gatsby application, you should use a standard HTML<a>element with anhrefattribute instead [1][4][2]. 2. Implementation: Thegatsby-linkcomponent does not natively expose anhrefprop in its API [4][5]. If you attempt to pass anhrefto theLinkcomponent, it may not function as expected because the component is not designed to treat it as a navigation target [6]. 3. Customization: If you need to manipulate the underlying<a>tag (for example, to add specific classes or attributes), you can use thegetPropsprop, which allows you to pass a function that returns props to be applied to the rendered anchor element [7]. For further details on the properties accepted by theLinkcomponent, you can refer to the official Gatsby documentation on built-in components [1].Citations:
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 11989
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 370
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 6526
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 2808
🌐 Web query:
@gatsbyjs/reach-router resolve relative path hash implementation💡 Result:
The
@gatsbyjs/reach-routerlibrary uses a custom utility function, located at@gatsbyjs/reach-router/lib/utils, to resolve relative paths [1]. This resolution logic is specifically designed to handle navigation within a client-side routing environment where trailing slashes can be ambiguous [1][2]. Regarding the handling of hash fragments (#) and relative paths: 1. Hash Fragment Handling: The standard resolve logic in reach-router is generally configured to treat paths starting with a hash (#) as absolute relative to the current URL, meaning it preserves them rather than attempting to resolve them as part of the directory structure [3]. In some custom implementations, developers have explicitly modified the resolve function to check for the presence of a hash (e.g., if(startsWith(to, "/") || startsWith(to, "#")) { return to; }) to ensure these links are correctly ignored by the relative path resolution logic [3]. 2. Relative Path Resolution Logic: The router treats relative links by essentially assuming the current page path ends with a trailing slash [2]. This ensures that navigating to a relative path like./baz from /foo/bar resolves to /foo/bar/baz rather than /foo/baz [2]. Because of this design, Gatsby’s own implementation of the resolve function has historically faced issues where it sometimes incorrectly strips trailing slashes or interacts unexpectedly with query parameters, necessitating workarounds in various Gatsby versions [1][4]. If you are encountering issues with hash links in relative navigation, the common approach is to verify if your version of the resolve utility treats hashes as special cases or to perform the resolution manually using the@gatsbyjs/reach-router/lib/utilsresolve function, ensuring your logic handles the hash fragment independently before or after path resolution [1][5].Citations:
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 344
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 270
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 296
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 153
🏁 Script executed:
Repository: layer5io/layer5
Length of output: 22258
Prevent
nullpathnames in explicit-content links.When
contentsis non-empty, the first render passesto="null#Installation"becauseintapathis initialized tonulland set only inuseEffect. Gatsby rewrites this local relative path to a pathname containingnull, so the link does not target the current-page fragment in SSR or the initial client render. Use<a href={x.link}>for same-page fragments, or defer rendering untilintapathis set.🤖 Prompt for AI Agents