Skip to content

Astro.redirect JSDoc comment is wrong #11544

@ArmandPhilippot

Description

@ArmandPhilippot

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).

Screenshot of the JSDoc comment for Astro.redirect method in VSCode

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:

  1. Download the project
  2. Open it in VS Code
  3. Run npm i
  4. Open src/pages/page/[page].astro
  5. Hover Astro.redirect on 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

https://stackblitz.com/edit/astro-check-imported-module-top-level-return?file=src%2Fpages%2Fpage%2F[page].astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions