diff --git a/knip.json b/knip.json index 6b0e9046d..fff9533bc 100644 --- a/knip.json +++ b/knip.json @@ -1,6 +1,6 @@ { "$schema": "https://unpkg.com/knip@6/schema.json", - "entry": ["src/sw.ts", "scripts/**/*.js"], + "entry": ["scripts/**/*.js"], "ignore": ["src/test/choochmeque-notifications-stub.ts"], "ignoreExportsUsedInFile": { "interface": true, diff --git a/package.json b/package.json index dcb8c2406..2f0fe64a9 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@lottiefiles/dotlottie-react": "^0.19.10", "@noble/hashes": "^2.2.0", "@phosphor-icons/react": "^2.1.10", + "@rolldown/plugin-node-polyfills": "^1.0.3", "@sableclient/twemoji-font": "^1.0.4", "@sentry/react": "^10.67.0", "@tanstack/react-query": "^5.101.3", @@ -121,7 +122,6 @@ }, "devDependencies": { "@cloudflare/vite-plugin": "^1.45.1", - "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@playwright/test": "^1.61.1", "@rollup/plugin-inject": "^5.0.5", "@rollup/plugin-wasm": "^6.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4750b45f0..49576897c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -52,6 +52,9 @@ importers: '@phosphor-icons/react': specifier: ^2.1.10 version: 2.1.10(react-dom@19.2.8(react@19.2.8))(react@19.2.8) + '@rolldown/plugin-node-polyfills': + specifier: ^1.0.3 + version: 1.0.3 '@sableclient/twemoji-font': specifier: ^1.0.4 version: 1.0.4 @@ -263,9 +266,6 @@ importers: '@cloudflare/vite-plugin': specifier: ^1.45.1 version: 1.49.0(vite@8.2.0(@types/node@24.13.2)(esbuild@0.28.1)(jiti@2.7.0)(terser@5.49.0)(yaml@2.9.0))(wrangler@4.116.0) - '@esbuild-plugins/node-globals-polyfill': - specifier: ^0.2.3 - version: 0.2.3(esbuild@0.28.1) '@playwright/test': specifier: ^1.61.1 version: 1.62.1 @@ -1060,11 +1060,6 @@ packages: '@emotion/hash@0.9.2': resolution: {integrity: sha512-MyqliTZGuOm3+5ZRSaaBGP3USLw6+EGykkwZns2EPC5g8jJ4z9OrdZY9apkl3+UP9+sdz76YYkwCKP5gh8iY3g==} - '@esbuild-plugins/node-globals-polyfill@0.2.3': - resolution: {integrity: sha512-r3MIryXDeXDOZh7ih1l/yE9ZLORCd5e8vWg02azWRGj5SPTuoh69A2AIyn0Z31V/kHBfZ4HgWJ+OK3GTTwLmnw==} - peerDependencies: - esbuild: '>=0.25.0' - '@esbuild/aix-ppc64@0.28.1': resolution: {integrity: sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==} engines: {node: '>=18'} @@ -2231,6 +2226,9 @@ packages: cpu: [x64] os: [win32] + '@rolldown/plugin-node-polyfills@1.0.3': + resolution: {integrity: sha512-V7iWE6UI+InppK51NfuHlaCpep7Rzv4w92pZif6BtRP3ULDHfQjU6HNyIS41Plrx1tqzcANcAsnjDS6ye+1kFQ==} + '@rolldown/pluginutils@1.0.1': resolution: {integrity: sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==} @@ -6494,10 +6492,6 @@ snapshots: '@emotion/hash@0.9.2': {} - '@esbuild-plugins/node-globals-polyfill@0.2.3(esbuild@0.28.1)': - dependencies: - esbuild: 0.28.1 - '@esbuild/aix-ppc64@0.28.1': optional: true @@ -7217,6 +7211,8 @@ snapshots: '@rolldown/binding-win32-x64-msvc@1.2.1': optional: true + '@rolldown/plugin-node-polyfills@1.0.3': {} + '@rolldown/pluginutils@1.0.1': {} '@rollup/plugin-babel@6.1.0(@babel/core@7.29.7)(rollup@4.62.3)': diff --git a/src/app/components/MobileSwipeDownModal.tsx b/src/app/components/MobileSwipeDownModal.tsx index 77b0a580c..d7b940c66 100644 --- a/src/app/components/MobileSwipeDownModal.tsx +++ b/src/app/components/MobileSwipeDownModal.tsx @@ -1,4 +1,4 @@ -import type { ComponentProps, CSSProperties, RefObject } from "react"; +import type { ComponentProps, CSSProperties, RefObject } from 'react'; import React, { createContext, useCallback, @@ -6,22 +6,22 @@ import React, { useLayoutEffect, useRef, useState, -} from "react"; -import { createPortal } from "react-dom"; -import { Box } from "folds"; -import FocusTrap from "focus-trap-react"; -import { useDrag } from "@use-gesture/react"; -import * as css from "$features/room/message/styles.css"; -import { useDismissOnBack } from "$utils/androidBack"; -import { stopPropagation } from "$utils/keyboard"; -import { getMobileSheetTiming, useMobileSheetAnimation } from "./mobileSheetAnimation"; -import { MOBILE_SHEET_DURATION_MS, MOBILE_SHEET_EASING } from "./mobileSheetAnimationConstants"; -import * as animationCss from "./mobileSheetAnimation.css"; +} from 'react'; +import { createPortal } from 'react-dom'; +import { Box } from 'folds'; +import { FocusTrap } from 'focus-trap-react'; +import { useDrag } from '@use-gesture/react'; +import * as css from '$features/room/message/styles.css'; +import { useDismissOnBack } from '$utils/androidBack'; +import { stopPropagation } from '$utils/keyboard'; +import { getMobileSheetTiming, useMobileSheetAnimation } from './mobileSheetAnimation'; +import { MOBILE_SHEET_DURATION_MS, MOBILE_SHEET_EASING } from './mobileSheetAnimationConstants'; +import * as animationCss from './mobileSheetAnimation.css'; interface MobileSwipeDownModalProps { children: () => React.ReactNode; requestClose: () => void; - containerRef?: RefObject; + containerRef?: RefObject; focusTrap?: boolean; dialogLabel?: string; skipReturnFocusRef?: RefObject; @@ -30,7 +30,7 @@ interface MobileSwipeDownModalProps { keyboardAware?: boolean; } -type FocusTrapOptions = ComponentProps["focusTrapOptions"]; +type FocusTrapOptions = ComponentProps['focusTrapOptions']; const MobileSheetCloseContext = createContext<(() => void) | null>(null); @@ -42,8 +42,8 @@ const DISMISS_VELOCITY = 0.5; /** Keeps a fling that lands at the top of a list from turning into a sheet drag. */ const DRAG_BLOCKED_COOLDOWN_MS = 200; -const HANDLE_ATTRIBUTE = "data-mobile-sheet-handle"; -const NO_DRAG_ATTRIBUTE = "data-mobile-sheet-no-drag"; +const HANDLE_ATTRIBUTE = 'data-mobile-sheet-handle'; +const NO_DRAG_ATTRIBUTE = 'data-mobile-sheet-no-drag'; function getKeyboardOverlap(): number { const viewport = window.visualViewport; @@ -57,7 +57,7 @@ function findScroller(from: HTMLElement | null, boundary: HTMLElement): HTMLElem while (element && element !== boundary) { const { overflowY } = window.getComputedStyle(element); if ( - (overflowY === "auto" || overflowY === "scroll") && + (overflowY === 'auto' || overflowY === 'scroll') && element.scrollHeight > element.clientHeight ) { return element; @@ -123,15 +123,15 @@ export function MobileSwipeDownModal({ sheet.style.transition = animate && !shouldReduceMotion ? `transform ${MOBILE_SHEET_DURATION_MS}ms ${MOBILE_SHEET_EASING}` - : ""; - sheet.style.transform = y === 0 ? "" : `translate3d(0, ${y}px, 0)`; + : ''; + sheet.style.transform = y === 0 ? '' : `translate3d(0, ${y}px, 0)`; // Once lifted above the keyboard the bottom inset is no longer a safe area. sheet.style.setProperty( - "--mobile-sheet-safe-bottom", - keyboardOffset.current > 0 ? "0px" : "", + '--mobile-sheet-safe-bottom', + keyboardOffset.current > 0 ? '0px' : '' ); }, - [shouldReduceMotion], + [shouldReduceMotion] ); useLayoutEffect(() => { @@ -144,7 +144,7 @@ export function MobileSwipeDownModal({ const next = Math.max(stableViewportHeight, window.innerHeight); if (next === stableViewportHeight) return; stableViewportHeight = next; - sheetRef.current?.style.setProperty("--mobile-sheet-viewport", `${next}px`); + sheetRef.current?.style.setProperty('--mobile-sheet-viewport', `${next}px`); }; // The two viewports shrink in separate stages. Mid-way the visual one alone @@ -157,7 +157,7 @@ export function MobileSwipeDownModal({ if (closingRef.current) return; publishViewportHeight(); const visible = window.visualViewport?.height ?? window.innerHeight; - sheetRef.current?.style.setProperty("--mobile-sheet-visible", `${visible}px`); + sheetRef.current?.style.setProperty('--mobile-sheet-visible', `${visible}px`); const next = getKeyboardOverlap(); if (next === keyboardOffset.current) return; @@ -181,19 +181,19 @@ export function MobileSwipeDownModal({ const viewport = window.visualViewport; applySettled(); - window.addEventListener("resize", handleViewportChange); - window.addEventListener("scroll", handleViewportChange); - window.addEventListener("orientationchange", handleOrientationChange); - viewport?.addEventListener("resize", handleViewportChange); - viewport?.addEventListener("scroll", handleViewportChange); + window.addEventListener('resize', handleViewportChange); + window.addEventListener('scroll', handleViewportChange); + window.addEventListener('orientationchange', handleOrientationChange); + viewport?.addEventListener('resize', handleViewportChange); + viewport?.addEventListener('scroll', handleViewportChange); return () => { window.clearTimeout(settleTimer); - window.removeEventListener("resize", handleViewportChange); - window.removeEventListener("scroll", handleViewportChange); - window.removeEventListener("orientationchange", handleOrientationChange); - viewport?.removeEventListener("resize", handleViewportChange); - viewport?.removeEventListener("scroll", handleViewportChange); + window.removeEventListener('resize', handleViewportChange); + window.removeEventListener('scroll', handleViewportChange); + window.removeEventListener('orientationchange', handleOrientationChange); + viewport?.removeEventListener('resize', handleViewportChange); + viewport?.removeEventListener('scroll', handleViewportChange); }; }, [keyboardAware, applySheetOffset]); @@ -209,16 +209,16 @@ export function MobileSwipeDownModal({ } container.getAnimations().forEach((animation) => animation.cancel()); - container.style.transition = ""; + container.style.transition = ''; const startY = touchYDiff.current - keyboardOffset.current; const animation = container.animate( - [{ transform: `translate3d(0, ${startY}px, 0)` }, { transform: "translate3d(0, 100%, 0)" }], + [{ transform: `translate3d(0, ${startY}px, 0)` }, { transform: 'translate3d(0, 100%, 0)' }], { ...getMobileSheetTiming(shouldReduceMotion), duration: shouldReduceMotion ? 0 : 140, - }, + } ); - animation.addEventListener("finish", requestClose, { once: true }); + animation.addEventListener('finish', requestClose, { once: true }); }, [requestClose, shouldReduceMotion]); // Android back closes the overlay instead of navigating away. @@ -285,10 +285,10 @@ export function MobileSwipeDownModal({ target: sheetRef, eventOptions: { passive: false }, pointer: { capture: false, touch: true }, - axis: "y", + axis: 'y', // MobileMenuItem owns tap activation for marked actions; the sheet owns drag arbitration. filterTaps: false, - }, + } ); // A sheet opened by a long press mounts under the finger, and releasing it @@ -296,7 +296,7 @@ export function MobileSwipeDownModal({ // backdrop is a dismiss. const handleBackdropClick = (e: React.MouseEvent) => { const fromTouch = - e.nativeEvent instanceof PointerEvent && e.nativeEvent.pointerType === "touch"; + e.nativeEvent instanceof PointerEvent && e.nativeEvent.pointerType === 'touch'; if (fromTouch && !backdropTouchRef.current) return; closeWithAnimation(); }; @@ -306,7 +306,7 @@ export function MobileSwipeDownModal({ className={css.MessageMobileDragHandle} data-gestures="ignore" data-testid="mobile-sheet-drag-handle" - {...{ [HANDLE_ATTRIBUTE]: "" }} + {...{ [HANDLE_ATTRIBUTE]: '' }} >
@@ -326,7 +326,7 @@ export function MobileSwipeDownModal({ fallbackFocus: () => sheetRef.current ?? target, preventScroll: true, returnFocusOnDeactivate: true, - setReturnFocus: (previousActiveElement: HTMLElement) => + setReturnFocus: (previousActiveElement: HTMLElement | SVGElement) => skipReturnFocusRef?.current ? false : previousActiveElement, allowOutsideClick: true, clickOutsideDeactivates: false, @@ -356,10 +356,10 @@ export function MobileSwipeDownModal({ return createPortal( e.stopPropagation()} onPointerMove={(e: React.PointerEvent) => e.stopPropagation()} onPointerUp={(e: React.PointerEvent) => e.stopPropagation()} @@ -386,6 +386,6 @@ export function MobileSwipeDownModal({
{dialog}
, - target, + target ); } diff --git a/vite.config.ts b/vite.config.ts index 14e7a2fe3..a986f6adb 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -6,7 +6,7 @@ import svgr from 'vite-plugin-svgr'; import { wasm } from '@rollup/plugin-wasm'; import { viteStaticCopy } from 'vite-plugin-static-copy'; import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin'; -import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'; +import nodePolyfills from '@rolldown/plugin-node-polyfills'; import inject from '@rollup/plugin-inject'; import { VitePWA } from 'vite-plugin-pwa'; import { compression, defineAlgorithm } from 'vite-plugin-compression2'; @@ -280,17 +280,13 @@ export default defineConfig(({ command }) => { '@vanilla-extract/recipes/createRuntimeFn', ], needsInterop: ['matrix-widget-api'], - esbuildOptions: { - define: { - global: 'globalThis', + rolldownOptions: { + transform: { + define: { + global: 'globalThis', + }, }, - plugins: [ - // Enable esbuild polyfill plugins - NodeGlobalsPolyfillPlugin({ - process: false, - buffer: true, - }), - ], + plugins: [nodePolyfills()], }, }, build: {