Skip to content

fix(utils): prevent false positive multiple instances warning in dev mode#7933

Merged
steveruizok merged 2 commits intomainfrom
fix/false-positive-multiple-instances-warning
Mar 10, 2026
Merged

fix(utils): prevent false positive multiple instances warning in dev mode#7933
steveruizok merged 2 commits intomainfrom
fix/false-positive-multiple-instances-warning

Conversation

@steveruizok
Copy link
Copy Markdown
Collaborator

@steveruizok steveruizok commented Feb 14, 2026

In order to fix a false positive "multiple instances" warning that fires in Next.js dev mode, this PR deduplicates registrations in registerTldrawLibraryVersion().

When Next.js re-evaluates modules on page refresh, each tldraw package re-registers itself via registerTldrawLibraryVersion(). Since globalThis.__TLDRAW_LIBRARY_VERSIONS__ persists across module re-evaluations, duplicate entries accumulate and trigger the "multiple instances" warning — even though only one copy of each library is loaded (all entries show the same version and same module type).

The fix skips registration when an identical entry (same name, version, and module type) already exists. Genuine conflicts (different versions or mixed ESM/CJS) are still detected correctly.

Closes #4614

Change type

  • bugfix

Test plan

  1. Use tldraw in a Next.js app with dev mode
  2. Refresh the page — the false "multiple instances" warning should no longer appear
  3. Genuine version mismatches or ESM/CJS conflicts should still produce warnings
  • Unit tests

Release notes

  • Fixed false positive "multiple instances" warning in Next.js dev mode caused by module re-evaluation

Note

Low Risk
Small, well-scoped change to warning/dedup logic gated to Next.js dev mode with unit test coverage; main risk is inadvertently suppressing a real duplicate only under those conditions.

Overview
Prevents false "multiple instances" warnings in Next.js dev mode by skipping re-registration when registerTldrawLibraryVersion sees an exact duplicate entry (same package, version, and module type) during Fast Refresh.

Adds isNextjsDev() gating (checks NODE_ENV === 'development' and presence of __NEXT_DATA__) so duplicate tracking and warnings still occur in non-Next.js environments, and updates tests to cover both the Next.js dev dedupe behavior and the unchanged non-dev duplicate warning.

Written by Cursor Bugbot for commit cc920c0. This will update automatically on new commits. Configure here.

…mode

In Next.js dev mode, module re-evaluation causes each tldraw package to
re-register itself via registerTldrawLibraryVersion(), but globalThis
persists across re-evaluations. This leads to duplicate entries that
trigger a spurious "multiple instances" warning even though only one
copy of each library is actually loaded.

Deduplicate registrations by skipping entries where the same name,
version, and module type are already recorded. Genuine conflicts
(different versions or mixed ESM/CJS) are still detected.

Closes #4614
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 14, 2026

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

Project Deployment Actions Updated (UTC)
examples Ready Ready Preview Mar 10, 2026 4:36pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
analytics Ignored Ignored Mar 10, 2026 4:36pm
chat-template Ignored Ignored Mar 10, 2026 4:36pm
tldraw-docs Ignored Ignored Mar 10, 2026 4:36pm
tldraw-shader Ignored Ignored Mar 10, 2026 4:36pm
workflow-template Ignored Ignored Mar 10, 2026 4:36pm

Request Review

@huppy-bot huppy-bot bot added the bugfix Bug fix label Feb 14, 2026
@steveruizok steveruizok requested a review from ds300 February 14, 2026 22:47
Avoid false-positive multiple-instance warnings caused by Next.js Fast Refresh re-executing module code. Add an isNextjsDev() helper and only skip exact duplicate registrations when running in Next.js development mode (process.env.NODE_ENV === 'development' and global __NEXT_DATA__ present). Update tests to stub __NEXT_DATA__, toggle NODE_ENV and restore it, and add a new test that verifies duplicates still trigger a warning outside Next.js dev mode. Files changed: packages/utils/src/lib/version.ts, packages/utils/src/lib/version.test.ts.
@steveruizok steveruizok added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit 316fca2 Mar 10, 2026
19 of 20 checks passed
@steveruizok steveruizok deleted the fix/false-positive-multiple-instances-warning branch March 10, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple instances error after upgrading to v3

2 participants