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

+1-1
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

+2-2
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

+2-2
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

+3
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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

+2-2
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
}

packages/nextjs/src/common/devErrorSymbolicationEventProcessor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export async function devErrorSymbolicationEventProcessor(event: Event, hint: Ev
116116
const frames = stackTraceParser.parse(hint.originalException.stack);
117117

118118
const resolvedFrames = await Promise.all(
119-
frames.map(async frame => await resolveStackFrame(frame, hint.originalException as Error)),
119+
frames.map(frame => resolveStackFrame(frame, hint.originalException as Error)),
120120
);
121121

122122
if (event.exception?.values?.[0].stacktrace?.frames) {

packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function wrapApiHandlerWithSentry<H extends EdgeRouteHandler>(
1111
parameterizedRoute: string,
1212
): (...params: Parameters<H>) => Promise<ReturnType<H>> {
1313
return new Proxy(handler, {
14-
apply: async (wrappingTarget, thisArg, args: Parameters<H>) => {
14+
apply: (wrappingTarget, thisArg, args: Parameters<H>) => {
1515
const req = args[0];
1616

1717
const activeSpan = !!getCurrentHub().getScope()?.getSpan();
@@ -25,7 +25,7 @@ export function wrapApiHandlerWithSentry<H extends EdgeRouteHandler>(
2525
mechanismFunctionName: 'wrapApiHandlerWithSentry',
2626
});
2727

28-
return await wrappedHandler.apply(thisArg, args);
28+
return wrappedHandler.apply(thisArg, args);
2929
},
3030
});
3131
}

packages/nextjs/src/edge/wrapMiddlewareWithSentry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
1111
middleware: H,
1212
): (...params: Parameters<H>) => Promise<ReturnType<H>> {
1313
return new Proxy(middleware, {
14-
apply: async (wrappingTarget, thisArg, args: Parameters<H>) => {
14+
apply: (wrappingTarget, thisArg, args: Parameters<H>) => {
1515
return withEdgeWrapping(wrappingTarget, {
1616
spanDescription: 'middleware',
1717
spanOp: 'middleware.nextjs',

packages/nextjs/src/server/wrapApiHandlerWithSentry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { autoEndTransactionOnResponseEnd, finishTransaction, flushQueue } from '
2626
*/
2727
export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameterizedRoute: string): NextApiHandler {
2828
return new Proxy(apiHandler, {
29-
apply: async (wrappingTarget, thisArg, args: Parameters<NextApiHandler>) => {
29+
apply: (wrappingTarget, thisArg, args: Parameters<NextApiHandler>) => {
3030
// eslint-disable-next-line deprecation/deprecation
3131
return withSentry(wrappingTarget, parameterizedRoute).apply(thisArg, args);
3232
},
@@ -49,7 +49,7 @@ export const withSentryAPI = wrapApiHandlerWithSentry;
4949
*/
5050
export function withSentry(apiHandler: NextApiHandler, parameterizedRoute?: string): NextApiHandler {
5151
return new Proxy(apiHandler, {
52-
apply: async (wrappingTarget, thisArg, args: [AugmentedNextApiRequest, AugmentedNextApiResponse]) => {
52+
apply: (wrappingTarget, thisArg, args: [AugmentedNextApiRequest, AugmentedNextApiResponse]) => {
5353
const [req, res] = args;
5454

5555
// We're now auto-wrapping API route handlers using `wrapApiHandlerWithSentry` (which uses `withSentry` under the hood), but

packages/nextjs/src/server/wrapDocumentGetInitialPropsWithSentry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function wrapDocumentGetInitialPropsWithSentry(
1919
origDocumentGetInitialProps: DocumentGetInitialProps,
2020
): DocumentGetInitialProps {
2121
return new Proxy(origDocumentGetInitialProps, {
22-
apply: async (wrappingTarget, thisArg, args: Parameters<DocumentGetInitialProps>) => {
22+
apply: (wrappingTarget, thisArg, args: Parameters<DocumentGetInitialProps>) => {
2323
if (isBuild()) {
2424
return wrappingTarget.apply(thisArg, args);
2525
}
@@ -41,7 +41,7 @@ export function wrapDocumentGetInitialPropsWithSentry(
4141
dataFetchingMethodName: 'getInitialProps',
4242
});
4343

44-
return await tracedGetInitialProps.apply(thisArg, args);
44+
return tracedGetInitialProps.apply(thisArg, args);
4545
} else {
4646
return errorWrappedGetInitialProps.apply(thisArg, args);
4747
}

packages/nextjs/src/server/wrapGetStaticPropsWithSentry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function wrapGetStaticPropsWithSentry(
1919
parameterizedRoute: string,
2020
): GetStaticProps<Props> {
2121
return new Proxy(origGetStaticPropsa, {
22-
apply: async (wrappingTarget, thisArg, args: Parameters<GetStaticProps<Props>>) => {
22+
apply: (wrappingTarget, thisArg, args: Parameters<GetStaticProps<Props>>) => {
2323
if (isBuild()) {
2424
return wrappingTarget.apply(thisArg, args);
2525
}

packages/replay/src/util/sendReplay.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function sendReplay(
5757
// will retry in intervals of 5, 10, 30
5858
retryConfig.interval *= ++retryConfig.count;
5959

60-
return await new Promise((resolve, reject) => {
60+
return new Promise((resolve, reject) => {
6161
setTimeout(async () => {
6262
try {
6363
await sendReplay(replayData, retryConfig);

packages/replay/test/integration/flush.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ describe('Integration | flush', () => {
135135

136136
it('long first flush enqueues following events', async () => {
137137
// Mock this to resolve after 20 seconds so that we can queue up following flushes
138-
mockAddPerformanceEntries.mockImplementationOnce(async () => {
139-
return await new Promise(resolve => setTimeout(resolve, 20000));
138+
mockAddPerformanceEntries.mockImplementationOnce(() => {
139+
return new Promise(resolve => setTimeout(resolve, 20000));
140140
});
141141

142142
expect(mockAddPerformanceEntries).not.toHaveBeenCalled();

packages/sveltekit/src/vite/svelteConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function getHooksFileName(svelteConfig: Config, hookType: 'client' | 'ser
5252
*/
5353
export async function getAdapterOutputDir(svelteConfig: Config, adapter: SupportedSvelteKitAdapters): Promise<string> {
5454
if (adapter === 'node') {
55-
return await getNodeAdapterOutputDir(svelteConfig);
55+
return getNodeAdapterOutputDir(svelteConfig);
5656
}
5757

5858
// Auto and Vercel adapters simply use config.kit.outDir

packages/utils/test/buildPolyfills/originals.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// the modified versions do the same thing the originals do.
33

44
// From Sucrase
5-
export async function _asyncNullishCoalesce(lhs, rhsFn) {
5+
export function _asyncNullishCoalesce(lhs, rhsFn) {
66
if (lhs != null) {
77
return lhs;
88
} else {
9-
return await rhsFn();
9+
return rhsFn();
1010
}
1111
}
1212

0 commit comments

Comments
 (0)