ClerkProvider mounts the `@clerk/ui` component renderer on every page load (~234 KB extra JS without any auth intent)

Abierto
#10,697 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
next.js, node.js, react, typescript

Línea de trabajo

Start by tracing the provider effects in @clerk/react and how __internal_updateProps and ensureMounted() interact in @clerk/clerk-js; the issue cites their published package files and the related fixes #4498, #4876, and #7901. Reproduce with a Next.js App Router page that has no Clerk components, then inspect the network chunks. Done means the renderer and billing chunks do not load on an idle page while mount*() and open*() still work as expected.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

With a plain <ClerkProvider> (Next.js App Router, UI loaded from the Clerk CDN, no ui prop), every page load
downloads and evaluates the full @clerk/ui renderer after v1/client, even if the page renders no Clerk component
and no modal is ever opened. We expected the renderer to mount on the first open*() / mount*() call.

Measured on a production app (signed out, no Clerk component on the page, transfer sizes):

Chunk Transfer
framework_ui_*_1.25.0.js 43 KB
ui-common_ui_*_1.25.0.js 122 KB
vendors_ui_*_1.25.0.js 64 KB
subscriptionDetails_ui_*_1.25.0.js 5 KB

That is ~234 KB on the wire, ~765 KB of raw JS to parse and evaluate on every page view, plus ui.browser.js itself.
subscriptionDetails is loaded although Clerk Billing is not used. With the bundled ui prop the same chunks load,
from the app bundle instead.

Versions
  • @clerk/nextjs 7.5.14, @clerk/react 6.12.0, @clerk/shared 4.25.0
  • @clerk/clerk-js 6.41.0 (CDN, @6), @clerk/ui 1.25.0 (CDN, version pinned)
  • Next.js 16.4.3, React 19.3.0
  • Same code paths in the latest versions as of 2026-11-05: @clerk/react 6.18.6, @clerk/clerk-js 6.42.3, @clerk/ui 1.42.4
Cause (code references in the published packages)
  1. @clerk/react 6.12.0, dist/ClerkProvider-GF8qvIpk.mjs:1544–1549: useLoadedIsomorphicClerk has two effects that
    call isomorphicClerk.__internal_updateProps(...), one for appearance and one for localization. They run on the
    first mount, even if the values equal the options already passed to clerk.load().
  2. @clerk/clerk-js 6.41.0 (dist/clerk.browser.js): __internal_updateProps always mounts first:
    return this.#eR?.then(e=>e.ensureMounted()).then(e=>e.updateProps(t)). This dates from #4498.
  3. @clerk/ui 1.25.0, dist/Components.js:34–42: the first ensureMounted() imports lazyModules/common.js
    (framework, ui-common, vendors) and renders Components.
  4. @clerk/ui 1.25.0, dist/Components.js:431–444 and dist/lazyModules/drawers.js: Components always renders
    MountedCheckoutDrawer, MountedPlanDetailDrawer and MountedSubscriptionDetailDrawer. They are React.lazy
    modules, so rendering them while closed loads the billing chunk.
Expected
  • __internal_updateProps called before the renderer is mounted should store the props and apply them on mount,
    instead of calling ensureMounted(). A similar early mount was fixed for the keyless prompt in #4876. #7901 already
    preloads component chunks on mount*() / open*(), so the first modal would not wait long.
  • The billing drawers should render only when opened, or only when Billing is enabled for the instance.
Steps to reproduce
  1. Create a Next.js App Router app and wrap the root layout in <ClerkProvider> (CDN UI, no ui prop). Pass
    localization or appearance, or none: the effects run on mount either way.
  2. Render a page without any Clerk component and do not interact with it.
  3. In the Network panel, after v1/client, the framework_ui_*, ui-common_ui_*, vendors_ui_* and
    subscriptionDetails_ui_* chunks load.
Related question: shared React variant

@clerk/react sets clerkUIVariant: "shared" for compatible React versions (ClerkProvider-GF8qvIpk.mjs:1536–1539),
and @clerk/ui ships dist/ui.shared.browser.js without its own React. The CDN loader in @clerk/shared 4.25.0
always requests dist/ui.browser.js (dist/loadClerkJsScript.js:141–149). We found no consumer of clerkUIVariant
in clerk.browser.js 6.41.0 or in ui.browser.js 1.25.0. As a result the CDN path always loads the variant with its
own React (framework_ui, ~43 KB). Is there a supported way to load the shared variant from the CDN, or is this
expected?

Thanks!

Lenguaje dominante
TypeScript
Estrellas
1.8k
Forks
492
Merge medio
1 d 8 h
PR fusionados (30 d)
374

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de clerk/javascript

Todos los issues de clerk/javascript

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.