getsentry / getsentry/sentry-javascript

Support lazy-loading to keep the initial client bundle small (@sentry/nuxt)

Open
#16,700 1 comment 2 reactions 0 assignees View on GitHub
Feature Nuxt
Dominant language
TypeScript
Stars
8.7k
Forks
1.8k
Avg merge
1d 17h
Merged PRs (30d)
523

Description

### Problem Statement

The legacy Nuxt 2 module `@nuxtjs/sentry` exposed a `[lazy: true` option](https://sentry.nuxtjs.org/guide/lazy-loading/) that:
- removed the Sentry runtime from the default client bundle
- injected a mocked `$sentry` instance together with `$sentryReady()` / `$sentryLoad()` helpers so we could load Sentry on-demand (e.g. after user consent or on the first error)

In production this shaved 40 kB (gzipped) off the initial JS sent to every visitor, important for Core Web Vitals on mobile connections.

The current Nuxt 3 integration always ships the full SDK in the main bundle. For apps that need the SDK only after explicit user consent or once the user is authenticated this is avoidable overhead.

### Solution Brainstorm

It would be great if `@sentry/nuxt` could bring back first-class lazy-loading support, for example:

1. **Config flag**
```ts
// nuxt.config.ts
sentry: { lazy: true, /* … */ }
```

2. **Mocked API injection** (parity with Nuxt 2)
* Inject a lightweight proxy that queues calls until the real SDK is loaded.
* Expose `$sentryReady()` (Promise) and optionally `$sentryLoad()` to manually trigger the load.

3. **Route-level auto-loading**
Allow opting into SDK loading per-route via route rules or middleware so that public/landing pages remain lean.

4. **Vite split-chunk**
Generate a separate `sentry.client.js` chunk and load it dynamically so source-maps & release artifacts continue to work as today.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the current @sentry/nuxt integration alongside the legacy Nuxt 2 lazy-loading behavior described in the linked documentation. Use nuxt.config.ts, route rules or middleware, and the Vite split-chunk approach as the proposed integration points. Done should include an opt-in lazy mode that keeps the initial client bundle small while preserving the requested loading and mocked API behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript, vite
Domain
frontend, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.