Skip to content

Commit 8e84a4c

Browse files
committed
fix(react): Add missing Sentry import to react guide
1 parent ba61c04 commit 8e84a4c

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
const {nodeFileTrace} = require('@vercel/nft');
2+
const path = require('path');
3+
const fs = require('fs');
4+
5+
function formatBytes(bytes, decimals = 2) {
6+
if (bytes === 0) return '0 Bytes';
7+
const k = 1024;
8+
const dm = decimals < 0 ? 0 : decimals;
9+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
10+
const i = Math.floor(Math.log(bytes) / Math.log(k));
11+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
12+
}
13+
14+
async function analyzeBuild() {
15+
try {
16+
const tracePath = path.join(
17+
process.cwd(),
18+
'node_modules/next/dist/server/next-server.js'
19+
);
20+
21+
/*
22+
collectBuildTraces({
23+
dir,
24+
config,
25+
distDir,
26+
edgeRuntimeRoutes: collectRoutesUsingEdgeRuntime(pageInfos),
27+
staticPages: [...staticPages],
28+
nextBuildSpan,
29+
hasSsrAmpPages,
30+
buildTraceContext,
31+
outputFileTracingRoot,
32+
isTurbopack: true,
33+
}
34+
*/
35+
36+
const fileSizes = new Map();
37+
let totalSize = 0;
38+
39+
const results = await nodeFileTrace([tracePath], {
40+
base: process.cwd(),
41+
processCwd: process.cwd(),
42+
ignore: [
43+
'node_modules/next/dist/pages/**/*',
44+
'node_modules/next/dist/server/image-optimizer.js',
45+
'node_modules/next/dist/compiled/@ampproject/toolbox-optimizer/**/*',
46+
'node_modules/next/dist/compiled/webpack/(bundle4|bundle5).js',
47+
'node_modules/react/**/*.development.js',
48+
'node_modules/react-dom/**/*.development.js',
49+
'node_modules/use-subscription/**/*.development.js',
50+
'node_modules/sharp/**/*',
51+
],
52+
});
53+
54+
for (const file of results.fileList) {
55+
const stats = fs.statSync(file);
56+
const fileSize = stats.size;
57+
fileSizes.set(file, fileSize);
58+
totalSize += fileSize;
59+
}
60+
61+
const reportPath = path.join(process.cwd(), 'build-analysis.json');
62+
fs.writeFileSync(
63+
reportPath,
64+
JSON.stringify(
65+
{
66+
files: Array.from(results.fileList),
67+
reasons: Object.fromEntries(
68+
Array.from(results.reasons.entries()).map(([file, reason]) => [file, reason])
69+
),
70+
sizes: Object.fromEntries(fileSizes),
71+
summary: {
72+
totalFiles: results.fileList.size,
73+
totalSize: {
74+
bytes: totalSize,
75+
formatted: formatBytes(totalSize),
76+
},
77+
},
78+
},
79+
null,
80+
2
81+
)
82+
);
83+
console.log(`Report written to ${reportPath}`);
84+
console.log('Total size:', formatBytes(totalSize));
85+
} catch (error) {
86+
console.error('Error analyzing build:', error);
87+
process.exit(1);
88+
}
89+
}
90+
91+
analyzeBuild();

docs/platforms/javascript/guides/react/index.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ import * as Sentry from "@sentry/react";
4848

4949
Sentry.init({
5050
dsn: "___PUBLIC_DSN___",
51-
51+
5252
// Adds request headers and IP for users, for more info visit:
5353
// https://docs.sentry.io/platforms/javascript/guides/react/configuration/options/#sendDefaultPii
5454
sendDefaultPii: true,
55-
55+
5656
integrations: [
5757
// ___PRODUCT_OPTION_START___ performance
5858
// If you're using react router, use the integration for your react router version instead.
@@ -113,6 +113,7 @@ Integrate Sentry with these hooks and customize error handling:
113113

114114
```javascript
115115
import { createRoot } from "react-dom/client";
116+
import * as Sentry from '@sentry/react';
116117

117118
const container = document.getElementById(“app”);
118119
const root = createRoot(container, {

platform-includes/capture-error/javascript.react.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Starting with React 19, the `createRoot` and `hydrateRoot` methods from `react-d
5252

5353
```javascript
5454
import { createRoot } from "react-dom/client";
55+
import * as Sentry from '@sentry/react';
5556

5657
const container = document.getElementById(“app”);
5758
const root = createRoot(container, {

0 commit comments

Comments
 (0)