Skip to content

chore: replace lodash.debounce with inline implementation#236

Open
roli-lpci wants to merge 2 commits intosplinetool:mainfrom
roli-lpci:chore/remove-lodash-debounce
Open

chore: replace lodash.debounce with inline implementation#236
roli-lpci wants to merge 2 commits intosplinetool:mainfrom
roli-lpci:chore/remove-lodash-debounce

Conversation

@roli-lpci
Copy link

Summary

  • Replace lodash.debounce runtime dependency with a small (~0.4KB) inline debounce utility
  • Supports the same leading option and .cancel() API used by ParentSize
  • Removes 3 packages from the dependency tree (lodash.debounce, @types/lodash.debounce, transitive deps)

Changes

  • src/debounce.ts — new inline debounce utility with TypeScript types
  • src/ParentSize.tsx — import changed from lodash.debounce to local ./debounce
  • package.json — removed lodash.debounce from dependencies, @types/lodash.debounce from devDependencies
  • vite.config.ts — removed lodash.debounce from rollup externals (now bundled inline at 0.38KB)

Testing

  • yarn build passes — all 5 modules transformed, clean output
  • yarn build-types passes — TypeScript declarations emit cleanly
  • Bundle size: debounce.js is 0.38KB (gzip: 0.22KB), smaller than the external lodash.debounce package

Replace lodash.debounce with a lightweight inline debounce utility,
removing the lodash.debounce and @types/lodash.debounce dependencies.

The inline implementation supports the same options used by ParentSize
(delay and leading), handles leading+trailing edge calls correctly,
provides cancel(), and resets state before invoking callbacks to
support re-entrant calls safely.

- New src/debounce.ts (0.46KB gzip vs external package)
- Updated ParentSize.tsx import
- Removed lodash.debounce from rollup externals in vite.config.ts
- Removed lodash.debounce + @types/lodash.debounce from package.json
@roli-lpci roli-lpci force-pushed the chore/remove-lodash-debounce branch from 907f6b8 to 0238061 Compare February 27, 2026 00:49
- Reset lastThis in cancel() to prevent memory leak when used in
  useEffect cleanup (captured component instance was never GC'd)
- Replace non-null assertion with defensive undefined guard
- Add JSDoc documenting supported/unsupported debounce features

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant