Token导航 LogoToken导航TokenDH.com
研究检索操作浏览器github未标认证来源可访问许可证需确认审计通过

router-act路由器法

Agent Skill

router-act 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

9,596

周安装

392

GitHub Stars

139,172

下载量

3,073
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:router-act(路由器法)
来源仓库:https://github.com/vercel/next.js
仓库路径:skills/router-act
安装命令:
npx skills add https://github.com/vercel/next.js --skill router-act
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/vercel/next.js --skill router-act

简介

router-act 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词快速定位候选结果时使用。

  • 它适用于研究检索类任务,可结合来源仓库和原始 README 进一步核验具体用法。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用该技能。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网或文件读写操作。
  • router-act 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Router Act Testing

Use this skill when writing or modifying tests that involve prefetch requests, client router navigations, or the segment cache. The createRouterAct utility from test/lib/router-act.ts lets you assert on prefetch and navigation responses in an end-to-end way without coupling to the exact number of requests or the protocol details. This is why most client router-related tests use this pattern.

When NOT to Use act

Don't bother with act if you don't need to instrument the network responses — either to control their timing or to assert on what's included in them. If all you're doing is waiting for some part of the UI to appear after a navigation, regular Playwright helpers like browser.elementById(), browser.elementByCss(), and browser.waitForElementByCss() are sufficient.

Core Principles

  1. Use LinkAccordion to control when prefetches happen. Never let links be visible outside an act scope.
  2. Prefer 'no-requests' whenever the data should be served from cache. This is the strongest assertion — it proves the cache is working.
  3. Avoid retry/polling timers. The act utility exists specifically to replace inherently flaky patterns like retry() loops or setTimeout waits for network activity. If you find yourself wanting to poll, you're probably not using act correctly.
  4. Avoid the block feature. It's prone to false negatives. Prefer includes and 'no-requests' assertions instead.

Act API

Config Options

// Assert NO router requests are made (data served from cache).
// Prefer this whenever possible — it's the strongest assertion.
await act(async () => { ... }, 'no-requests')

// Expect at least one response containing this substring
await act(async () => { ... }, { includes: 'Page content' })

// Expect multiple responses (checked in order)
await act(async () => { ... }, [
  { includes: 'First response' },
  { includes: 'Second response' },
])

// Assert the same content appears in two separate responses
await act(async () => { ... }, [
  { includes: 'Repeated content' },
  { includes: 'Repeated content' },
])

// Expect at least one request, don't assert on content
await act(async () => { ... })

How includes Matching Works

  • The includes substring is matched against the HTTP response body. Use text content that appears literally in the rendered output (e.g. 'Dynamic content (stale time 60s)').
  • Extra responses that don't match any includes assertion are silently ignored — you only need to assert on the responses you care about. This keeps tests decoupled from the exact number of requests the router makes.
  • Each includes expectation claims exactly one response. If the same substring appears in N separate responses, provide N separate {includes: '...'} entries.

What act Does Internally

act intercepts all router requests — prefetches, navigations, and Server Actions — made during the scope:

  1. Installs a Playwright route handler to intercept router requests
  2. Runs your scope function
  3. Waits for a requestIdleCallback (captures IntersectionObserver-triggered prefetches)
  4. Fulfills buffered responses to the browser
  5. Repeats steps 3-4 until no more requests arrive
  6. Asserts on the responses based on the config

Responses are buffered and only forwarded to the browser after the scope function returns. This means you cannot navigate to a new page and wait for it to render within the same scope — that would deadlock. Trigger the navigation (click the link) and let act handle the rest. Read destination page content *after* act returns:

await act(
  async () => {
    /* toggle accordion, click link */
  },
  { includes: 'Page content' }
)

// Read content after act returns, not inside the scope
expect(await browser.elementById('my-content').text()).toBe('Page content')

LinkAccordion Pattern

Why LinkAccordion Exists

LinkAccordion controls when <Link> components enter the DOM. A Next.js <Link> triggers a prefetch when it enters the viewport (via IntersectionObserver). By hiding the Link behind a checkbox toggle, you control exactly when prefetches happen — only when you explicitly toggle the accordion inside an act scope.

// components/link-accordion.tsx
'use client'
import Link from 'next/link'
import { useState } from 'react'

export function LinkAccordion({ href, children, prefetch }) {
  const [isVisible, setIsVisible] = useState(false)
  return (
    <>
      <input
        type="checkbox"
        checked={isVisible}
        onChange={() => setIsVisible(!isVisible)}
        data-link-accordion={href}
      />
      {isVisible ? (
        <Link href={href} prefetch={prefetch}>
          {children}
        </Link>
      ) : (
        `${children} (link is hidden)`
      )}
    </>
  )
}

Standard Navigation Pattern

Always toggle the accordion and click the link inside the same act scope:

