-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Astro.redirect JSDoc comment is wrong #11544
Description
Astro Info
Astro v4.12.2
Node v20.12.0
System Linux (x64)
Package Manager pnpm
Output hybrid
Adapter @astrojs/node
Integrations astro-icon
dev-only-pages
@astrojs/mdx
pagefind
@astrojs/sitemap
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
It's not a bug but rather bad information in inline documentation (JSDoc comment).
Context
I was using Astro.redirect in my project and I noticed the VSCode popup on hover. In addition of the method signature, we have a comment Redirect to another page (SSR Only).
Issue
This statement is wrong since Astro.redirect can also be used with statically rendered pages. For example, in my project the page that uses it is generated like this:
<!doctype html>
<title>Redirecting to: https://example.test/blog/posts</title>
<meta http-equiv="refresh" content="0;url=https://example.test/blog/posts" />
<meta name="robots" content="noindex" />
<link rel="canonical" href="https://example.test/blog/posts" />
<body>
<a href="https://example.test/blog/posts">
Redirecting from <code>/blog/posts/page/1/</code> to
<code>https://example.test/blog/posts</code>
</a>
</body>My concern
When an user sees this information, he may think that he cannot use Astro.redirect with output: 'static' or output: 'hybrid' when he can.
Reproduction
Since a reproduction link is mandatory, I reused another reproduction (don't pay attention to the title). On Stackblitz, you cannot see the popup with the comment so:
- Download the project
- Open it in VS Code
- Run
npm i - Open
src/pages/page/[page].astro - Hover
Astro.redirecton line 24
What's the expected result?
I think the comment in @types/astro.ts should be updated with something like:
-/** Redirect to another page (**SSR Only**)
+/** Redirect to another page
*
* Example usage:
* ```typescript
* if(!isLoggedIn) {
* return Astro.redirect('/login');
* }
* ```
*
-* [Astro reference](https://docs.astro.build/en/guides/server-side-rendering/)
+* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroredirect)
*/
redirect: AstroSharedContext['redirect'];Alternatively, we could write: Redirect to another page (**use `status` parameter with SSR only**) but it might be more useful to add this information in the documentation (I can submit a suggestion on astro/docs).
Link to Minimal Reproducible Example
Participation
- I am willing to submit a pull request for this issue.
