Skip to content

chore(shared): replace telemetry postinstall with runtime notice#8549

Open
jacekradko wants to merge 6 commits into
mainfrom
jacek/sdk-84-remove-telemetry-postinstall-notice
Open

chore(shared): replace telemetry postinstall with runtime notice#8549
jacekradko wants to merge 6 commits into
mainfrom
jacek/sdk-84-remove-telemetry-postinstall-notice

Conversation

@jacekradko
Copy link
Copy Markdown
Member

@jacekradko jacekradko commented May 14, 2026

NOT READY FOR REVIEW YET!

Moves the one-time telemetry disclosure off the postinstall lifecycle script and into the TelemetryCollector itself. The same notice now fires at runtime the first time telemetry activates on a development instance, gated on CI, headless, and the existing opt-out signals. The Node persistence marker reuses the prior env-paths location so anyone who already saw the postinstall notice will not see it again. Drops the std-env dependency and removes install-time code from the published package, which addresses the supply-chain concern raised in #8540.

Resolves SDK-84.

Move the one-time telemetry disclosure off of npm lifecycle scripts and into the
TelemetryCollector itself. Surfacing it at runtime instead of install time keeps
@clerk/shared free of postinstall code, drops the std-env dependency, and only
shows the notice in environments where telemetry actually fires. The Node
persistence marker reuses the prior env-paths location, so users who already
saw the notice via postinstall will not see it again.

Resolves SDK-84.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

🦋 Changeset detected

Latest commit: 9e5fe52

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@clerk/shared Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/react Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment May 15, 2026 3:09am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 14, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The postinstall telemetry script and the std-env dependency were removed from @clerk/shared and published files narrowed to dist. A new Node-only, synchronous maybeShowTelemetryNotice(options?) was added that detects CI/browser, prints a one-time terminal notice deduped per process via a global Symbol, and swallows errors. TelemetryCollector now invokes the notice at construction. A Vitest suite was added to validate gating, dedupe, skip behavior, CI/browser suppression, and error resilience.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: replacing the telemetry postinstall script with a runtime notice mechanism.
Description check ✅ Passed The description is well-related to the changeset, explaining the migration from postinstall to runtime disclosure, dependency removal, and supply-chain improvements.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@brkalow
Copy link
Copy Markdown
Member

brkalow commented May 14, 2026

@jacekradko my hunch is that this is going to trigger more than desired in the browser, and we'll get requests to disable the warning altogether similar to what happened with the dev mode warning. How can we get ahead of that? 🤔

@clerk/ui re-bundles @clerk/shared with Rspack, which does not handle bare
`node:` URI imports even when they are only reachable on a Node runtime.
Route the dynamic imports through a `new Function('id', 'return import(id)')`
indirection so the module specifiers are no longer visible to static
analysis. Also apply prettier to the new spec file.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8549

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8549

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8549

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8549

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8549

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8549

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8549

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8549

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8549

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8549

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8549

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8549

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8549

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8549

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8549

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8549

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8549

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8549

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8549

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8549

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8549

commit: 9e5fe52

Next.js Edge Runtime forbids `new Function`/`eval` even in unreachable code,
so the dynamic-import-evasion trick used to hide `node:` module specifiers
from webpack tripped the edge analyzer when @clerk/shared was reached through
@clerk/nextjs middleware. Replace the Node config-file persistence with a
`globalThis` Symbol flag (browser still uses localStorage). The notice now
shows at most once per process on Node and once per machine in the browser,
with no filesystem access and no dynamic-code APIs anywhere in the bundle.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/shared/src/telemetry/notice.ts`:
- Around line 66-75: hasSeen() currently returns early if
hasUsableLocalStorage() is true even when localStorage.getItem throws, so the
process-level dedupe (PROCESS_FLAG) never gets consulted; update hasSeen() to
attempt reading localStorage in a try/catch and on exception fall back to
returning the boolean value of (globalThis as Record<symbol,
unknown>)[PROCESS_FLAG] instead of false. Also adjust markSeen() so when writing
to localStorage throws it sets PROCESS_FLAG as the fallback; reference
STORAGE_KEY, PROCESS_FLAG, hasUsableLocalStorage(), hasSeen(), and markSeen()
when making these changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: f335de7c-4216-4858-aabd-2ebf30fd08e7

📥 Commits

Reviewing files that changed from the base of the PR and between 6592f97 and 8d23466.

📒 Files selected for processing (4)
  • .changeset/sdk-84-remove-telemetry-postinstall.md
  • packages/shared/src/__tests__/telemetry.notice.spec.ts
  • packages/shared/src/telemetry/collector.ts
  • packages/shared/src/telemetry/notice.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/sdk-84-remove-telemetry-postinstall.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/shared/src/telemetry/collector.ts
  • packages/shared/src/tests/telemetry.notice.spec.ts

Comment thread packages/shared/src/telemetry/notice.ts
@jacekradko
Copy link
Copy Markdown
Member Author

@brkalow I think you are right. It's tricky in the browser. Are we ok with this only on the server?

Browser consoles are observed by non-developers (QA, screenshots, demos), so
adding another runtime warning there invites the same complaints we get about
the existing dev-mode banner. Drop the browser surface entirely and emit the
disclosure only on Node, matching the noise profile of the original postinstall
(terminal-only, dev-eyes-only). Persistence simplifies to a single per-process
globalThis flag; the localStorage path and the bug it had around getItem
exceptions both go away.
The Next.js Edge Runtime build-time analyzer flags any reachable read of
process.versions even when guarded — this caused a warning when @clerk/backend
was reached through middleware, which the next-build integration test asserts
against. Detect Edge Runtime via its standard `EdgeRuntime` global instead, and
use the absence of `window`+`EdgeRuntime` as the positive signal for "server
runtime" without touching process.versions at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants