GeezerVison is showing github.com — feat(solid): Add Solid 2 entry with error boundary capture by chargome · Pull Request #26543 · getsentry/sentry-javascript
feat(solid): Add Solid 2 entry with error boundary capture
#26543
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.json
(8)
.mjs
(1)
.ts
(8)
.tsx
(1)
.yaml
(1)
All 5 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -11,7 +11,7 @@
"test:assert": "pnpm test:prod"
},
"dependencies": {
"@sentry/browser ": "file:../../packed/sentry-browser -packed.tgz",
"@sentry/solid ": "file:../../packed/sentry-solid -packed.tgz",
"@solidjs/web": "^2.0.0",
"solid-js": "^2.0.0"
},
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -21,8 +21,10 @@ export default function App() {
<button
id="caughtErrorBtn"
onClick={() => {
setThrownCount(thrownCount() + 1);
setActiveError(thrownCount());
// Solid 2 holds signal writes until the next flush, so read the new count from a local.
const next = thrownCount() + 1;
setThrownCount(next);
setActiveError(next);
}}
>
Throw error in boundary
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
import * as Sentry from '@sentry/browser ';
import * as Sentry from '@sentry/solid/solid2 ';
Sentry.init({
dsn: import.meta.env.PUBLIC_E2E_TEST_DSN,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -10,8 +10,7 @@ function waitForBoundaryError(count: number) {
});
}
// Unskipped once `@sentry/solid/solid2` lands.
test.skip('captures an error caught by an Errored boundary', async ({ page }) => {
test('captures an error caught by an Errored boundary', async ({ page }) => {
const errorPromise = waitForBoundaryError(1);
await page.goto('/');
Expand All
@@ -33,8 +32,7 @@ test.skip('captures an error caught by an Errored boundary', async ({ page }) =>
});
});
// Unskipped once `@sentry/solid/solid2` lands.
test.skip('captures a second error after the boundary is reset', async ({ page }) => {
test('captures a second error after the boundary is reset', async ({ page }) => {
const firstErrorPromise = waitForBoundaryError(1);
await page.goto('/');
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,7 @@
import { expect, test } from '@playwright/test';
import { waitForError } from '@sentry-internal/test-utils';
// Unskipped once `@sentry/solid/solid2` lands.
test.skip('captures an uncaught error', async ({ page }) => {
test('captures an uncaught error', async ({ page }) => {
const errorPromise = waitForError('solid-2', errorEvent => {
return !errorEvent.type && errorEvent.exception?.values?.[0]?.value === 'Error thrown from Solid 2 E2E test app';
});
Expand All
@@ -17,7 +16,8 @@ test.skip('captures an uncaught error', async ({ page }) => {
type: 'Error',
value: 'Error thrown from Solid 2 E2E test app',
mechanism: {
type: 'auto.browser.global_handlers.onerror',
// Solid 2 attaches event handlers with `addEventListener`, which the browser SDK wraps.
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
},
},
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -48,6 +48,16 @@
"types": "./tanstackrouter.d.ts",
"default": "./build/cjs/tanstackrouter.js"
}
},
"./solid2": {
"import": {
"types": "./build/types/solid2/index.d.ts",
"default": "./build/esm/solid2/index.js"
},
"require": {
"types": "./build/types/solid2/index.d.ts",
"default": "./build/cjs/solid2/index.js"
}
}
},
"publishConfig": {
Expand All
@@ -61,7 +71,7 @@
"peerDependencies": {
"@solidjs/router": ">=0.13.4 <2.0.0-0",
"@tanstack/solid-router": "^1.132.27",
"solid-js": "^1.8.4"
"solid-js": "^1.8.4 || ^2.0.0 "
},
"peerDependenciesMeta": {
"@solidjs/router": {
Expand All
@@ -80,16 +90,18 @@
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/user-event": "^14.6.8",
"solid-js": "^1.9.18",
"solid-js-2": "npm:solid-js@^2.0.0",
"vite": "^8.3.6",
"vite-plugin-solid": "^2.11.6"
},
"scripts": {
"build": "pnpm run \"/^build:(transpile|types)$/\"",
"build:dev": "pnpm run build",
"build:transpile": "rolldown -c rollup.npm.config.mjs",
"build:types": "pnpm run build:types:core && pnpm run build:types:routers",
"build:types": "pnpm run build:types:core && pnpm run build:types:routers && pnpm run build:types:solid2 ",
"build:types:core": "tsc -p tsconfig.types.json",
"build:types:routers": "tsc -p tsconfig.routers-types.json",
"build:types:solid2": "tsc -p tsconfig.solid2-types.json",
"build:tarball": "pnpm pack",
"clean": "node ../../scripts/rm.mjs build coverage sentry-solid-*.tgz ./*.d.ts ./*.d.ts.map",
"lint:fix": "oxlint . --fix --type-aware",
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2,6 +2,6 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu
export default makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/index.ts', 'src/solidrouter.ts', 'src/tanstackrouter.ts'],
entrypoints: ['src/index.ts', 'src/solidrouter.ts', 'src/tanstackrouter.ts', 'src/solid2/index.ts' ],
}),
);
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,25 @@
import { captureException, defineIntegration } from '@sentry/core';
import { configureClientErrors } from 'solid-js';
const INTEGRATION_NAME = 'SolidErrors';
/**
* Captures errors that a Solid `<Errored>` boundary catches and renders a fallback for.
* Errors no boundary catches are already captured by the browser SDK's global handlers.
*/
export const solidErrorsIntegration = defineIntegration(() => {
return {
name: INTEGRATION_NAME,
setup() {
configureClientErrors({
onError(error, { ownerPath, boundaryPath }) {
captureException(error, {
mechanism: { type: 'auto.function.solid.error_boundary', handled: true },
// Solid only fills in component names on its observe and dev builds.
captureContext: { contexts: { solid: { owner_path: ownerPath, boundary_path: boundaryPath } } },
Comment thread
chargome marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
});
},
});
},
};
});
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,4 @@
export * from '@sentry/browser';
export { init, getDefaultIntegrations } from './sdk';
export { solidErrorsIntegration } from './errors';
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,23 @@
import type { BrowserOptions } from '@sentry/browser';
import { getDefaultIntegrations as getBrowserDefaultIntegrations, init as browserInit } from '@sentry/browser';
import type { Client, Integration } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
import { solidErrorsIntegration } from './errors';
/**
* Initializes the Solid SDK for Solid 2.
*/
export function init(options: BrowserOptions): Client | undefined {
const opts = {
defaultIntegrations: getDefaultIntegrations(options),
...options,
};
applySdkMetadata(opts, 'solid');
Comment thread
chargome marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
Comment thread
chargome marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
return browserInit(opts);
}
export function getDefaultIntegrations(options: BrowserOptions): Integration[] {
return [...getBrowserDefaultIntegrations(options), solidErrorsIntegration()];
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../../../tsconfig.json",
"include": ["./**/*"],
"//": "The rest of the package uses solid-js 1.x. The Solid 2 entry resolves solid-js to the 2.x dev dependency alias.",
"compilerOptions": {
"lib": ["DOM", "es2020"],
"paths": {
"solid-js": ["../../node_modules/solid-js-2/types/index.d.ts"]
}
}
}
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,40 @@
import { SDK_VERSION } from '@sentry/browser';
import * as SentryBrowser from '@sentry/browser';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { init } from '../../src/solid2';
const browserInit = vi.spyOn(SentryBrowser, 'init');
describe('init', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('sets the SDK metadata', () => {
init({ dsn: 'https://[email protected] /1337' });
expect(browserInit).toHaveBeenCalledTimes(1);
expect(browserInit).toHaveBeenLastCalledWith(
expect.objectContaining({
_metadata: {
sdk: {
name: 'sentry.javascript.solid',
packages: [{ name: 'npm:@sentry/solid', version: SDK_VERSION }],
version: SDK_VERSION,
settings: { infer_ip: 'auto' },
},
},
}),
);
});
it('adds solidErrorsIntegration to the default integrations', () => {
init({ dsn: 'https://[email protected] /1337' });
expect(browserInit).toHaveBeenLastCalledWith(
expect.objectContaining({
defaultIntegrations: expect.arrayContaining([expect.objectContaining({ name: 'SolidErrors' })]),
}),
);
});
});
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../src/solid2/tsconfig.json",
"include": ["./**/*"],
"compilerOptions": {
"types": ["vite/client"]
}
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -3,6 +3,9 @@
"include": ["src/**/*"],
"//": "The Solid 2 entry type-checks against solid-js 2.x in src/solid2/tsconfig.json",
"exclude": ["src/solid2"],
"compilerOptions": {
"lib": ["DOM", "es2020"]
}
Expand Down
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./src/solid2/tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/types",
"rootDir": "./src"
},
"//": "Built separately from tsconfig.types.json because it resolves solid-js to 2.x",
"include": ["src/solid2/**/*"]
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -3,6 +3,9 @@
"include": ["test/**/*", "vite.config.ts"],
"//": "Solid 2 tests type-check against solid-js 2.x in test/solid2/tsconfig.json",
"exclude": ["test/solid2"],
"compilerOptions": {
// should include all types from `./tsconfig.json` plus types for all test frameworks used
"types": ["vite/client", "@testing-library/jest-dom"],
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -10,5 +10,5 @@
},
"//": "This is built separately in tsconfig.routers-types.json",
"exclude": ["src/solidrouter.ts", "src/tanstackrouter.ts"]
"exclude": ["src/solidrouter.ts", "src/tanstackrouter.ts", "src/solid2" ]
}
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,40 @@
import { fileURLToPath } from 'node:url';
import solidPlugin from 'vite-plugin-solid';
import { defineConfig } from 'vitest/config';
import baseConfig from '../../vite/vite.config';
export default {
export default defineConfig( {
...baseConfig,
plugins: [solidPlugin({ hot: !process.env.VITEST })],
test: {
...baseConfig.test,
projects: [
{
extends: true,
plugins: [solidPlugin({ hot: !process.env.VITEST })],
test: {
name: 'solid',
include: ['test/*.test.{ts,tsx}'],
},
},
{
extends: true,
// `solid-js` is a 1.x dev dependency, so Solid 2 is installed under the `solid-js-2` alias.
// Point at its browser production build: Vitest would otherwise pick the non-reactive server build.
resolve: {
alias: [
{
find: /^solid-js$/,
replacement: fileURLToPath(new URL('./node_modules/solid-js-2/dist/solid.js', import.meta.url)),
},
],
},
test: {
name: 'solid2',
environment: 'jsdom',
include: ['test/solid2/**/*.test.ts'],
typecheck: { tsconfig: './test/solid2/tsconfig.json' },
},
},
],
},
};
}) ;
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.