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

Đang mở
#10,697 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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!

Ngôn ngữ chính
TypeScript
Star
1.8k
Fork
492
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
374

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của clerk/javascript

Tất cả issue của clerk/javascript

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.