All skills
sergiodxa avatar

/frontend-async-best-practices

@4d1d816

Async/await and Promise optimization guidelines. Use when writing, reviewing, or refactoring asynchronous code to eliminate waterfalls and maximize parallelism. Triggers on tasks involving data fetching, loaders, actions, or Promise handling.

Use this Skill: https://skilld.dev/gh/sergiodxa/agent-skills/frontend-async-best-practices

This session only. Nothing lands on disk.

rulesapi-routes.md

≈279 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Prevent Waterfall Chains in API Routes

In API routes and loaders, start independent operations immediately, even if you don't await them yet.

Incorrect (config waits for auth, data waits for both):

export async function loader({ request }: LoaderFunctionArgs) {
  let session = await auth();
  let config = await fetchConfig();
  let data = await fetchData(session.user.id);
  return json({ data, config });
}

Correct (auth and config start immediately):

export async function loader({ request }: LoaderFunctionArgs) {
  let sessionPromise = auth();
  let configPromise = fetchConfig();
  let session = await sessionPromise;
  let [config, data] = await Promise.all([
    configPromise,
    fetchData(session.user.id),
  ]);
  return json({ data, config });
}

For operations with more complex dependency chains, use better-all to automatically maximize parallelism (see Dependency-Based Parallelization).

Source: SKILL.md on GitHub

1 warning13d5 checks · Risk SAFE
  • Gen Agent Trust Hub13d

    This skill is an educational resource containing best practice guidelines for optimizing asynchronous JavaScript and React code. No security risks, malicious code, or unauthorized operations were detected.

  • Socket13d

    No alerts

  • Snyk13d

    Risk: LOW · No issues

  • Runlayer7mo

    6/6 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 4d1d816. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-async-best-practices