Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v7
with:
node-version: 22
node-version: '>=22.23.4 <23'

- name: Install dependencies
run: pnpm install --frozen-lockfile
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v7
with:
node-version: 22
node-version: '>=22.23.4 <23'

- name: Setup Bun
uses: oven-sh/setup-bun@v2
Expand Down
2 changes: 2 additions & 0 deletions docs/PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1442,3 +1442,5 @@ One name, one writer per session (spec `platforms/javascript.md` "Host-owned tra

### Compat watch (issue #11, 2026-10-28)
Verified against current majors, all green with no adapter code changes: `@bugsee/koa` on Koa 3.2 (+ `@types/koa` 3), `@bugsee/nestjs` on Nest 12 (peer range widened to `^9 || ^10 || ^11 || ^12`; unit + real-Nest suites run on 12), `@bugsee/sveltekit` + `sveltekit-e2e` on SvelteKit 3 (fixture migrated: Kit 3 errors on `svelte.config.js`, options are passed to `sveltekit({ adapter })` in `vite.config.ts`; adapter-node 6). Dev deps now track the latest majors, so Nest 9-11, Koa 2 and Kit 2 are no longer exercised in CI. Not done (needs owner decision / separate work): Astro 7 (passes locally on Node 24, but its engine floor is Node >=22.23.4 and CI `node-version: 22` resolved to 22.23.3, so the astro-e2e build was refused; bump CI Node first), Preact 11 smoke, React Router 8 for `@bugsee/remix`, Kit 3 `handleError` status-influence semantics, Rollup 5 prerelease.

**Follow-up (issue #11).** Astro 7 now dev-tested (`astro ^7`, `@astrojs/node ^11`; astro-e2e green); CI `node-version` is `>=22.23.4 <23` in both jobs (Astro 7's engine floor). Preact 11 smoke added, wired into the react `test` and `test:coverage` scripts (`packages/react/vitest.preact.config.ts` aliases `react` to `preact/compat`; `BugseeErrorBoundary` + HOC catch, report and render the fallback). React Router 8: `HandleErrorFunction` is unchanged, but RR's client `onError` passes `{ location, params, pattern, errorInfo }` (React's `ErrorInfo` is nested), so `bugseeOnError` now reads `info.errorInfo.componentStack` (bare `ErrorInfo` still accepted); before, the component stack was silently dropped. Kit 3 `handleError`: tested that an app handler's `{ message, status }` return is forwarded verbatim; reporting gates on the input status. Kit 3 no longer passes a top-level `status` (input is `{ kind, error, issues? }`, status inside `error`), so `effectiveStatus` reads it there for non-`unknown` kinds (kind first: the top-level `status` is a warning getter in Kit 3 dev); before, in production builds every 404 and `error(4xx)` would have been reported. The same filter now guards the client hook in `@bugsee/svelte`, and RR `bugseeOnError` skips thrown `Response`/`data()` control flow. Rollup 5.0.0-0 (prerelease, no notes) left out; keep watching.
2 changes: 1 addition & 1 deletion docs/dev-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ machine you develop on.

What is left:

- **Node version.** CI pins Node 22; the script warns when the local major differs.
- **Node version.** CI pins Node `>=22.23.4 <23` (Astro 7 refuses anything older); the script warns when the local major differs.
- **A clean tree, not a clean machine.** `actions/checkout` wipes the working tree (`git clean -ffdx`),
so `node_modules` and the local turbo cache are cold every run — but the pnpm store, the runner tool
cache and *anything a previous run leaked* persist. Leaked processes are the practical hazard: the
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"packageManager": "pnpm@11.3.0",
"engines": {
"node": "^22.18.0 || ^24.11.0 || >=26.0.0"
"node": "^22.23.4 || ^24.11.0 || >=26.0.0"
},
"scripts": {
"build": "turbo run build",
Expand Down
4 changes: 2 additions & 2 deletions packages/astro-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"@bugsee/util": "workspace:*"
},
"devDependencies": {
"@astrojs/node": "^9.0.0",
"astro": "^5.0.0",
"@astrojs/node": "^11.0.0",
"astro": "^7.0.0",
"vitest": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@
},
"devDependencies": {
"@bugsee/node": "workspace:*",
"astro": "^5.0.0"
"astro": "^7.0.0"
}
}
8 changes: 5 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"scripts": {
"build": "tsup",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:coverage": "vitest run --coverage"
"test": "vitest run && vitest run --config vitest.preact.config.ts",
"test:coverage": "vitest run --coverage && vitest run --config vitest.preact.config.ts"
},
"dependencies": {
"@bugsee/browser": "workspace:*",
Expand All @@ -40,7 +40,9 @@
"@types/react": "^18.3.0",
"@types/react-dom": "^18.3.7",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"jsdom": "^25.0.1",
"preact": "^11.0.0"
},
"publishConfig": {
"main": "./dist/index.cjs",
Expand Down
65 changes: 65 additions & 0 deletions packages/react/src/preact-compat.preact.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type { Bugsee } from '@bugsee/browser';
import { createElement } from 'react'; // aliased to preact/compat by vitest.preact.config.ts
import { createRoot } from 'react-dom/client';
import { describe, expect, it, vi } from 'vitest';
import { BugseeErrorBoundary, withBugseeErrorBoundary } from './error-boundary';

// Preact 11 smoke: the error boundary must catch a render throw under `preact/compat`, report it, and render
// the fallback. Guards the README's claim that @bugsee/react works through the compat alias.

function fakeClient() {
const logException = vi.fn(async () => ({ ok: true }) as const);
return { client: { logException } as unknown as Bugsee, logException };
}

function Boom(): never {
throw new Error('preact render boom');
}

async function flush(): Promise<void> {
await new Promise((r) => setTimeout(r, 20));
}

describe('@bugsee/react under preact/compat 11', () => {
it('resolves react to Preact (the alias is live)', async () => {
const preact = await import('preact');
expect(typeof preact.h).toBe('function');
const compat = (await import('react')) as unknown as { Component: unknown };
expect(compat.Component).toBe(preact.Component);
});

it('BugseeErrorBoundary catches a render throw, reports it and renders the fallback', async () => {
const { client, logException } = fakeClient();
const onError = vi.fn();
const host = document.createElement('div');
document.body.appendChild(host);
createRoot(host).render(
createElement(
BugseeErrorBoundary,
{ getClient: () => client, onError, fallback: createElement('p', { id: 'fb' }, 'oops') },
createElement(Boom),
),
);
await flush();
expect(host.querySelector('#fb')?.textContent).toBe('oops');
expect(logException).toHaveBeenCalledTimes(1);
expect(((logException.mock.calls[0] as unknown[])[0] as Error).message).toBe(
'preact render boom',
);
expect(onError).toHaveBeenCalledTimes(1);
});

it('withBugseeErrorBoundary wraps a component the same way', async () => {
const { client, logException } = fakeClient();
const Safe = withBugseeErrorBoundary(Boom, {
getClient: () => client,
fallback: createElement('i', { id: 'hoc' }, 'hoc-fallback'),
});
const host = document.createElement('div');
document.body.appendChild(host);
createRoot(host).render(createElement(Safe));
await flush();
expect(host.querySelector('#hoc')?.textContent).toBe('hoc-fallback');
expect(logException).toHaveBeenCalledTimes(1);
});
});
1 change: 1 addition & 0 deletions packages/react/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig({
testTimeout: 30_000,
environment: 'node',
include: ['src/**/*.test.ts'],
exclude: ['src/**/*.preact.test.ts', '**/node_modules/**'],
coverage: {
provider: 'v8',
include: ['src/**/*.ts'],
Expand Down
19 changes: 19 additions & 0 deletions packages/react/vitest.preact.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from 'vitest/config';

// Preact 11 compat smoke (the package `test` and `test:coverage` scripts run it after the main suite, which is what CI invokes). The same sources, with `react` /
// `react-dom` aliased to `preact/compat` exactly as a Preact app's bundler does. Kept out of the main config
// (which gates coverage against real React) via the `*.preact.test.ts` suffix.
export default defineConfig({
resolve: {
alias: [
{ find: /^react-dom\/client$/, replacement: 'preact/compat/client' },
{ find: /^react-dom$/, replacement: 'preact/compat' },
{ find: /^react$/, replacement: 'preact/compat' },
],
},
test: {
testTimeout: 30_000,
environment: 'jsdom',
include: ['src/**/*.preact.test.ts'],
},
});
4 changes: 2 additions & 2 deletions packages/remix/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# @bugsee/remix

Remix and React Router v7 adapter for the Bugsee SDK: server error reporting through `handleError` in `entry.server`, and browser capture through `entry.client`.
Remix and React Router v7/v8 adapter for the Bugsee SDK: server error reporting through `handleError` in `entry.server`, and browser capture through `entry.client`.

Part of the Bugsee JavaScript SDK (public beta, 0.1.0-beta.x).

Install this package directly in Remix and React Router v7 (framework mode) apps. It is a single install: it bundles the browser and Node.js SDKs and re-exports the React adapter from `@bugsee/remix/client`.
Install this package directly in Remix and React Router v7 or v8 (framework mode) apps. It is a single install: it bundles the browser and Node.js SDKs and re-exports the React adapter from `@bugsee/remix/client`.

## Install

Expand Down
28 changes: 28 additions & 0 deletions packages/remix/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ describe('bugseeOnError (RR7 <HydratedRouter onError>)', () => {
expect(reportReactError).toHaveBeenCalledWith(err, {});
});

it("reads the component stack from React Router's `{ location, params, pattern, errorInfo }` info (RR7.x/8)", () => {
const err = new Error('render boom');
bugseeOnError(err, {
location: { pathname: '/x' },
params: {},
pattern: '/x',
errorInfo: { componentStack: '\n at Route' },
});
expect(reportReactError).toHaveBeenCalledWith(err, { componentStack: '\n at Route' });
});

it('prefers the nested `errorInfo` stack over a top-level one, and omits a null nested stack', () => {
const err = new Error('boom');
bugseeOnError(err, {
componentStack: '\n at Top',
errorInfo: { componentStack: '\n at Nested' },
});
expect(reportReactError).toHaveBeenLastCalledWith(err, { componentStack: '\n at Nested' });
bugseeOnError(err, { pattern: '/x', errorInfo: { componentStack: null } });
expect(reportReactError).toHaveBeenLastCalledWith(err, {});
});

it('skips expected control flow: route error responses and thrown Responses', () => {
bugseeOnError({ status: 404, statusText: 'Not Found', data: 'x' }, { pattern: '/x' });
bugseeOnError(new Response(null, { status: 404 }));
expect(reportReactError).not.toHaveBeenCalled();
});

it('omits the component stack when React passes null (componentStack is string | null)', () => {
const err = new Error('boom');
bugseeOnError(err, { componentStack: null });
Expand Down
22 changes: 18 additions & 4 deletions packages/remix/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,28 @@ export async function registerClient(
return await launch(appToken, options);
}

/** What React Router's `onError` receives as its second argument (structural; no `react-router` dep): the
* RR8 `{ location, params, pattern, errorInfo }` shape (extra fields ignored) or a bare React `ErrorInfo`. */
export interface RouterOnErrorInfo extends ReactErrorInfo {
errorInfo?: ReactErrorInfo;
location?: unknown;
params?: unknown;
pattern?: string;
}

/**
* The React Router v7 `<HydratedRouter onError>` (and data-router `onError`) handler — report a client
* The React Router v7/v8 `<HydratedRouter onError>` (and data-router `onError`) handler — report a client
* React error to Bugsee with its component stack. Defensive + no-ops when Bugsee is not launched (via
* `reportReactError`).
*/
export function bugseeOnError(error: unknown, errorInfo?: ReactErrorInfo): void {
// React's `errorInfo.componentStack` is `string | null` — narrow to a real stack before forwarding.
const componentStack = errorInfo?.componentStack;
export function bugseeOnError(error: unknown, info?: RouterOnErrorInfo): void {
// React Router calls `onError` for thrown `data()`/`Response` values (404s, auth redirects) too.
if (isRouteErrorResponse(error) || (typeof Response !== 'undefined' && error instanceof Response))
return;
// React Router (7.x/8) passes `{ location, params, pattern, errorInfo }`; the React `ErrorInfo` is NESTED
// under `errorInfo`. A bare React `ErrorInfo` (older RR7 / direct use) is still accepted. React's
// `componentStack` is `string | null` — narrow to a real stack before forwarding.
const componentStack = info?.errorInfo?.componentStack ?? info?.componentStack;
reportReactError(error, typeof componentStack === 'string' ? { componentStack } : {});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/svelte-plugin-component-annotate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default {
};
```

On SvelteKit 3 there is no `svelte.config.js`; pass `preprocess` to the `sveltekit()` Vite plugin instead (see the [`@bugsee/sveltekit` README](../sveltekit/README.md)).

Each host element (lowercase tag) in a `.svelte` file gets a `data-bugsee-component="<ComponentName>"` attribute. The name comes from the file name (`UserCard.svelte` becomes `UserCard`). For `index.svelte` and SvelteKit route files (`+page`, `+layout`, `+error`) the enclosing directory name is used. Elements you already annotated by hand are left alone, and component instances (`<Child />`) get no attribute.

## Options
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export default {
};
```

On SvelteKit 3 there is no `svelte.config.js`; pass `preprocess` to the `sveltekit()` Vite plugin instead (see the [`@bugsee/sveltekit` README](../sveltekit/README.md)).

## Options

`launch(appToken, options)` accepts the SDK launch options. The most relevant ones in the browser:
Expand Down
28 changes: 28 additions & 0 deletions packages/svelte/src/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ describe('handleErrorWithBugsee', () => {
expect(result).toEqual({ message: 'Custom error page' }); // …and its return is forwarded to SvelteKit
});

it('skips expected <500 errors (Kit 3 kind bodies, Kit 2 status) but still delegates; reports 5xx/unknown', () => {
const { client, logException } = fakeClient();
const appHandler = vi.fn();
const h = handleErrorWithBugsee(appHandler, { getClient: () => client });
h({ kind: 'framework', error: { status: 404 } });
h({ kind: 'app', error: { status: 403 } });
h({ error: new Error('k2 404'), status: 404 });
expect(logException).not.toHaveBeenCalled();
expect(appHandler).toHaveBeenCalledTimes(3);
h({ kind: 'app', error: { status: 503 } });
h({ error: new Error('k2 500'), status: 500 });
h({ kind: 'unknown', error: Object.assign(new Error('x'), { status: 404 }) }); // thrown value: not trusted
h({ kind: 'app', error: null });
h({ error: new Error('no status at all') });
expect(logException).toHaveBeenCalledTimes(5);
});

it('Kit 3: does not read the deprecated top-level `status` getter', () => {
const { client } = fakeClient();
const getter = vi.fn(() => 404);
const input = { kind: 'unknown', error: new Error('x') } as Record<string, unknown>;
Object.defineProperty(input, 'status', { get: getter });
handleErrorWithBugsee(undefined, { getClient: () => client })(
input as unknown as Parameters<ReturnType<typeof handleErrorWithBugsee>>[0],
);
expect(getter).not.toHaveBeenCalled();
});

// The four cases below all describe a DEGRADED route shape: no label is expected, but THE ERROR MUST
// STILL BE REPORTED. `expect(calls[0]?.[1]?.labels).toBeUndefined()` alone cannot say that — it passes
// just as happily when `logException` was never called at all, which is exactly what happens if a
Expand Down
14 changes: 14 additions & 0 deletions packages/svelte/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ export interface ReportSvelteErrorOptions extends SvelteErrorOptions {
export interface HandleErrorInput {
error: unknown;
event?: { route?: { id?: string | null } };
/** Kit 3: the error category; for every kind but `unknown`, `error` is a `{ status, message }` body. */
kind?: 'app' | 'framework' | 'unknown';
/** Kit 2 only (a deprecated, warning getter in Kit 3 dev — read only when `kind` is absent). */
status?: number;
}

/** True for an expected <500 condition (404, `error(4xx)`), which is not a crash. Kit 3 (`kind` present) keeps
* the status in the `error` body (never for `unknown`, a thrown value); Kit 2 has a top-level `status`. */
function isExpectedStatus(input: HandleErrorInput): boolean {
let status: unknown;
if (input.kind === undefined) status = input.status;
else if (input.kind !== 'unknown') status = (input.error as { status?: unknown } | null)?.status;
return typeof status === 'number' && status < 500;
}
/** A SvelteKit `handleError` hook (returns the `App.Error` to render, or void). */
export type HandleErrorHook = (input: HandleErrorInput) => unknown;
Expand Down Expand Up @@ -57,6 +70,7 @@ export function handleErrorWithBugsee(
// the error seam did not.
const routeId = neverThrow(() => input.event?.route?.id, options.onError);
neverThrow(() => {
if (isExpectedStatus(input)) return;
reportSvelteError(input.error, {
...options,
...(typeof routeId === 'string' && routeId !== '' ? { routeId } : {}),
Expand Down
Loading
Loading