Skip to content

Refactor async usage #3419

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
"noControlCharactersInRegex": "warn",
"noPrototypeBuiltins": "warn",
"noAssignInExpressions": "warn",
"noArrayIndexKey": "warn"
"noArrayIndexKey": "warn",
"useAwait": "error"
},
"a11y": {
"useSemanticElements": "warn",
Expand Down Expand Up @@ -152,6 +153,13 @@
"include": ["*.test.ts", "packages/gitbook/tests/**/*"],
"javascript": {
"globals": ["Bun"]
},
"linter": {
"rules": {
"suspicious": {
"useAwait": "off"
}
}
}
},
{
Expand All @@ -170,6 +178,16 @@
"ExportedHandler"
]
}
},
{
"include": ["packages/gitbook/openNext/**/*"],
"linter": {
"rules": {
"suspicious": {
"useAwait": "off"
}
}
}
}
]
}
8 changes: 4 additions & 4 deletions packages/gitbook/e2e/internal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ const testCases: TestsCase[] = [
name: 'Text page',
url: 'text-page.md',
screenshot: false,
run: async (_page, response) => {
run: (_page, response) => {
expect(response?.status()).toBe(200);
expect(response?.headers()['content-type']).toContain('text/markdown');
},
Expand All @@ -441,7 +441,7 @@ const testCases: TestsCase[] = [
name: 'llms.txt',
url: 'llms.txt',
screenshot: false,
run: async (_page, response) => {
run: (_page, response) => {
expect(response?.status()).toBe(200);
expect(response?.headers()['content-type']).toContain('text/markdown');
},
Expand All @@ -457,7 +457,7 @@ const testCases: TestsCase[] = [
name: 'llms-full.txt',
url: 'llms-full.txt',
screenshot: false,
run: async (_page, response) => {
run: (_page, response) => {
expect(response?.status()).toBe(200);
expect(response?.headers()['content-type']).toContain('text/markdown');
},
Expand All @@ -473,7 +473,7 @@ const testCases: TestsCase[] = [
name: 'blocks.md',
url: 'blocks.md',
screenshot: false,
run: async (_page, response) => {
run: (_page, response) => {
expect(response?.status()).toBe(200);
expect(response?.headers()['content-type']).toContain('text/markdown');
},
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/e2e/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export async function waitForCookiesDialog(page: Page) {
await expect(dialog).toBeVisible();
}

export async function waitForNotFound(_page: Page, response: Response | null) {
export function waitForNotFound(_page: Page, response: Response | null) {
expect(response).not.toBeNull();
expect(response?.status()).toBe(404);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const nextConfig = {
],
},

async headers() {
headers() {
return [
{
source: '/~gitbook/static/:path*',
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/openNext/customWorkers/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class R2WriteBuffer extends DurableObject {
}

export default {
async fetch(request, env, ctx) {
fetch(request, env, ctx) {
return runWithCloudflareRequestContext(request, env, ctx, async () => {
// We can't move the handler import to the top level, otherwise the runtime will not be properly initialized
const { handler } = await import(
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/openNext/customWorkers/do.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export { DOQueueHandler } from '../../.open-next/.build/durable-objects/queue.js
export { DOShardedTagCache } from '../../.open-next/.build/durable-objects/sharded-tag-cache.js';

export default {
async fetch() {
fetch() {
// This worker does not handle any requests, it only provides Durable Objects
return new Response('This worker is not meant to handle requests directly', {
status: 400,
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/openNext/customWorkers/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export { DOQueueHandler } from '../../.open-next/.build/durable-objects/queue.js
export { DOShardedTagCache } from '../../.open-next/.build/durable-objects/sharded-tag-cache.js';

export default class extends WorkerEntrypoint {
async fetch(request) {
fetch(request) {
return runWithCloudflareRequestContext(request, this.env, this.ctx, async () => {
// - `Request`s are handled by the Next server
const reqOrResp = await middlewareHandler(request, this.env, this.ctx);
Expand Down
4 changes: 2 additions & 2 deletions packages/gitbook/openNext/queue/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import doQueue from '@opennextjs/cloudflare/overrides/queue/do-queue';

export default {
name: 'GitbookISRQueue',
send: async (msg) => {
return trace({ operation: 'gitbookISRQueueSend', name: msg.MessageBody.url }, async () => {
send: (msg) => {
return trace({ operation: 'gitbookISRQueueSend', name: msg.MessageBody.url }, () => {
const { ctx } = getCloudflareContext();
ctx.waitUntil(doQueue.send(msg));
});
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/openNext/queue/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Queue } from '@opennextjs/aws/types/overrides.js';

export default {
name: 'GitbookISRQueue',
send: async (msg) => {
send: (msg) => {
// We should never reach this point in the server. If that's the case, we should log it.
console.warn('GitbookISRQueue: send called on server side, this should not happen.', msg);
},
Expand Down
6 changes: 3 additions & 3 deletions packages/gitbook/openNext/tagCache/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const originalTagCache = doShardedTagCache({
export default {
name: 'GitbookTagCache',
mode: 'nextMode',
getLastRevalidated: async (tags: string[]) => {
getLastRevalidated: (tags: string[]) => {
const tagsToCheck = tags.filter(softTagFilter);
if (tagsToCheck.length === 0) {
// If we reach here, it probably means that there is an issue that we'll need to address.
Expand All @@ -40,7 +40,7 @@ export default {
}
);
},
hasBeenRevalidated: async (tags: string[], lastModified?: number) => {
hasBeenRevalidated: (tags: string[], lastModified?: number) => {
const tagsToCheck = tags.filter(softTagFilter);
if (tagsToCheck.length === 0) {
// If we reach here, it probably means that there is an issue that we'll need to address.
Expand All @@ -61,7 +61,7 @@ export default {
}
);
},
writeTags: async (tags: string[]) => {
writeTags: (tags: string[]) => {
return trace(
{
operation: 'gitbookTagCacheWriteTags',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SitePageNotFound } from '@/components/SitePage';

export default async function NotFound() {
export default function NotFound() {
return <SitePageNotFound />;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SitePageNotFound } from '@/components/SitePage';

export default async function NotFound() {
export default function NotFound() {
return <SitePageNotFound />;
}
2 changes: 1 addition & 1 deletion packages/gitbook/src/app/~gitbook/env/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
/**
* Output the public environment variables for this deployment
*/
export async function GET(_req: NextRequest) {
export function GET(_req: NextRequest) {
return NextResponse.json({
GITBOOK_URL,
GITBOOK_APP_URL,
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/app/~gitbook/revalidate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface JsonBody {
* Revalidate cached data based on tags.
* The body should be a JSON with { tags: string[] }
*/
export async function POST(req: NextRequest) {
export function POST(req: NextRequest) {
return withVerifySignature<JsonBody>(req, async (body) => {
if (!body.tags || !Array.isArray(body.tags)) {
return NextResponse.json(
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/components/AI/useAIPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function useAIPage(
* Generate a new page for a query.
*/
const generate = React.useCallback(
async (query: string) => {
(query: string) => {
generateFromStream(
streamGenerateAIPage({
query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { DocumentInlineIcon } from '@gitbook/api';
import { Icon, type IconName } from '@gitbook/icons';
import type { InlineProps } from './Inline';

export async function InlineIcon(props: InlineProps<DocumentInlineIcon>) {
export function InlineIcon(props: InlineProps<DocumentInlineIcon>) {
const { inline } = props;

return <Icon icon={inline.data.icon as IconName} className="inline size-[1em]" />;
Expand Down
4 changes: 2 additions & 2 deletions packages/gitbook/src/components/DocumentView/Math.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { InlineProps } from './Inline';

const assetsUrl = getAssetURL('math');

export async function BlockMath(props: BlockProps<DocumentBlockMath>) {
export function BlockMath(props: BlockProps<DocumentBlockMath>) {
const { block, style } = props;

return (
Expand All @@ -22,7 +22,7 @@ export async function BlockMath(props: BlockProps<DocumentBlockMath>) {
);
}

export async function InlineMath(props: InlineProps<DocumentInlineMath>) {
export function InlineMath(props: InlineProps<DocumentInlineMath>) {
const { inline } = props;

return <MathFormula formula={inline.data.formula} inline={true} assetsUrl={assetsUrl} />;
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/components/Header/HeaderLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface HeaderLinksProps {
style?: ClassValue;
}

export async function HeaderLinks({ children, style }: HeaderLinksProps) {
export function HeaderLinks({ children, style }: HeaderLinksProps) {
return (
<div
className={tcls(
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/components/Header/HeaderLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface HeaderLogoProps {
* Render the logo for a space using the customization settings.
*/

export async function HeaderLogo(props: HeaderLogoProps) {
export function HeaderLogo(props: HeaderLogoProps) {
const { context } = props;
const { customization, linker } = context;

Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/components/PDF/PDFRootLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CustomizationThemeMode } from '@gitbook/api';
/**
* Layout to be used for rendering the PDF.
*/
export async function PDFRootLayout(props: {
export function PDFRootLayout(props: {
context: GitBookSpaceContext | GitBookSiteContext;
children: React.ReactNode;
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Link, type LinkInsightsProps } from '../primitives';
/**
* Show cards to go to previous/next pages at the bottom.
*/
export async function PageFooterNavigation(props: {
export function PageFooterNavigation(props: {
context: GitBookSiteContext;
page: RevisionPageDocument;
}) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/components/PageBody/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tcls } from '@/lib/tailwind';
import { PageIcon } from '../PageIcon';
import { StyledLink } from '../primitives';

export async function PageHeader(props: {
export function PageHeader(props: {
context: GitBookSiteContext;
page: RevisionPageDocument;
ancestors: AncestorRevisionPage[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { AnnouncementDismissedScript } from '../Announcement';
* Layout shared between the content and the PDF renderer.
* It takes care of setting the theme and the language.
*/
export async function CustomizationRootLayout(props: {
export function CustomizationRootLayout(props: {
forcedTheme?: CustomizationThemeMode | null;
customization: SiteCustomizationSettings;
children: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/components/primitives/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type ClassValue, tcls } from '@/lib/tailwind';

import { Link, type LinkInsightsProps } from './Link';

export async function Card(
export function Card(
props: {
href: string;
leadingIcon?: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/lib/data/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getDataOrNull } from './errors';
/**
* Get the document for a page.
*/
export async function getPageDocument(
export function getPageDocument(
context: GitBookSpaceContext | GitBookSiteContext,
page: RevisionPageDocument
): Promise<JSONDocument | null> {
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbook/src/lib/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { unified } from 'unified';
/**
* Parse markdown and output HTML.
*/
export async function parseMarkdown(markdown: string): Promise<string> {
export function parseMarkdown(markdown: string): Promise<string> {
const promise = unified()
.use(remarkParse)
.use(remarkGfm)
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-parser/src/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { parseOpenAPIV3 } from './v3';
/**
* Convert a Swagger 2.0 schema to an OpenAPI 3.0 schema.
*/
export async function convertOpenAPIV2ToOpenAPIV3(
export function convertOpenAPIV2ToOpenAPIV3(
input: ParseOpenAPIInput
): Promise<Filesystem<OpenAPIV3xDocument>> {
const { value, rootURL } = input;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-contentkit/src/ElementMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export function ElementMarkdown(props: ContentKitServerElementProps<ContentKitMa

const initialMarkdown = resolveDynamicBinding(state, element.content);

async function renderMarkdown(markdown: string) {
function renderMarkdown(markdown: string) {
'use server';
return <Markdown className="contentkit-markdown" markdown={markdown} />;
return Promise.resolve(<Markdown className="contentkit-markdown" markdown={markdown} />);
}

return (
Expand Down
Loading