await act(
  async () => {
    // 1. Toggle accordion — Link enters DOM, triggers prefetch
    const toggle = await browser.elementByCss(
      'input[data-link-accordion="/target-page"]'
    )
    await toggle.click()

    // 2. Click the now-visible link — triggers navigation
    const link = await browser.elementByCss('a[href="/target-page"]')
    await link.click()
  },
  { includes: 'Expected page content' }
)

Common Sources of Flakiness

Using browser.back() with open accordions

Do not use browser.back() to return to a page where accordions were previously opened. BFCache restores the full React state including useState values, so previously-opened Links are immediately visible. This triggers IntersectionObserver callbacks outside any act scope — if the cached data is stale, uncontrolled re-prefetches fire and break subsequent no-requests assertions.

The only safe use of browser.back()/browser.forward() is when testing BFCache behavior specifically.

Fix: navigate forward to a fresh hub page instead. See Hub Pages.

Using visible <Link> components outside act scopes

Any <Link> visible in the viewport can trigger a prefetch at any time via IntersectionObserver. If this happens outside an act scope, the request is uncontrolled and can interfere with subsequent assertions. Always hide links behind LinkAccordion and only toggle them inside act.

Using retry/polling timers to wait for network activity

retry(), setTimeout, or any polling pattern to wait for prefetches or navigations to settle is inherently flaky. act deterministically waits for all router requests to complete before returning.

Navigating and waiting for render in the same act scope

Responses are buffered until the scope exits. Clicking a link then reading destination content in the same scope deadlocks. Read page content after act returns instead.

Hub Pages

When you need to navigate away from a page and come back to test staleness, use "hub" pages instead of browser.back(). Each hub is a fresh page with its own LinkAccordion components that start closed.

Hub pages use connection() to ensure they are dynamically rendered. This guarantees that navigating to a hub always produces a router request, which lets act properly manage the navigation and wait for the page to fully render before continuing.

Hub page pattern:

// app/my-test/hub-a/page.tsx
import { Suspense } from 'react'
import { connection } from 'next/server'
import { LinkAccordion } from '../../components/link-accordion'

async function Content() {
  await connection()
  return <div id="hub-a-content">Hub a</div>
}

export default function Page() {
  return (
    <>
      <Suspense fallback="Loading...">
        <Content />
      </Suspense>
      <ul>
        <li>
          <LinkAccordion href="/my-test/target-page">Target page</LinkAccordion>
        </li>
      </ul>
    </>
  )
}

Target pages link to hubs via LinkAccordion too:

// On target pages, add LinkAccordion links to hub pages
<LinkAccordion href="/my-test/hub-a">Hub A</LinkAccordion>

Test flow:

// 1. Navigate to target (first visit)
await act(
  async () => {
    /* toggle accordion, click link */
  },
  { includes: 'Target content' }
)

// 2. Navigate to hub-a (fresh page, all accordions closed)
await act(
  async () => {
    const toggle = await browser.elementByCss(
      'input[data-link-accordion="/my-test/hub-a"]'
    )
    await toggle.click()
    const link = await browser.elementByCss('a[href="/my-test/hub-a"]')
    await link.click()
  },
  { includes: 'Hub a' }
)

// 3. Advance time
await page.clock.setFixedTime(startDate + 60 * 1000)

// 4. Navigate back to target from hub (controlled prefetch)
await act(async () => {
  const toggle = await browser.elementByCss(
    'input[data-link-accordion="/my-test/target-page"]'
  )
  await toggle.click()
  const link = await browser.elementByCss('a[href="/my-test/target-page"]')
  await link.click()
}, 'no-requests') // or { includes: '...' } if data is stale

Fake Clock Setup

Segment cache staleness tests use Playwright's clock API to control Date.now():

async function startBrowserWithFakeClock(url: string) {
  let page!: Playwright.Page
  const startDate = Date.now()

  const browser = await next.browser(url, {
    async beforePageLoad(p: Playwright.Page) {
      page = p
      await page.clock.install()
      await page.clock.setFixedTime(startDate)
    },
  })

  const act = createRouterAct(page)
  return { browser, page, act, startDate }
}
  • setFixedTime changes Date.now() return value but timers still run in real time
  • The segment cache uses Date.now() for staleness checks
  • Advancing the clock doesn't trigger IntersectionObserver — only viewport changes do
  • setFixedTime does NOT fire pending setTimeout/setInterval callbacks

Reference

  • createRouterAct: test/lib/router-act.ts
  • LinkAccordion: test/e2e/app-dir/segment-cache/staleness/components/link-accordion.tsx
  • Example tests: test/e2e/app-dir/segment-cache/staleness/

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.78%
按下载量换算1,100

Claude

28.29%
按下载量换算869

Cursor

18.17%
按下载量换算558

Gemini CLI

9.7%
按下载量换算298

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills