diff --git a/.github/workflows/golang-test-lint.yml b/.github/workflows/golang-test-lint.yml index 829deb366..aa7efda1e 100644 --- a/.github/workflows/golang-test-lint.yml +++ b/.github/workflows/golang-test-lint.yml @@ -25,7 +25,10 @@ jobs: go-version-file: bskyweb/go.mod cache-dependency-path: bskyweb/go.sum - name: ๐Ÿ“„ Dummy Static Files - run: touch bskyweb/static/js/blah.js && touch bskyweb/static/css/blah.txt && touch bskyweb/static/media/blah.txt + run: | + mkdir -p bskyweb/static/_expo bskyweb/static/assets + touch bskyweb/static/_expo/blah.js bskyweb/static/assets/blah.txt + touch bskyweb/templates/scripts.html bskyweb/templates/fonts.html - name: ๐Ÿ” Check run: cd bskyweb/ && make check - name: ๐Ÿ—๏ธ Build (binary) @@ -43,6 +46,9 @@ jobs: go-version-file: bskyweb/go.mod cache-dependency-path: bskyweb/go.sum - name: ๐Ÿ“„ Dummy Static Files - run: touch bskyweb/static/js/blah.js && touch bskyweb/static/css/blah.txt && touch bskyweb/static/media/blah.txt + run: | + mkdir -p bskyweb/static/_expo bskyweb/static/assets + touch bskyweb/static/_expo/blah.js bskyweb/static/assets/blah.txt + touch bskyweb/templates/scripts.html bskyweb/templates/fonts.html - name: ๐Ÿงน Lint run: cd bskyweb/ && make lint diff --git a/.github/workflows/pull-request-commit.yml b/.github/workflows/pull-request-commit.yml index 0a69d0177..d10dfc169 100644 --- a/.github/workflows/pull-request-commit.yml +++ b/.github/workflows/pull-request-commit.yml @@ -26,7 +26,7 @@ env: jobs: # Populate this from main so every PR can restore the same trusted baseline. - webpack-analyzer-base: + bundle-analyzer-base: runs-on: ubuntu-24.04 if: ${{ github.event_name == 'push' }} permissions: @@ -43,28 +43,29 @@ jobs: node-version-file: package.json cache: pnpm - - name: โฌ‡๏ธ Get base stats from cache - id: get-base-stats + - name: โฌ‡๏ธ Get base bundle size from cache + id: get-base-size uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: stats.json - key: stats-base-main-${{ github.sha }} + path: base-bundle-size.txt + key: base-bundle-size-main-${{ github.sha }} - - name: ๐Ÿ”ฆ Generate stats file for base commit - if: ${{ !steps.get-base-stats.outputs.cache-hit }} + - name: ๐Ÿ”ฆ Build and measure base bundle + if: ${{ !steps.get-base-size.outputs.cache-hit }} run: | pnpm install pnpm intl:build - pnpm generate-webpack-stats-file + pnpm build-web + node scripts/measure-web-bundle.js > base-bundle-size.txt - - name: โฌ†๏ธ Save base stats to cache - if: ${{ !steps.get-base-stats.outputs.cache-hit }} + - name: โฌ†๏ธ Save base bundle size to cache + if: ${{ !steps.get-base-size.outputs.cache-hit }} uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: stats.json - key: stats-base-main-${{ github.sha }} + path: base-bundle-size.txt + key: base-bundle-size-main-${{ github.sha }} - webpack-analyzer: + bundle-analyzer: runs-on: ubuntu-24.04 if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request'}} permissions: @@ -109,41 +110,66 @@ jobs: pnpm install pnpm intl:build - - name: ๐Ÿ”ฆ Generate stats file for PR + - name: ๐Ÿ”ฆ Build and measure PR bundle run: | - pnpm generate-webpack-stats-file - mv stats.json ../stats-new.json + pnpm build-web + node scripts/measure-web-bundle.js > ../pr-bundle-size.txt - - name: โฌ‡๏ธ Get base stats from cache - id: get-base-stats + - name: โฌ‡๏ธ Get base bundle size from cache + id: get-base-size # Restore-only prevents PR-scoped fallback builds from creating caches. uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: - path: stats.json - key: stats-base-main-${{ steps.base-commit.outputs.base-commit }} + path: base-bundle-size.txt + key: base-bundle-size-main-${{ steps.base-commit.outputs.base-commit }} - name: โช Restore to base commit - if: ${{ !steps.get-base-stats.outputs.cache-hit }} + if: ${{ !steps.get-base-size.outputs.cache-hit }} env: BASE_COMMIT: ${{ steps.base-commit.outputs.base-commit }} run: | git reset "$BASE_COMMIT" git restore . + # Drop the PR-side export so the measure script's output-dir + # auto-detection can't pick it up: a webpack base exports to + # web-build/ while the PR's Metro build left dist/ behind. + rm -rf dist web-build - - name: ๐Ÿ”ฆ Generate stats file from base commit - if: ${{ !steps.get-base-stats.outputs.cache-hit }} + - name: ๐Ÿ”ฆ Build and measure base bundle + if: ${{ !steps.get-base-size.outputs.cache-hit }} run: | pnpm install pnpm intl:build - pnpm generate-webpack-stats-file + pnpm build-web + node scripts/measure-web-bundle.js --allow-missing > base-bundle-size.txt - name: ๏ผ… Get diff id: get-diff - uses: NejcZdovc/bundle-size-diff@5321de41d2d62a7b0f4d6e60f59d1280a0034160 # v1.1.0 - with: - base_path: "stats.json" - pr_path: "../stats-new.json" - excluded_assets: "(.+).chunk.js|(.+).js.map|(.+).json|(.+).png|(.+).svg|(.+).webp|(.+).jpg|(.+).ico" + run: | + node -e ' + const fs = require("node:fs") + const base = Number(fs.readFileSync("base-bundle-size.txt", "utf8").trim()) + const pr = Number(fs.readFileSync("../pr-bundle-size.txt", "utf8").trim()) + if (!Number.isFinite(base) || !Number.isFinite(pr) || base <= 0) { + console.error(`Bad measurements: base=${base} pr=${pr}`) + process.exit(1) + } + const fmt = bytes => { + const abs = Math.abs(bytes) + if (abs >= 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(2)} MB` + if (abs >= 1024) return `${(bytes / 1024).toFixed(2)} KB` + return `${bytes} B` + } + const diff = pr - base + const out = [ + `base_file_string=${fmt(base)}`, + `pr_file_string=${fmt(pr)}`, + `diff_file_string=${diff > 0 ? "+" : ""}${fmt(diff)}`, + `percent=${((diff / base) * 100).toFixed(2)}`, + ].join("\n") + console.log(out) + fs.appendFileSync(process.env.GITHUB_OUTPUT, out + "\n") + ' - name: ๐Ÿ’ฌ Drop a comment uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5 diff --git a/.oxlintrc.json b/.oxlintrc.json index 319b11038..4ad6c60c9 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -326,6 +326,10 @@ "default" ], "message": "React is already in the global type namespace. Use named imports for runtime modules." + }, + { + "name": "@sentry/react-native", + "message": "Import {Sentry} from '#/logger/sentry/lib' instead. Importing @sentry/react-native directly (especially as `import * as Sentry`) defeats Metro tree-shaking and pulls ~180KB of dead weight into the web bundle." } ] } @@ -401,6 +405,15 @@ "env": { "jest": true } + }, + { + "files": [ + "src/logger/sentry/**/*.ts", + "src/logger/__tests__/logger.test.ts" + ], + "rules": { + "no-restricted-imports": "off" + } } ] } diff --git a/.prettierignore b/.prettierignore index be1658124..965743609 100644 --- a/.prettierignore +++ b/.prettierignore @@ -23,3 +23,4 @@ lib/react-compiler-runtime bskyweb/static coverage web-build +dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index fff191cc5..f0bab01ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,10 @@ ENV CI=1 # use the pnpm version specified in package.json ENV pnpm_config_pm_on_fail=download +# Metro's web export needs far more heap than Node's default (~1GB in the +# container), which crashes the bundle step with a V8 OOM. +ENV NODE_OPTIONS="--max-old-space-size=8192" + # The latest git hash of the preview branch on render.com # https://render.com/docs/docker-secrets#environment-variables-in-docker-builds ARG RENDER_GIT_COMMIT diff --git a/Dockerfile.embedr b/Dockerfile.embedr index ef7d72cc9..b16b68ff7 100644 --- a/Dockerfile.embedr +++ b/Dockerfile.embedr @@ -22,7 +22,7 @@ ENV CI=true COPY . . # -# Generate the JavaScript webpack. NOTE: this will change +# Generate the JavaScript bundle. NOTE: this will change # RUN mkdir --parents $NVM_DIR && \ wget \ diff --git a/app.config.js b/app.config.js index a8f0fd6b5..ba237137e 100644 --- a/app.config.js +++ b/app.config.js @@ -217,6 +217,7 @@ module.exports = function (_config) { ], }, web: { + bundler: 'metro', favicon: './assets/favicon.png', }, updates: { @@ -479,6 +480,9 @@ module.exports = function (_config) { projectId: '55bd077a-d905-4184-9c7f-94789ba0f302', }, }, + experiments: { + baseUrl: '/static', + }, }, } } diff --git a/babel.config.js b/babel.config.js index 90abe51c4..5f16f38fa 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,3 +1,24 @@ +/** + * React Compiler tags generated nodes with loc = Symbol(GeneratedSource), + * which breaks the structuredClone Metro performs on the AST when + * EXPO_UNSTABLE_TREE_SHAKING is enabled. Strip them after all other + * transforms have run. + */ +const stripSymbolLocs = () => ({ + post(file) { + file.path.traverse({ + enter(path) { + if (typeof path.node.loc === 'symbol') { + path.node.loc = undefined + } + }, + }) + if (typeof file.ast.program.loc === 'symbol') { + file.ast.program.loc = undefined + } + }, +}) + /** * @param {import("@babel/core").ConfigAPI} api * @returns {import("@babel/core").InputOptions} @@ -20,7 +41,6 @@ module.exports = function (api) { plugins: [ '@lingui/babel-plugin-lingui-macro', ['babel-plugin-react-compiler', {target: '19'}], - 'module:react-native-dotenv', // used by web build! can remove when we drop webpack [ 'module-resolver', { @@ -45,6 +65,7 @@ module.exports = function (api) { : []), ...(api.env('production') ? ['transform-remove-console'] : []), + stripSymbolLocs, 'react-native-worklets/plugin', // NOTE: this plugin MUST be last ], } diff --git a/bskyweb/.gitignore b/bskyweb/.gitignore index a63a381f9..9ac9bc804 100644 --- a/bskyweb/.gitignore +++ b/bskyweb/.gitignore @@ -16,7 +16,10 @@ static/css/*.css.LICENSE.txt static/css/empty.txt static/media/*.png static/media/empty.txt +static/_expo/ +static/assets/ templates/scripts.html +templates/fonts.html templates/*-embed.html static/embed/*.html static/embed/assets/*.js diff --git a/bskyweb/cmd/bskyweb/server.go b/bskyweb/cmd/bskyweb/server.go index eb59adf40..f2dd0d1f8 100644 --- a/bskyweb/cmd/bskyweb/server.go +++ b/bskyweb/cmd/bskyweb/server.go @@ -280,8 +280,8 @@ func serve(cctx *cli.Context) error { path := c.Request().URL.Path maxAge := 1 * (60 * 60) // default is 1 hour - // all assets in /static/js, /static/css, /static/media are content-hashed and can be cached for a long time - if strings.HasPrefix(path, "/static/js/") || strings.HasPrefix(path, "/static/css/") || strings.HasPrefix(path, "/static/media/") { + // all assets in /static/_expo, /static/assets, /static/media are content-hashed and can be cached for a long time + if strings.HasPrefix(path, "/static/_expo/") || strings.HasPrefix(path, "/static/assets/") || strings.HasPrefix(path, "/static/media/") { maxAge = 365 * (60 * 60 * 24) // 1 year } diff --git a/bskyweb/static.go b/bskyweb/static.go index 38adb8333..4b59f27d7 100644 --- a/bskyweb/static.go +++ b/bskyweb/static.go @@ -2,7 +2,10 @@ package bskyweb import "embed" -//go:embed static/* +// `all:` disables the default exclusion of files/dirs beginning with `_` or `.`, +// which is needed because Metro emits chunks like `__common-...js` and +// `__expo-metro-runtime-...js`. +//go:embed all:static var StaticFS embed.FS //go:embed embedr-static/* diff --git a/bskyweb/templates/base.html b/bskyweb/templates/base.html index 7f723ce36..3684fa781 100644 --- a/bskyweb/templates/base.html +++ b/bskyweb/templates/base.html @@ -13,7 +13,7 @@ - + {% include "fonts.html" %} +` +console.log(`Writing ${fontsTemplateFile}`) +fs.writeFileSync(fontsTemplateFile, fontsHtml) - return '' - }) - .join('\n') -fs.writeFileSync(templateFile, outputFile) +// Clean previous build output to avoid stale files +function cleanDir(dir) { + if (fs.existsSync(dir)) { + fs.rmSync(dir, {recursive: true}) + console.log(`Cleaned ${dir}`) + } +} + +cleanDir(path.join(bskywebStatic, '_expo')) +cleanDir(path.join(bskywebStatic, 'assets')) -function copyFiles(sourceDir, targetDir) { - const files = fs.readdirSync(path.join(projectRoot, sourceDir)) - files.forEach(file => { - const sourcePath = path.join(projectRoot, sourceDir, file) - const targetPath = path.join(projectRoot, targetDir, file) - fs.copyFileSync(sourcePath, targetPath) - console.log(`Copied ${sourcePath} to ${targetPath}`) - }) +// Recursively copy a directory. +function copyDir(sourceDir, targetDir) { + if (!fs.existsSync(sourceDir)) { + console.log(`Skipping ${sourceDir} (does not exist)`) + return + } + fs.mkdirSync(targetDir, {recursive: true}) + const entries = fs.readdirSync(sourceDir, {withFileTypes: true}) + for (const entry of entries) { + const sourcePath = path.join(sourceDir, entry.name) + const targetPath = path.join(targetDir, entry.name) + if (entry.isDirectory()) { + copyDir(sourcePath, targetPath) + } else { + fs.copyFileSync(sourcePath, targetPath) + console.log(`Copied ${sourcePath} to ${targetPath}`) + } + } } -copyFiles('web-build/static/js', 'bskyweb/static/js') -copyFiles('web-build/static/css', 'bskyweb/static/css') -copyFiles('web-build/static/media', 'bskyweb/static/media') +// Copy Metro's _expo/ tree wholesale so JS chunks (including lazy chunks +// referenced by hash) and source maps resolve at the same paths the runtime expects. +copyDir(path.join(distDir, '_expo'), path.join(bskywebStatic, '_expo')) + +// Copy assets (fonts, images, icons, etc.) referenced as /static/assets/... by the bundle. +copyDir(path.join(distDir, 'assets'), path.join(bskywebStatic, 'assets')) + +// Upload source maps to Sentry +if ( + process.env.SENTRY_AUTH_TOKEN && + process.env.SENTRY_AUTH_TOKEN != 'unknown' +) { + const release = + process.env.SENTRY_RELEASE || + require(path.join(projectRoot, 'package.json')).version + /* + * The runtime reports EXPO_PUBLIC_RELEASE_VERSION || package.json version + * (src/env/common.ts), so maps uploaded under a bogus release never match + * incoming events. "null"/"undefined" catch `jq -r '.version'` stringifying + * a missing package.json version field. + */ + if (!release || release === 'null' || release === 'undefined') { + throw new Error( + `Refusing to upload source maps under invalid Sentry release ${JSON.stringify(release)}. ` + + 'Set SENTRY_RELEASE or restore the "version" field in package.json.', + ) + } + const dist = process.env.SENTRY_DIST || undefined + const sourceMapDir = path.join(distDir, '_expo', 'static') + + console.log(`Uploading source maps to Sentry (release: ${release})`) + const args = [ + 'sourcemaps', + 'upload', + '--org', + 'blueskyweb', + '--project', + 'app', + '--release', + release, + ...(dist ? ['--dist', dist] : []), + sourceMapDir, + ] + try { + execFileSync('sentry-cli', args, {stdio: 'inherit', cwd: projectRoot}) + console.log('Sentry source map upload complete') + } catch (e) { + console.error('Sentry source map upload failed:', e.message) + process.exit(1) + } +} else { + console.log('Skipping Sentry source map upload (SENTRY_AUTH_TOKEN not set)') +} diff --git a/src/App.tsx b/src/App.tsx index 2f0a70203..eaaf70afa 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -11,7 +11,6 @@ import * as ScreenOrientation from 'expo-screen-orientation' import * as SplashScreen from 'expo-splash-screen' import * as SystemUI from 'expo-system-ui' import {useLingui} from '@lingui/react/macro' -import * as Sentry from '@sentry/react-native' import {Provider as HideBottomBarBorderProvider} from '#/lib/hooks/useHideBottomBarBorder' import {QueryProvider} from '#/lib/react-query' @@ -19,6 +18,7 @@ import {ThemeProvider} from '#/lib/ThemeContext' import {Provider as TranslateOnDeviceProvider} from '#/lib/translation' import I18nProvider from '#/locale/i18nProvider' import {logger} from '#/logger' +import {Sentry} from '#/logger/sentry/lib' import {Provider as A11yProvider} from '#/state/a11y' import { prefetchAppConfig, diff --git a/src/App.web.tsx b/src/App.web.tsx index ef6ac5e4c..1f5763045 100644 --- a/src/App.web.tsx +++ b/src/App.web.tsx @@ -5,7 +5,6 @@ import {Fragment, useEffect, useState} from 'react' import {KeyboardProvider as KeyboardControllerProvider} from 'react-native-keyboard-controller' import {SafeAreaProvider} from 'react-native-safe-area-context' import {useLingui} from '@lingui/react/macro' -import * as Sentry from '@sentry/react-native' import {Provider as HotkeysProvider} from '#/lib/hotkeys' import {QueryProvider} from '#/lib/react-query' @@ -13,6 +12,7 @@ import {ThemeProvider} from '#/lib/ThemeContext' import {Provider as TranslateOnDeviceProvider} from '#/lib/translation' import I18nProvider from '#/locale/i18nProvider' import {logger} from '#/logger' +import {Sentry} from '#/logger/sentry/lib' import {Provider as A11yProvider} from '#/state/a11y' import { prefetchAppConfig, diff --git a/src/components/Dialog/index.web.tsx b/src/components/Dialog/index.web.tsx index ee74da624..34930bc1b 100644 --- a/src/components/Dialog/index.web.tsx +++ b/src/components/Dialog/index.web.tsx @@ -19,7 +19,9 @@ import { } from 'react-native' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' -import {DismissableLayer, FocusGuards, FocusScope} from 'radix-ui/internal' +import * as DismissableLayer from '@radix-ui/react-dismissable-layer' +import * as FocusGuards from '@radix-ui/react-focus-guards' +import * as FocusScope from '@radix-ui/react-focus-scope' import {RemoveScrollBar} from 'react-remove-scroll-bar' import {logger} from '#/logger' diff --git a/src/components/EmojiPicker/index.web.tsx b/src/components/EmojiPicker/index.web.tsx index 8d5e7788e..71cf769b9 100644 --- a/src/components/EmojiPicker/index.web.tsx +++ b/src/components/EmojiPicker/index.web.tsx @@ -1,6 +1,6 @@ import {createContext, useContext, useEffect, useMemo, useRef} from 'react' import EmojiPicker from '@emoji-mart/react' -import {DropdownMenu} from 'radix-ui' +import * as DropdownMenu from '@radix-ui/react-dropdown-menu' import {useA11y} from '#/state/a11y' import {textInputWebEmitter} from '#/view/com/composer/text-input/textInputWebEmitter' diff --git a/src/components/FocusScope/index.web.tsx b/src/components/FocusScope/index.web.tsx index 541cd7260..4e9c49b80 100644 --- a/src/components/FocusScope/index.web.tsx +++ b/src/components/FocusScope/index.web.tsx @@ -1,4 +1,4 @@ -import {FocusScope as RadixFocusScope} from 'radix-ui/internal' +import * as RadixFocusScope from '@radix-ui/react-focus-scope' /* * The web version of the FocusScope component is a proper implementation, we diff --git a/src/components/Lightbox/Lightbox.web.tsx b/src/components/Lightbox/Lightbox.web.tsx index cccbe4f85..5e75b209e 100644 --- a/src/components/Lightbox/Lightbox.web.tsx +++ b/src/components/Lightbox/Lightbox.web.tsx @@ -2,7 +2,8 @@ import {useCallback, useEffect, useRef, useState} from 'react' import {Pressable, ScrollView, StyleSheet, View} from 'react-native' import {Image} from 'expo-image' import {Trans, useLingui} from '@lingui/react/macro' -import {FocusGuards, FocusScope} from 'radix-ui/internal' +import * as FocusGuards from '@radix-ui/react-focus-guards' +import * as FocusScope from '@radix-ui/react-focus-scope' import {RemoveScrollBar} from 'react-remove-scroll-bar' import {saveImageToMediaLibrary} from '#/lib/media/manip' diff --git a/src/components/Menu/index.web.tsx b/src/components/Menu/index.web.tsx index ab7ac7dbc..622d23907 100644 --- a/src/components/Menu/index.web.tsx +++ b/src/components/Menu/index.web.tsx @@ -8,7 +8,7 @@ import { } from 'react-native' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' -import {DropdownMenu} from 'radix-ui' +import * as DropdownMenu from '@radix-ui/react-dropdown-menu' import {useA11y} from '#/state/a11y' import {atoms as a, flatten, flattenToCSS, useTheme, web} from '#/alf' diff --git a/src/components/ProfileCard.tsx b/src/components/ProfileCard.tsx index 71653896c..5b45b9907 100644 --- a/src/components/ProfileCard.tsx +++ b/src/components/ProfileCard.tsx @@ -160,6 +160,7 @@ export function Avatar({ moderationOpts, onPress, disabledPreview, + disableLink, liveOverride, size = 40, }: { @@ -167,6 +168,7 @@ export function Avatar({ moderationOpts: ModerationOpts onPress?: () => void disabledPreview?: boolean + disableLink?: boolean liveOverride?: boolean size?: number }) { @@ -188,6 +190,7 @@ export function Avatar({ profile={profile} moderation={moderation.ui('avatar')} onBeforePress={onPress} + disableLink={disableLink} live={liveOverride ?? live} /> ) diff --git a/src/components/Select/index.web.tsx b/src/components/Select/index.web.tsx index ade6cf3e2..6ad773792 100644 --- a/src/components/Select/index.web.tsx +++ b/src/components/Select/index.web.tsx @@ -1,6 +1,6 @@ import {createContext, forwardRef, Fragment, useContext, useMemo} from 'react' import {View} from 'react-native' -import {Select as RadixSelect} from 'radix-ui' +import * as RadixSelect from '@radix-ui/react-select' import {useA11y} from '#/state/a11y' import {atoms as a, flatten, flattenToCSS, useTheme, web} from '#/alf' diff --git a/src/components/Tooltip/index.web.tsx b/src/components/Tooltip/index.web.tsx index 8d6c9634a..80194632f 100644 --- a/src/components/Tooltip/index.web.tsx +++ b/src/components/Tooltip/index.web.tsx @@ -1,7 +1,7 @@ import {createContext, useContext, useMemo} from 'react' import {View} from 'react-native' import {utils} from '@bsky.app/alf' -import {Popover} from 'radix-ui' +import * as Popover from '@radix-ui/react-popover' import {atoms as a, flattenToCSS, useTheme} from '#/alf' import { diff --git a/src/components/WelcomeModal.tsx b/src/components/WelcomeModal.tsx index 3e76a914e..639a484f0 100644 --- a/src/components/WelcomeModal.tsx +++ b/src/components/WelcomeModal.tsx @@ -2,7 +2,8 @@ import {useEffect, useEffectEvent, useState} from 'react' import {Pressable, View} from 'react-native' import {ImageBackground} from 'expo-image' import {Trans, useLingui} from '@lingui/react/macro' -import {FocusGuards, FocusScope} from 'radix-ui/internal' +import * as FocusGuards from '@radix-ui/react-focus-guards' +import * as FocusScope from '@radix-ui/react-focus-scope' import {useLoggedOutViewControls} from '#/state/shell/logged-out' import {Logo} from '#/view/icons/Logo' diff --git a/src/components/dms/EmojiReactionPicker.web.tsx b/src/components/dms/EmojiReactionPicker.web.tsx index c84151f36..b71b16f7b 100644 --- a/src/components/dms/EmojiReactionPicker.web.tsx +++ b/src/components/dms/EmojiReactionPicker.web.tsx @@ -1,7 +1,7 @@ import {useState} from 'react' import {Pressable, View} from 'react-native' import {useLingui} from '@lingui/react/macro' -import {DropdownMenu} from 'radix-ui' +import * as DropdownMenu from '@radix-ui/react-dropdown-menu' import {useSession} from '#/state/session' import {atoms as a, flatten, useTheme} from '#/alf' diff --git a/src/components/dms/MessagesListHeader.tsx b/src/components/dms/MessagesListHeader.tsx index e69148655..bf1faeeb5 100644 --- a/src/components/dms/MessagesListHeader.tsx +++ b/src/components/dms/MessagesListHeader.tsx @@ -116,6 +116,7 @@ function ProfileHeaderReady({ profile={profile} moderation={moderation.ui('avatar')} disableHoverCard={moderation.blocked} + disableLink /> diff --git a/src/components/forms/SearchInput.tsx b/src/components/forms/SearchInput.tsx index c4a77069c..8fcfd687b 100644 --- a/src/components/forms/SearchInput.tsx +++ b/src/components/forms/SearchInput.tsx @@ -32,7 +32,7 @@ export function SearchInput({ }: Props) { const t = useTheme() const {t: l} = useLingui() - const showClear = value && value.length > 0 + const showClear = !!value && value.length > 0 const internalRef = useRef>(null) useEffect(() => { diff --git a/src/lib/media/video/mediabunny.ts b/src/lib/media/video/mediabunny.ts index edcbc805c..9ed8905f1 100644 --- a/src/lib/media/video/mediabunny.ts +++ b/src/lib/media/video/mediabunny.ts @@ -3,18 +3,16 @@ type MediaBunnyModule = typeof import('mediabunny') let promise: Promise | undefined /** - * Lazily loads mediabunny into its own webpack chunk and caches the resulting + * Lazily loads mediabunny into its own async chunk and caches the resulting * promise so the module is fetched at most once. If the import fails (e.g. a * transient chunk-load error), the cached promise is reset so a later call can * retry the load. */ export function loadMediaBunny(): Promise { - promise ??= import(/* webpackChunkName: "mediabunny" */ 'mediabunny').catch( - e => { - // reset so a later attempt can retry after a transient chunk-load failure - promise = undefined - throw e - }, - ) + promise ??= import('mediabunny').catch(e => { + // reset so a later attempt can retry after a transient chunk-load failure + promise = undefined + throw e + }) return promise } diff --git a/src/logger/sentry/lib/index.ts b/src/logger/sentry/lib/index.ts index e771560e7..791ec6316 100644 --- a/src/logger/sentry/lib/index.ts +++ b/src/logger/sentry/lib/index.ts @@ -1 +1,32 @@ -export * as Sentry from '@sentry/react-native' +import { + addBreadcrumb, + captureException, + captureFeedback, + captureMessage, + getClient, + startInactiveSpan, + withActiveSpan, + withScope, + wrap, +} from '@sentry/react-native' + +/** + * Curated subset of @sentry/react-native, listing only the symbols the app + * actually uses. Re-exporting the whole SDK namespace + * (`export * as Sentry from '@sentry/react-native'`) defeats Metro + * tree-shaking on web and pulls in ~180KB of dead weight. + * + * When the app needs another SDK function, add it to the import above and to + * this object, then run a web build to confirm the bundle size is unaffected. + */ +export const Sentry = { + addBreadcrumb, + captureException, + captureFeedback, + captureMessage, + getClient, + startInactiveSpan, + withActiveSpan, + withScope, + wrap, +} diff --git a/src/logger/sentry/lib/index.web.ts b/src/logger/sentry/lib/index.web.ts index e771560e7..af3d974dd 100644 --- a/src/logger/sentry/lib/index.web.ts +++ b/src/logger/sentry/lib/index.web.ts @@ -1 +1,39 @@ -export * as Sentry from '@sentry/react-native' +import { + addBreadcrumb, + captureException, + captureFeedback, + captureMessage, + getClient, + startInactiveSpan, + withActiveSpan, + withScope, +} from '@sentry/browser' + +/** + * Web counterpart of ./index.ts. Importing from `@sentry/browser` instead of + * `@sentry/react-native` keeps the RN SDK layer (native wrapper, RN tracing, + * feedback widget, RN integrations - roughly 200KB minified) out of the web + * bundle. All of these APIs are re-exported from `@sentry/core` by both + * packages, so behavior is identical. + * + * When the app needs another SDK function, add it here and to ./index.ts, then + * run a web build to confirm the bundle size is unaffected. + */ +export const Sentry = { + addBreadcrumb, + captureException, + captureFeedback, + captureMessage, + getClient, + startInactiveSpan, + withActiveSpan, + withScope, + /** + * `wrap` does not exist in `@sentry/browser`. On web, the RN SDK's `wrap` + * only adds a touch-event breadcrumb boundary and a React profiler span, so + * we pass the root component through unchanged. + */ + wrap:

>( + component: React.ComponentType

, + ): React.ComponentType

=> component, +} diff --git a/src/logger/sentry/setup/index.web.ts b/src/logger/sentry/setup/index.web.ts new file mode 100644 index 000000000..a927321b0 --- /dev/null +++ b/src/logger/sentry/setup/index.web.ts @@ -0,0 +1,51 @@ +import {init} from '@sentry/browser' + +import * as env from '#/env' + +/* + * Web counterpart of ./index.ts. Initializing `@sentry/browser` directly + * instead of `@sentry/react-native` keeps the RN SDK layer (native wrapper, + * RN tracing, feedback widget, RN integrations - roughly 200KB minified) out + * of the web bundle. Options mirror the native setup; RN-only options are + * omitted. + */ +init({ + enabled: !env.IS_DEV && !!env.SENTRY_DSN, + dsn: env.SENTRY_DSN, + debug: false, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production + environment: env.ENV, + dist: env.BUNDLE_IDENTIFIER, + release: env.RELEASE_VERSION, + ignoreErrors: [ + /* + * Unknown internals errors + */ + `t is not defined`, + `Can't find variable: t`, + /* + * Un-useful errors + */ + `Network request failed`, + ], + /** + * Does not affect traces of error events or other logs, just disables + * automatically attaching stack traces to events. This helps us group events + * and prevents explosions of separate issues. + * + * @see https://docs.sentry.io/platforms/react-native/configuration/options/#attach-stacktrace + */ + attachStacktrace: false, + sampleRate: env.IS_INTERNAL ? 1.0 : 0.1, + /** + * Sample rate for performance spans (video playback, video upload). Setting + * this also enables the SDK's default stall and slow/frozen frame tracking, + * whose measurements attach to every root span. + */ + tracesSampleRate: env.IS_INTERNAL ? 1.0 : 0.01, + /* + * The native setup passes `enableAutoSessionTracking: false`. The browser + * SDK's equivalent is the BrowserSession default integration, so filter it + * out to match. + */ + integrations: defaults => defaults.filter(i => i.name !== 'BrowserSession'), +}) diff --git a/src/platform/polyfills.web.ts b/src/platform/polyfills.web.ts index dce9b284c..53d786c7f 100644 --- a/src/platform/polyfills.web.ts +++ b/src/platform/polyfills.web.ts @@ -1,34 +1,12 @@ import 'array.prototype.findlast/auto' import 'setimmediate' -if (process.env.NODE_ENV !== 'production') { - // In development, react-native-web's tries to validate that - // text is wrapped into . It doesn't catch all cases but is useful. - // Unfortunately, it only does that via console.error so it's easy to miss. - // This is a hack to get it showing as a redbox on the web so we catch it early. - const realConsoleError = console.error - const thrownErrors = new WeakSet() - console.error = function consoleErrorWrapper(msgOrError) { - if ( - typeof msgOrError === 'string' && - msgOrError.startsWith('Unexpected text node') - ) { - if ( - msgOrError === - 'Unexpected text node: . A text node cannot be a child of a .' - ) { - // This is due to a stray empty string. - // React already handles this fine, so RNW warning is a false positive. Ignore. - return - } - const err = new Error(msgOrError) - thrownErrors.add(err) - throw err - } else if (!thrownErrors.has(msgOrError)) { - // @ts-expect-error - return realConsoleError.apply(this, arguments) - } - } -} +/* + * NOTE: the webpack-era console.error wrapper that re-threw react-native-web's + * "Unexpected text node" warnings as redboxes was removed with the Metro + * migration. Metro's LogBox already surfaces console.error prominently, and + * any wrapper around console.error becomes the top stack frame of every + * captured error, making Metro attribute all of them to this file. + */ export {} diff --git a/src/screens/Search/Shell.tsx b/src/screens/Search/Shell.tsx index dd232e89b..1b3e76c94 100644 --- a/src/screens/Search/Shell.tsx +++ b/src/screens/Search/Shell.tsx @@ -575,7 +575,7 @@ export function SearchScreenShell({ )} - {query && !showAutocomplete && ( + {!!query && !showAutocomplete && ( { + link.precache() + onPress?.() + }, + }) const record = view.record const isOwnStarterPack = view.creator?.did === currentAccount?.did @@ -105,13 +114,13 @@ export function StarterPackCard({ : _(msg`By ${sanitizeHandle(view.creator.handle, '@')}`)} - { - link.precache() - onPress?.() + onPress={e => { + // don't let the press reach the surrounding card link + e.stopPropagation() + openPack.onPress(e) }} variant="solid" color="secondary" @@ -120,7 +129,7 @@ export function StarterPackCard({ Open pack - + diff --git a/src/screens/Search/modules/ExploreSuggestedAccounts.tsx b/src/screens/Search/modules/ExploreSuggestedAccounts.tsx index 545cc0d23..2464fb886 100644 --- a/src/screens/Search/modules/ExploreSuggestedAccounts.tsx +++ b/src/screens/Search/modules/ExploreSuggestedAccounts.tsx @@ -13,6 +13,7 @@ import {boostInterests, InterestTabs} from '#/components/InterestTabs' import * as ProfileCard from '#/components/ProfileCard' import {SubtleHover} from '#/components/SubtleHover' import {useAnalytics} from '#/analytics' +import {IS_WEB} from '#/env' import {type app} from '#/lexicons' import type * as bsky from '#/types/bsky' @@ -138,6 +139,7 @@ let SuggestedProfileCard = ({ ) diff --git a/src/view/com/feeds/ComposerPrompt.tsx b/src/view/com/feeds/ComposerPrompt.tsx index 22f55e863..1e83f8d72 100644 --- a/src/view/com/feeds/ComposerPrompt.tsx +++ b/src/view/com/feeds/ComposerPrompt.tsx @@ -157,7 +157,7 @@ export function ComposerPrompt() { return ( cannot be a descendant of