:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(frontend): trim three frontend dependencies (#58121)
Georges-Antoine Assi15b10c0842d8
diff --git a/frontend/jest.setup.ts b/frontend/jest.setup.tsindex 94dc05a1ef97..e1ac44bca07a 100644--- a/frontend/jest.setup.ts+++ b/frontend/jest.setup.ts@@ -108,6 +108,14 @@ mockIntersectionObserver.mockReturnValue({});(globalThis as any).IntersectionObserver = mockIntersectionObserver+const mockResizeObserver = jest.fn()+mockResizeObserver.mockReturnValue({+ observe: () => null,+ unobserve: () => null,+ disconnect: () => null,+})+;(globalThis as any).ResizeObserver = mockResizeObserver+// Tell React Testing Library to use "data-attr" as the test ID attributeconfigure({ testIdAttribute: 'data-attr' })diff --git a/frontend/package.json b/frontend/package.jsonindex c1e7baf64c7f..810260156cab 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -161,7 +161,6 @@"@vapi-ai/web": "2.5.2","@vitejs/plugin-react": "^4.7.0","@xyflow/react": "^12.6.0",- "bintrees": "^1.0.2","bloommx": "^1.0.3","buffer": "^6.0.3","chart.js": "^4.5.1",@@ -207,7 +206,6 @@"kea-waitfor": "catalog:","kea-window-values": "catalog:","liquidjs": "^10.25.2",- "lodash.debounce": "^4.0.8","lodash.difference": "^4.5.0","lodash.merge": "^4.6.2","lodash.sortby": "^4.7.0",@@ -245,7 +243,6 @@"react-virtualized-auto-sizer": "^2.0.2","react-window": "^2.2.5","remark-gfm": "^4.0.0",- "resize-observer-polyfill": "^1.5.1","rrule": "^2.8.1","simple-statistics": "^7.8.8","snappy-wasm": "^0.3.0",@@ -271,7 +268,6 @@"@testing-library/jest-dom": "^5.17.0","@testing-library/react": "^14.3.1","@testing-library/user-event": "^14.6.1",- "@types/bintrees": "^1.0.6","@types/chartjs-plugin-crosshair": "^1.1.1","@types/chartjs-plugin-trendline": "^1.0.4","@types/clone": "^2.1.1",@@ -282,7 +278,6 @@"@types/image-blob-reduce": "^4.1.1","@types/jest": "catalog:","@types/jest-image-snapshot": "^6.1.0",- "@types/lodash.debounce": "^4.0.9","@types/lodash.difference": "^4.5.9","@types/lodash.merge": "^4.6.9","@types/lodash.sortby": "^4.7.9",diff --git a/frontend/src/lib/components/VerticalNestedDND/VerticalNestedDND.tsx b/frontend/src/lib/components/VerticalNestedDND/VerticalNestedDND.tsxindex 69ed5daa3129..3c309769c3ae 100644--- a/frontend/src/lib/components/VerticalNestedDND/VerticalNestedDND.tsx+++ b/frontend/src/lib/components/VerticalNestedDND/VerticalNestedDND.tsx@@ -27,9 +27,9 @@ import {import type { Transform } from '@dnd-kit/utilities'import { CSS } from '@dnd-kit/utilities'import equal from 'fast-deep-equal'-import debounce from 'lodash.debounce'-import React, { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react'+import React, { forwardRef, useCallback, useEffect, useRef, useState } from 'react'import { createPortal } from 'react-dom'+import { useDebouncedCallback } from 'use-debounce'import { IconTrash } from '@posthog/icons'@@ -88,16 +88,13 @@ export function VerticalNestedDND<ChildItem extends VDNDChildItem, Item extendsconst sensors = useSensors(useSensor(MouseSensor), useSensor(TouchSensor))const isSortingContainer = activeId ? containers.includes(activeId) : false- const debouncedOnChanged = useMemo(- () => (onChange ? debounce(onChange, 200, { trailing: true }) : undefined),- [onChange]- )+ const debouncedOnChanged = useDebouncedCallback((items: Item[]) => onChange?.(items), 200)const savedChanges = useRef<Item[]>(initialItems)useEffect(() => {const newItemsArray = containers.map((containerId) => items[containerId])if (!equal(newItemsArray, savedChanges.current)) {savedChanges.current = newItemsArray- debouncedOnChanged?.(newItemsArray)+ debouncedOnChanged(newItemsArray)}}, [containers, items, debouncedOnChanged])diff --git a/frontend/src/lib/hooks/useResizeObserver.ts b/frontend/src/lib/hooks/useResizeObserver.tsindex b46953e58516..28b28ea17c80 100644--- a/frontend/src/lib/hooks/useResizeObserver.ts+++ b/frontend/src/lib/hooks/useResizeObserver.ts@@ -1,12 +1,6 @@import { RefCallback, RefObject, useMemo, useState } from 'react'-import ResizeObserver from 'resize-observer-polyfill'import useResizeObserverImport from 'use-resize-observer'-// Use polyfill only if needed-if (!window.ResizeObserver) {- window.ResizeObserver = ResizeObserver-}-/** @deprecated Use CSS container or media queries instead. ResizeObserver use causes flapping of UI snapshots. */export const useResizeObserver = useResizeObserverImportdiff --git a/frontend/src/lib/utils/time-tree.ts b/frontend/src/lib/utils/time-tree.tsindex e9594f37ad8f..f11e85580638 100644--- a/frontend/src/lib/utils/time-tree.ts+++ b/frontend/src/lib/utils/time-tree.ts@@ -1,6 +1,5 @@-import { RBTree } from 'bintrees'-import { Dayjs } from 'lib/dayjs'+import { RBTree } from 'lib/utils/vendor/bintrees'export type TimeTreeComparable = {timestamp: Dayjsdiff --git a/frontend/src/lib/utils/vendor/bintrees/index.ts b/frontend/src/lib/utils/vendor/bintrees/index.tsnew file mode 100644index 000000000000..c538431ac266--- /dev/null+++ b/frontend/src/lib/utils/vendor/bintrees/index.ts@@ -0,0 +1,504 @@+// Vendored from [email protected] — https://github.com/vadimg/js_bintrees+// Ported to TypeScript with no algorithmic changes.+//+// Copyright (C) 2011 by Vadim Graboys+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++export type Comparator<T> = (a: T, b: T) => number+export type Callback<T> = (item: T) => void | boolean++class TreeNode<T> {+ data: T+ left: TreeNode<T> | null = null+ right: TreeNode<T> | null = null+ red: boolean = true++ constructor(data: T) {+ this.data = data+ }++ getChild(dir: boolean | 0 | 1): TreeNode<T> | null {+ return dir ? this.right : this.left+ }++ setChild(dir: boolean | 0 | 1, val: TreeNode<T> | null): void {+ if (dir) {+ this.right = val+ } else {+ this.left = val+ }+ }+}++function isRed<T>(node: TreeNode<T> | null): boolean {+ return node !== null && node.red+}++function singleRotate<T>(root: TreeNode<T>, dir: boolean | 0 | 1): TreeNode<T> {+ const save = root.getChild(!dir) as TreeNode<T>++ root.setChild(!dir, save.getChild(dir))+ save.setChild(dir, root)++ root.red = true+ save.red = false++ return save+}++function doubleRotate<T>(root: TreeNode<T>, dir: boolean | 0 | 1): TreeNode<T> {+ root.setChild(!dir, singleRotate(root.getChild(!dir) as TreeNode<T>, !dir))+ return singleRotate(root, dir)+}++export class Iterator<T> {+ private _tree: TreeBase<T>+ _ancestors: TreeNode<T>[] = []+ _cursor: TreeNode<T> | null = null++ constructor(tree: TreeBase<T>) {+ this._tree = tree+ }++ data(): T | null {+ return this._cursor !== null ? this._cursor.data : null+ }++ // if null-iterator, returns first node; otherwise next node+ next(): T | null {+ if (this._cursor === null) {+ const root = this._tree._root+ if (root !== null) {+ this._minNode(root)+ }+ } else {+ if (this._cursor.right === null) {+ let save: TreeNode<T> | null+ do {+ save = this._cursor+ if (this._ancestors.length) {+ this._cursor = this._ancestors.pop() as TreeNode<T>+ } else {+ this._cursor = null+ break+ }+ } while (this._cursor.right === save)+ } else {+ this._ancestors.push(this._cursor)+ this._minNode(this._cursor.right)+ }+ }+ return this._cursor !== null ? this._cursor.data : null+ }++ // if null-iterator, returns last node; otherwise previous node+ prev(): T | null {+ if (this._cursor === null) {+ const root = this._tree._root+ if (root !== null) {+ this._maxNode(root)+ }+ } else {+ if (this._cursor.left === null) {+ let save: TreeNode<T> | null+ do {+ save = this._cursor+ if (this._ancestors.length) {+ this._cursor = this._ancestors.pop() as TreeNode<T>+ } else {+ this._cursor = null+ break+ }+ } while (this._cursor.left === save)+ } else {+ this._ancestors.push(this._cursor)+ this._maxNode(this._cursor.left)+ }+ }+ return this._cursor !== null ? this._cursor.data : null+ }++ private _minNode(start: TreeNode<T>): void {+ while (start.left !== null) {+ this._ancestors.push(start)+ start = start.left+ }+ this._cursor = start+ }++ private _maxNode(start: TreeNode<T>): void {+ while (start.right !== null) {+ this._ancestors.push(start)+ start = start.right+ }+ this._cursor = start+ }+}++export abstract class TreeBase<T> {+ _root: TreeNode<T> | null = null+ _comparator: Comparator<T>+ size: number = 0++ constructor(comparator: Comparator<T>) {+ this._comparator = comparator+ }++ abstract insert(data: T): boolean+ abstract remove(data: T): boolean++ clear(): void {+ this._root = null+ this.size = 0+ }++ find(data: T): T | null {+ let res = this._root+ while (res !== null) {+ const c = this._comparator(data, res.data)+ if (c === 0) {+ return res.data+ }+ res = res.getChild(c > 0)+ }+ return null+ }++ findIter(data: T): Iterator<T> | null {+ let res = this._root+ const iter = this.iterator()++ while (res !== null) {+ const c = this._comparator(data, res.data)+ if (c === 0) {+ iter._cursor = res+ return iter+ }+ iter._ancestors.push(res)+ res = res.getChild(c > 0)+ }+ return null+ }++ // Returns an iterator at or immediately after the item+ lowerBound(item: T): Iterator<T> {+ let cur = this._root+ const iter = this.iterator()+ const cmp = this._comparator++ while (cur !== null) {+ const c = cmp(item, cur.data)+ if (c === 0) {+ iter._cursor = cur+ return iter+ }+ iter._ancestors.push(cur)+ cur = cur.getChild(c > 0)+ }++ for (let i = iter._ancestors.length - 1; i >= 0; --i) {+ cur = iter._ancestors[i]+ if (cmp(item, cur.data) < 0) {+ iter._cursor = cur+ iter._ancestors.length = i+ return iter+ }+ }++ iter._ancestors.length = 0+ return iter+ }++ // Returns an iterator immediately after the item+ upperBound(item: T): Iterator<T> {+ const iter = this.lowerBound(item)+ const cmp = this._comparator++ while (iter.data() !== null && cmp(iter.data() as T, item) === 0) {+ iter.next()+ }++ return iter+ }++ min(): T | null {+ let res = this._root+ if (res === null) {+ return null+ }+ while (res.left !== null) {+ res = res.left+ }+ return res.data+ }++ max(): T | null {+ let res = this._root+ if (res === null) {+ return null+ }+ while (res.right !== null) {+ res = res.right+ }+ return res.data+ }++ iterator(): Iterator<T> {+ return new Iterator<T>(this)+ }++ each(cb: Callback<T>): void {+ const it = this.iterator()+ let data: T | null+ while ((data = it.next()) !== null) {+ if (cb(data) === false) {+ return+ }+ }+ }++ reach(cb: Callback<T>): void {+ const it = this.iterator()+ let data: T | null+ while ((data = it.prev()) !== null) {+ if (cb(data) === false) {+ return+ }+ }+ }+}++export class RBTree<T> extends TreeBase<T> {+ constructor(comparator: Comparator<T>) {+ super(comparator)+ }++ // returns true if inserted, false if duplicate+ insert(data: T): boolean {+ let ret = false++ if (this._root === null) {+ this._root = new TreeNode<T>(data)+ ret = true+ this.size+++ } else {+ const head = new TreeNode<T>(undefined as unknown as T) // fake tree root++ let dir: boolean | 0 | 1 = 0+ let last: boolean | 0 | 1 = 0++ let gp: TreeNode<T> | null = null // grandparent+ let ggp: TreeNode<T> = head // grand-grand-parent+ let p: TreeNode<T> | null = null // parent+ let node: TreeNode<T> | null = this._root+ ggp.right = this._root++ while (true) {+ if (node === null) {+ node = new TreeNode<T>(data)+ ;(p as TreeNode<T>).setChild(dir, node)+ ret = true+ this.size+++ } else if (isRed(node.left) && isRed(node.right)) {+ node.red = true+ ;(node.left as TreeNode<T>).red = false+ ;(node.right as TreeNode<T>).red = false+ }++ if (isRed(node) && isRed(p)) {+ const dir2 = ggp.right === gp++ if (node === (p as TreeNode<T>).getChild(last)) {+ ggp.setChild(dir2, singleRotate(gp as TreeNode<T>, !last))+ } else {+ ggp.setChild(dir2, doubleRotate(gp as TreeNode<T>, !last))+ }+ }++ const cmp = this._comparator(node.data, data)++ if (cmp === 0) {+ break+ }++ last = dir+ dir = cmp < 0 ? 1 : 0++ if (gp !== null) {+ ggp = gp+ }+ gp = p+ p = node+ node = node.getChild(dir)+ }++ this._root = head.right+ }++ ;(this._root as TreeNode<T>).red = false++ return ret+ }++ // returns true if removed, false if not found+ remove(data: T): boolean {+ if (this._root === null) {+ return false+ }++ const head = new TreeNode<T>(undefined as unknown as T) // fake tree root+ let node: TreeNode<T> = head+ node.right = this._root+ let p: TreeNode<T> | null = null+ let gp: TreeNode<T> | null = null+ let found: TreeNode<T> | null = null+ let dir: boolean | 0 | 1 = 1++ while (node.getChild(dir) !== null) {+ const last = dir++ gp = p+ p = node+ node = node.getChild(dir) as TreeNode<T>++ const cmp = this._comparator(data, node.data)++ dir = cmp > 0 ? 1 : 0++ if (cmp === 0) {+ found = node+ }++ if (!isRed(node) && !isRed(node.getChild(dir))) {+ if (isRed(node.getChild(!dir))) {+ const sr = singleRotate(node, dir)+ ;(p as TreeNode<T>).setChild(last, sr)+ p = sr+ } else if (!isRed(node.getChild(!dir))) {+ const sibling = (p as TreeNode<T>).getChild(!last)+ if (sibling !== null) {+ if (!isRed(sibling.getChild(!last)) && !isRed(sibling.getChild(last))) {+ ;(p as TreeNode<T>).red = false+ sibling.red = true+ node.red = true+ } else {+ const dir2 = (gp as TreeNode<T>).right === p++ if (isRed(sibling.getChild(last))) {+ ;(gp as TreeNode<T>).setChild(dir2, doubleRotate(p as TreeNode<T>, last))+ } else if (isRed(sibling.getChild(!last))) {+ ;(gp as TreeNode<T>).setChild(dir2, singleRotate(p as TreeNode<T>, last))+ }++ const gpc = (gp as TreeNode<T>).getChild(dir2) as TreeNode<T>+ gpc.red = true+ node.red = true+ ;(gpc.left as TreeNode<T>).red = false+ ;(gpc.right as TreeNode<T>).red = false+ }+ }+ }+ }+ }++ if (found !== null) {+ found.data = node.data+ ;(p as TreeNode<T>).setChild((p as TreeNode<T>).right === node, node.getChild(node.left === null))+ this.size--+ }++ this._root = head.right+ if (this._root !== null) {+ this._root.red = false+ }++ return found !== null+ }+}++export class BinTree<T> extends TreeBase<T> {+ constructor(comparator: Comparator<T>) {+ super(comparator)+ }++ insert(data: T): boolean {+ if (this._root === null) {+ this._root = new TreeNode<T>(data)+ this.size+++ return true+ }++ let dir: boolean | 0 | 1 = 0+ let p: TreeNode<T> | null = null+ let node: TreeNode<T> | null = this._root++ while (true) {+ if (node === null) {+ node = new TreeNode<T>(data)+ ;(p as TreeNode<T>).setChild(dir, node)+ this.size+++ return true+ }++ if (this._comparator(node.data, data) === 0) {+ return false+ }++ dir = this._comparator(node.data, data) < 0 ? 1 : 0++ p = node+ node = node.getChild(dir)+ }+ }++ remove(data: T): boolean {+ if (this._root === null) {+ return false+ }++ const head = new TreeNode<T>(undefined as unknown as T)+ let node: TreeNode<T> = head+ node.right = this._root+ let p: TreeNode<T> | null = null+ let found: TreeNode<T> | null = null+ let dir: boolean | 0 | 1 = 1++ while (node.getChild(dir) !== null) {+ p = node+ node = node.getChild(dir) as TreeNode<T>+ const cmp = this._comparator(data, node.data)+ dir = cmp > 0 ? 1 : 0++ if (cmp === 0) {+ found = node+ }+ }++ if (found !== null) {+ found.data = node.data+ ;(p as TreeNode<T>).setChild((p as TreeNode<T>).right === node, node.getChild(node.left === null))++ this._root = head.right+ this.size--+ return true+ }+ return false+ }+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex b047fe149d83..9a5be46d4a4d 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -874,9 +874,6 @@ importers:'@xyflow/react':specifier: ^12.6.0version: 12.6.0(@types/[email protected])([email protected])([email protected]([email protected]))([email protected])- bintrees:- specifier: ^1.0.2- version: 1.0.2bloommx:specifier: ^1.0.3version: 1.0.3@@ -1012,9 +1009,6 @@ importers:liquidjs:specifier: ^10.25.2version: 10.25.2- lodash.debounce:- specifier: ^4.0.8- version: 4.0.8lodash.difference:specifier: ^4.5.0version: 4.5.0@@ -1126,9 +1120,6 @@ importers:remark-gfm:specifier: ^4.0.0version: 4.0.1- resize-observer-polyfill:- specifier: ^1.5.1- version: 1.5.1rrule:specifier: ^2.8.1version: 2.8.1@@ -1196,9 +1187,6 @@ importers:'@testing-library/user-event':specifier: ^14.6.1version: 14.6.1(@testing-library/[email protected])- '@types/bintrees':- specifier: ^1.0.6- version: 1.0.6'@types/chartjs-plugin-crosshair':specifier: ^1.1.1version: 1.1.4@@ -1229,9 +1217,6 @@ importers:'@types/jest-image-snapshot':specifier: ^6.1.0version: 6.1.0- '@types/lodash.debounce':- specifier: ^4.0.9- version: 4.0.9'@types/lodash.difference':specifier: ^4.5.9version: 4.5.9@@ -11895,9 +11880,6 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q==}- '@types/[email protected]':- resolution: {integrity: sha512-pZWT4Bz+tWwxlDspSjdoIza4PE5lbGI4Xvs3FZV/2v5m5SDA8LwNpU8AXxlndmARO7OaQ1Vf3zFenOsNMzaRkQ==}-'@types/[email protected]':resolution: {integrity: sha512-yR/Kxc0dd4FfwtEoLZMoqJbM/VE/W7hXn/MIjb+axcwag0iFmSPK7OBUZq1YWLynJUoWQkfUrI7T0HDqGApNSg==}@@ -12222,9 +12204,6 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==}- '@types/[email protected]':- resolution: {integrity: sha512-Ma5JcgTREwpLRwMM+XwBR7DaWe96nC38uCBDFKZWbNKD+osjVzdpnUSwBcqCptrp16sSOLBAUb50Car5I0TCsQ==}-'@types/[email protected]':resolution: {integrity: sha512-MNlajcjtwzLpXk+cw38UkBvEXJNEPhULgS8A4EHwtUwT7f7yFH/SFKD0iw5Rfilwh60yJIgFo0vsMr7xsa5+aw==}@@ -35781,8 +35760,6 @@ snapshots:dependencies:'@babel/types': 7.29.0- '@types/[email protected]': {}-'@types/[email protected]': {}'@types/[email protected]':@@ -36160,10 +36137,6 @@ snapshots:'@types/[email protected]': {}- '@types/[email protected]':- dependencies:- '@types/lodash': 4.17.13-'@types/[email protected]':dependencies:'@types/lodash': 4.17.16