Skip to content

Commit a34581d

Browse files
authored
feat(eslint): Add no-return-await rule to eslint config (#8388)
Add https://eslint.org/docs/latest/rules/no-return-await to eslint config to remove usage of uneeded async/await calls. This helps reduce microtasks being generated, which can help reduce memory pressure caused by the SDK. The downside of removing `return await` is that stacktraces get slightly worse for async errors that use these methods, as we no longer pause execution on return for the engine to grab context on, but instead just pass through the promise, but I think it's worth it for this to be the default, and for us to opt-in to the better stacktraces if need be.
1 parent 5217485 commit a34581d

20 files changed

+35
-32
lines changed

packages/browser-integration-tests/utils/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ async function injectScriptAndGetEvents(page: Page, url: string, scriptPath: str
268268
await page.goto(url);
269269
await runScriptInSandbox(page, scriptPath);
270270

271-
return await getSentryEvents(page);
271+
return getSentryEvents(page);
272272
}
273273

274274
export {

packages/browser-integration-tests/utils/replayHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ export async function waitForReplayRunning(page: Page): Promise<void> {
132132
* Note that due to how this works with playwright, this is a POJO copy of replay.
133133
* This means that we cannot access any methods on it, and also not mutate it in any way.
134134
*/
135-
export async function getReplaySnapshot(page: Page): Promise<{
135+
export function getReplaySnapshot(page: Page): Promise<{
136136
_isPaused: boolean;
137137
_isEnabled: boolean;
138138
_context: InternalEventContext;
139139
session: Session | undefined;
140140
recordingMode: ReplayRecordingMode;
141141
}> {
142-
return await page.evaluate(() => {
142+
return page.evaluate(() => {
143143
const replayIntegration = (window as unknown as Window & { Replay: { _replay: ReplayContainer } }).Replay;
144144
const replay = replayIntegration._replay;
145145

packages/e2e-tests/test-utils/event-proxy-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ async function registerCallbackServerPort(serverName: string, port: string): Pro
243243
await writeFile(tmpFilePath, port, { encoding: 'utf8' });
244244
}
245245

246-
async function retrieveCallbackServerPort(serverName: string): Promise<string> {
246+
function retrieveCallbackServerPort(serverName: string): Promise<string> {
247247
const tmpFilePath = path.join(os.tmpdir(), `${TEMP_FILE_PREFIX}${serverName}`);
248-
return await readFile(tmpFilePath, 'utf8');
248+
return readFile(tmpFilePath, 'utf8');
249249
}

packages/eslint-config-sdk/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,8 @@ module.exports = {
261261
'array-callback-return': ['error', { allowImplicit: true }],
262262

263263
quotes: ['error', 'single', { avoidEscape: true }],
264+
265+
// Remove uncessary usages of async await to prevent extra micro-tasks
266+
'no-return-await': 'error',
264267
},
265268
};

packages/nextjs/src/client/wrapAppGetInitialPropsWithSentry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ type AppGetInitialProps = (typeof App)['getInitialProps'];
88
*/
99
export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetInitialProps): AppGetInitialProps {
1010
return new Proxy(origAppGetInitialProps, {
11-
apply: async (wrappingTarget, thisArg, args: Parameters<AppGetInitialProps>) => {
12-
return await wrappingTarget.apply(thisArg, args);
11+
apply: (wrappingTarget, thisArg, args: Parameters<AppGetInitialProps>) => {
12+
return wrappingTarget.apply(thisArg, args);
1313
},
1414
});
1515
}

packages/nextjs/src/client/wrapDocumentGetInitialPropsWithSentry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export function wrapDocumentGetInitialPropsWithSentry(
1010
origDocumentGetInitialProps: DocumentGetInitialProps,
1111
): DocumentGetInitialProps {
1212
return new Proxy(origDocumentGetInitialProps, {
13-
apply: async (wrappingTarget, thisArg, args: Parameters<DocumentGetInitialProps>) => {
14-
return await wrappingTarget.apply(thisArg, args);
13+
apply: (wrappingTarget, thisArg, args: Parameters<DocumentGetInitialProps>) => {
14+
return wrappingTarget.apply(thisArg, args);
1515
},
1616
});
1717
}

packages/nextjs/src/client/wrapErrorGetInitialPropsWithSentry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export function wrapErrorGetInitialPropsWithSentry(
1111
origErrorGetInitialProps: ErrorGetInitialProps,
1212
): ErrorGetInitialProps {
1313
return new Proxy(origErrorGetInitialProps, {
14-
apply: async (wrappingTarget, thisArg, args: Parameters<ErrorGetInitialProps>) => {
15-
return await wrappingTarget.apply(thisArg, args);
14+
apply: (wrappingTarget, thisArg, args: Parameters<ErrorGetInitialProps>) => {
15+
return wrappingTarget.apply(thisArg, args);
1616
},
1717
});
1818
}

packages/nextjs/src/client/wrapGetInitialPropsWithSentry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ type GetInitialProps = Required<NextPage>['getInitialProps'];
88
*/
99
export function wrapGetInitialPropsWithSentry(origGetInitialProps: GetInitialProps): GetInitialProps {
1010
return new Proxy(origGetInitialProps, {
11-
apply: async (wrappingTarget, thisArg, args: Parameters<GetInitialProps>) => {
12-
return await wrappingTarget.apply(thisArg, args);
11+
apply: (wrappingTarget, thisArg, args: Parameters<GetInitialProps>) => {
12+
return wrappingTarget.apply(thisArg, args);
1313
},
1414
});
1515
}

packages/nextjs/src/client/wrapGetServerSidePropsWithSentry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { GetServerSideProps } from 'next';
66
*/
77
export function wrapGetServerSidePropsWithSentry(origGetServerSideProps: GetServerSideProps): GetServerSideProps {
88
return new Proxy(origGetServerSideProps, {
9-
apply: async (wrappingTarget, thisArg, args: Parameters<GetServerSideProps>) => {
10-
return await wrappingTarget.apply(thisArg, args);
9+
apply: (wrappingTarget, thisArg, args: Parameters<GetServerSideProps>) => {
10+
return wrappingTarget.apply(thisArg, args);
1111
},
1212
});
1313
}

packages/nextjs/src/client/wrapGetStaticPropsWithSentry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ type Props = { [key: string]: unknown };
88
*/
99
export function wrapGetStaticPropsWithSentry(origGetStaticProps: GetStaticProps<Props>): GetStaticProps<Props> {
1010
return new Proxy(origGetStaticProps, {
11-
apply: async (wrappingTarget, thisArg, args: Parameters<GetStaticProps<Props>>) => {
12-
return await wrappingTarget.apply(thisArg, args);
11+
apply: (wrappingTarget, thisArg, args: Parameters<GetStaticProps<Props>>) => {
12+
return wrappingTarget.apply(thisArg, args);
1313
},
1414
});
1515
}

0 commit comments

Comments
 (0)