Skip to content

Conversation

@LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Mar 17, 2025

Description

TL;DR: Improve the JSDoc comments of all React hooks and add additional Next.js examples to some of them. Modify the MDX output so that it can be used for rendering on clerk.com/docs

  • Format Typedoc MDX output with Prettier
  • Remove headings from certain Typedoc files
  • Add support for replacing links in Typedoc output
  • Remove type signature titles and type parameter tables from Typedoc output
  • Use {@include} JSDoc comments to add additional examples

Fixes ECO-508
Fixes ECO-424

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@vercel
Copy link

vercel bot commented Mar 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 10:09am

@changeset-bot
Copy link

changeset-bot bot commented Mar 17, 2025

🦋 Changeset detected

Latest commit: f108423

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@clerk/shared Patch
@clerk/clerk-react Patch
@clerk/types Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/clerk-expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-start Patch
@clerk/testing Patch
@clerk/vue Patch
@clerk/localizations Patch
@clerk/themes Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

/**
* A list of files where we want to remove any headings
*/
const FILES_WITHOUT_HEADINGS = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of the files only contain the contents of a single interface.

For example:

# Parameters

Table goes here

So since I want to use the table contents as a partial/include somewhere else I need to get rid off the heading. But since I don't want to remove headings everywhere I'm removing them only from the files I want to use in such way.

/**
* An array of tuples where the first element is the file name and the second element is the new path.
*/
const LINK_REPLACEMENTS = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sometimes there are relative links like [PaginatedResponse](../types/paginated-response.mdx) in the files. The link to the also generated file through typedoc. But we already have that page manually created and want to link to it. So this replaces relative links with links to our existing docs.

@@ -0,0 +1,43 @@
<!-- #region nextjs-01 -->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to use the https://typedoc.org/documents/Tags.__include_.html flag the examples should be in the root of the package, so that relative links work for the files inside dist. Because it has to be resolved from dist to that folder.

*
* The following example demonstrates how to use the `useAuth()` hook to access the current auth state, like whether the user is signed in or not. It also includes a basic example for using the `getToken()` method to retrieve a session token for fetching data from an external resource.
*
* <Tabs items='React,Next.js'>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you use these MDX components (they are not resolved, just passed along) in such way, they won't be rendered in IntelliSense

* ```
*/
export const useOrganization: UseOrganization = params => {
export function useOrganization<T extends UseOrganizationParams>(params?: T): UseOrganizationReturn<T> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No behavior change, just removing a type alias and explicitly making it a function (sometimes typedoc can be tripped up by using a const for a function)

/**
* @interface
*/
export type UseOrganizationParams = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inside useOrganization and useOrganizationList you'll notice that I added export to the params and return types. I need those to be accessible to typedoc, which requires you to export them.

Since we don't re-export them from src/react/hooks/index.ts file they won't surface to the users.

{
"$schema": "https://typedoc.org/schema.json",
"entryPoints": ["./src/index.ts", "./src/react/index.ts", "./src/react/types.ts"],
"entryPoints": ["./src/index.ts", "./src/react/types.ts", "./src/react/hooks/*.{ts,tsx}"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed access to the exported interfaces inside useOrganization/useOrganizationList but didn't want to change the public API. So we're looking at the hooks individually now.

@LekoArts LekoArts marked this pull request as ready for review March 17, 2025 11:47
@@ -1,2 +1,3 @@
/*/
!/src/
!/examples/
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename to doc-examples, or simply docs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we can choose whatever name we want really. I'd probably pick docs then

*
* The following example uses the `useSession()` hook to access the `Session` object, which has the `lastActiveAt` property. The `lastActiveAt` property is a `Date` object used to show the time the session was last active.
*
* <Tabs items='React,Next.js'>
Copy link
Member

Choose a reason for hiding this comment

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

Could this be items='react,next' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In our existing docs we use <Tabs items={['React', 'Next.js'}]>. After the transformation to add the curly and square brackets it needs to be the same, hence it's written like that

@LekoArts LekoArts merged commit 7524943 into main Mar 18, 2025
30 checks passed
@LekoArts LekoArts deleted the lekoarts/eco-508-finish-up-last-missing-pieces-for-react-hooks branch March 18, 2025 10:45
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.

4 participants