@flareapp/react

中文文档
2.13.0发布于 2026/09/17MITTypeScriptESM + CJS近 30 天下载 1万

React client for flareapp.io

原始使用文档
文档目录10 节
  1. Installation
  2. Quick start
  3. Logging
  4. Minified production errors
  5. Identifying users
  6. Documentation
  7. Compatibility
  8. License
  9. Component profiler ( @flareapp/react/profiler )
  10. Self time

@flareapp/react

React integration for Flare error tracking and logging. Provides an error boundary component and a React 19+ error handler for catching and reporting React component errors to Flare.

Installation

npm install @flareapp/react @flareapp/js

Quick start

Initialize the Flare client and wrap your component tree with the error boundary:

import { flare } from '@flareapp/js';
import { FlareErrorBoundary } from '@flareapp/react';

flare.light('YOUR_FLARE_API_KEY');

function App() {
    return (
        <FlareErrorBoundary fallback={<p>Something went wrong.</p>}>
            <MyComponent />
        </FlareErrorBoundary>
    );
}

Logging

Beyond errors, the client can send structured logs. Logs are opt-in: enable them with enableLogs, then call any of the eight syslog levels (debug, info, notice, warning, error, critical, alert, emergency).

import { flare } from '@flareapp/js';

flare.configure({ enableLogs: true });

flare.logger.info('Checkout started', { cartId: cart.id, total: cart.total });

Minified production errors

In production, React throws minified errors like Minified React error #418; visit https://react.dev/errors/418?args[]=Foo. The client parses these into a single self-contained field, flare.exception.react_minified_error, carrying the running React version alongside the parsed pieces:

'flare.exception.react_minified_error': {
    number: 418,
    args: ['Foo', 'Bar'],
    url: 'https://react.dev/errors/418?args[]=Foo&args[]=Bar',
    react_version: '19.0.0',
}

Flare reads this field on the backend to look up React's error-code map (keyed on react_version) and surface the full, human-readable message. It is a Flare-internal field, not part of the display context, so it is emitted only when an error actually parses as a minified React error and cannot be stripped by a beforeSubmit hook. No error-code map is bundled into the client. Non-minified errors are reported unchanged.

context.custom.react continues to carry componentStack, componentStackFrames and version for display.

Identifying users

import { flare } from '@flareapp/js';

flare.setUser({ id: 123, email: '[email protected]', fullName: 'Jane Doe' });

See the JavaScript identifying-users docs for the full field list. Pass null to clear.

Documentation

Full documentation on the error boundary, the React 19+ error handler, lifecycle callbacks, and more is available at flareapp.io/docs/react/general/installation.

Compatibility

  • React 16, 17, 18, 19
  • flareReactErrorHandler requires React 19+
  • withFlareProfiler forwards ref on React 19 only

License

The MIT License (MIT). Please see License File for more information.

Component profiler (@flareapp/react/profiler)

Opt-in mount profiling: wrap a component to record a browser_component span for its mount, nested under the active page-load / navigation trace. Requires tracing to be enabled (enableTracing: true).

import { FlareProfiler, withFlareProfiler } from '@flareapp/react/profiler';

// Wrap at the definition:
export default withFlareProfiler(ProductPage);

// Or wrap an inline subtree:
<FlareProfiler name="Gallery">
    <ProductGallery />
</FlareProfiler>;

Spans nest into a tree: a profiled child nests under its nearest profiled ancestor; unprofiled components in between are transparent. A component with no active trace (tracing off, or no page-load/navigation root) records nothing and renders normally.

A component that mounts later inside an already-mounted profiled ancestor still nests under that ancestor, whose own span closed when it finished mounting. The tree is correct, but the waterfall shows the child starting after its parent ended. A page body swapped inside a persistent layout is the usual way to see this.

Self time

Every component span carries flare.component.self_time_ns: the span's duration minus the time its own profiled children account for. Children that overlap in time are counted once, so the value never goes below zero.

A child that mounts after its parent's span closed is not subtracted. Its work happened outside the parent's window, so the parent keeps its full duration.

React starts every component during render and ends them all during commit, so sibling spans overlap in time. The self times of one tree therefore add up to more than the root span's duration.

Import the main entry somewhere too. @flareapp/react/profiler is deliberately dependency-free, so it does not register React as the framework. That identity (flare.framework.name) is what tells Flare a component span came from React, and importing @flareapp/react anywhere in the app sets it. An app that uses only the /profiler entry reports js instead, and its component spans are attributed to plain JavaScript rather than React.

Naming: the span name is name (prop or withFlareProfiler(Component, { name })), then Component.displayName, then Component.name. Minified production builds can mangle Component.name, so pass an explicit name or set displayName for production.

Suspense (v1 limitation): a <Suspense> boundary inside a profiled subtree can end a parent span before a suspended child resumes, so the child may appear outside its parent in the waterfall, and its duration includes the data wait. If the wait outlasts the trace's idle window the child span is dropped rather than attached to a closed trace.

Render-phase start: the span starts when the component first renders, not when React commits it. A render React defers or discards (useDeferredValue, an interrupted transition, an <Activity mode="hidden"> prerender revealed later) bills that whole gap to the component.

Refs and statics: the wrapper is a plain function component. It forwards no ref through forwardRef and hoists no statics. On React 19 ref is a normal prop and passes straight through, so this only affects the React 16-18 half of the peer range; there, wrap with FlareProfiler inside the component instead of applying withFlareProfiler to it.

版本与发布记录

@flareapp/react 共发布 28 个版本,首次发布于 2024/01/25;过去 12 个月发布了 20 个版本。

版本发布日期距今
2.13.0latest2026/09/171 个月前
2.12.22026/09/142 个月前
2.12.12026/09/112 个月前
2.12.02026/09/022 个月前
2.11.02026/08/272 个月前
2.10.02026/08/262 个月前

关于 @flareapp/react 的常见问题

@flareapp/react 是什么?

React client for flareapp.io

如何安装 @flareapp/react?

在项目目录运行 npm install @flareapp/react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.0.0||^17.0.0||^18.0.0||^19.0.0)、@flareapp/js(^2.13.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flareapp/react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flareapp/react 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flareapp/react 可以商用吗?

@flareapp/react 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flareapp/react 的下载量有多少?

根据 npm 官方下载统计,@flareapp/react 在 2026/10/15 – 2026/11/13 这 30 天内被下载 10,020 次,日均约 334 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flareapp/react 还在维护吗?

最新版本 2.13.0 发布于 2026/09/17(1 个月前);至今共发布 28 个版本,其中过去 12 个月发布了 20 个;首次发布于 2024/01/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。