mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
### Description Fixes #350 This adds a dynamic multiline layout to `CustomEditor`. When the message input grows past a single line (word wrap, explicit newlines, or multiple blocks), the editor shifts from a single-row layout into a two-row grid, before/textarea on top, with responsive content spanning the full width below. It drops back to single-row once the text fits on one line again. The old `replacementContent` prop (which swapped out the textarea on mobile during voice recording) is gone. It's replaced by `responsiveAfter`, which renders inline next to the send button in single-line mode and moves down to the footer row in multiline mode. There's also a `forceMultilineLayout` prop for when you want to push into multiline immediately, which is what we use when the audio recorder opens. This means the recorder now takes the same code path on desktop and mobile instead of having a separate mobile-only branch. A few other things got fixed along the way: - Holding the record button on mobile was selecting the "following the conversation" text underneath it. Fixed with `userSelect: none`. (related to #350) - The stop button's `onClick` was being skipped on mobile entirely, so if `pointerup` got lost mid-drag there was no way to stop recording. Now `onClick` works as a fallback when recording is already active. (a form of recovery in case more situations like #350 happen again) - The waveform bar count is now calculated from the actual container width via `ResizeObserver` instead of a hardcoded number. - `cleanupMediaRecorder` wasn't being called in all the stop/delete/restart/error/unmount paths, which could leave the mic track open. That's fixed. - Firefox couldn't seek voice messages because `audio/webm` doesn't include a seek index. Codec preference now puts `audio/ogg;codecs=opus` first so Firefox records seekable blobs. Also added a `seekTo` helper that waits for `loadedmetadata` if the audio element isn't ready yet, and `audio.preload = 'auto'` + `audio.load()` on mount so Firefox parses metadata right away. - Multiline wrap detection is now debounced through `requestAnimationFrame` and uses a `ResizeObserver` on the scroll container to cut down on flicker and extra re-renders. - Added cloudflared tunnels for easier testing on mobile Also sorry for the cursed line height measurer, there was legit no other way to detect it that didn't cause other issues. Good amount of this was created with help of AI (like figuring out options on how to fix the edge cases), especially the edge case unit tests, but It had to be fixed by hand in many places and frankly I can't tell you exactly where was what. I've been working on this for couple days now.. (losing my mind over it) ### Screenshots: https://github.com/user-attachments/assets/bcff3766-6c60-46c7-ac9e-a8b943a665d3 https://github.com/user-attachments/assets/367cdcc4-666e-4324-8e81-1b415feb0aca #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [x] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail).
256 lines
7.5 KiB
TypeScript
256 lines
7.5 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
import type { ViteDevServer, PluginOption } from 'vite';
|
|
import { execSync } from 'child_process';
|
|
import react from '@vitejs/plugin-react';
|
|
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 inject from '@rollup/plugin-inject';
|
|
import topLevelAwait from 'vite-plugin-top-level-await';
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
import { compression, defineAlgorithm } from 'vite-plugin-compression2';
|
|
import { constants as zlibConstants } from 'zlib';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { cloudflare } from '@cloudflare/vite-plugin';
|
|
import { createRequire } from 'module';
|
|
import { sentryVitePlugin } from '@sentry/vite-plugin';
|
|
import buildConfig from './build.config';
|
|
|
|
const packageJson = JSON.parse(
|
|
fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf8')
|
|
) as {
|
|
version: string;
|
|
};
|
|
|
|
const normalizeShortSha = (value?: string): string | undefined => {
|
|
if (!value) return undefined;
|
|
const normalized = value.trim();
|
|
if (!normalized) return undefined;
|
|
return normalized.slice(0, 7);
|
|
};
|
|
|
|
const resolveBuildHash = (): string | undefined => {
|
|
const envHash = normalizeShortSha(
|
|
process.env.VITE_BUILD_HASH ??
|
|
process.env.GITHUB_SHA ??
|
|
process.env.CI_COMMIT_SHA ??
|
|
process.env.SOURCE_VERSION
|
|
);
|
|
if (envHash) return envHash;
|
|
try {
|
|
return normalizeShortSha(execSync('git rev-parse --short HEAD').toString('utf8'));
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
};
|
|
|
|
const appVersion = packageJson.version;
|
|
const buildHash = resolveBuildHash();
|
|
|
|
const isReleaseTag = (() => {
|
|
const envVal = process.env.VITE_IS_RELEASE_TAG;
|
|
if (envVal !== undefined && envVal !== '') return envVal === 'true';
|
|
try {
|
|
const tag = execSync('git describe --exact-match --tags HEAD 2>/dev/null').toString().trim();
|
|
return tag.startsWith('v');
|
|
} catch {
|
|
return false;
|
|
}
|
|
})();
|
|
|
|
const copyFiles = {
|
|
targets: [
|
|
{
|
|
src: 'node_modules/@sableclient/sable-call-embedded/dist/*',
|
|
dest: 'public/element-call',
|
|
},
|
|
{
|
|
src: 'node_modules/pdfjs-dist/build/pdf.worker.min.mjs',
|
|
dest: '',
|
|
rename: 'pdf.worker.min.js',
|
|
},
|
|
{
|
|
src: 'config.json',
|
|
dest: '',
|
|
},
|
|
{
|
|
src: 'public/manifest.json',
|
|
dest: '',
|
|
},
|
|
{
|
|
src: 'public/res/logo-maskable',
|
|
dest: 'public/',
|
|
},
|
|
{
|
|
src: 'public/res/logo',
|
|
dest: 'public/',
|
|
},
|
|
{
|
|
src: 'public/res/svg',
|
|
dest: 'public/',
|
|
},
|
|
{
|
|
src: 'public/locales',
|
|
dest: 'public/',
|
|
},
|
|
],
|
|
};
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
function serverMatrixSdkCryptoWasm() {
|
|
return {
|
|
name: 'vite-plugin-serve-matrix-sdk-crypto-wasm',
|
|
configureServer(server: ViteDevServer) {
|
|
const resolvedPath = path.join(
|
|
path.dirname(require.resolve('@matrix-org/matrix-sdk-crypto-wasm')),
|
|
'pkg/matrix_sdk_crypto_wasm_bg.wasm'
|
|
);
|
|
|
|
server.middlewares.use((req, res, next) => {
|
|
if (!req.url?.endsWith('matrix_sdk_crypto_wasm_bg.wasm')) {
|
|
next();
|
|
return;
|
|
}
|
|
res.setHeader('Content-Type', 'application/wasm');
|
|
res.setHeader('Cache-Control', 'no-cache');
|
|
fs.createReadStream(resolvedPath).pipe(res);
|
|
});
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig(({ command }) => ({
|
|
appType: 'spa',
|
|
publicDir: false,
|
|
base: buildConfig.base,
|
|
define: {
|
|
APP_VERSION: JSON.stringify(appVersion),
|
|
BUILD_HASH: JSON.stringify(buildHash ?? ''),
|
|
IS_RELEASE_TAG: JSON.stringify(isReleaseTag),
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
$hooks: path.resolve(__dirname, 'src/app/hooks'),
|
|
$plugins: path.resolve(__dirname, 'src/app/plugins'),
|
|
$components: path.resolve(__dirname, 'src/app/components'),
|
|
$features: path.resolve(__dirname, 'src/app/features'),
|
|
$state: path.resolve(__dirname, 'src/app/state'),
|
|
$styles: path.resolve(__dirname, 'src/app/styles'),
|
|
$utils: path.resolve(__dirname, 'src/app/utils'),
|
|
$pages: path.resolve(__dirname, 'src/app/pages'),
|
|
$types: path.resolve(__dirname, 'src/types'),
|
|
$public: path.resolve(__dirname, 'public'),
|
|
$client: path.resolve(__dirname, 'src/client'),
|
|
},
|
|
},
|
|
server: {
|
|
port: 8080,
|
|
host: true,
|
|
allowedHosts: command === 'serve' ? true : undefined,
|
|
fs: {
|
|
// Allow serving files from one level up to the project root
|
|
allow: ['..'],
|
|
},
|
|
},
|
|
plugins: [
|
|
serverMatrixSdkCryptoWasm(),
|
|
topLevelAwait({
|
|
// The export name of top-level await promise for each chunk module
|
|
promiseExportName: '__tla',
|
|
// The function to generate import names of top-level await promise in each chunk module
|
|
promiseImportName: (i) => `__tla_${i}`,
|
|
}),
|
|
viteStaticCopy(copyFiles),
|
|
vanillaExtractPlugin({ identifiers: 'debug' }),
|
|
wasm() as PluginOption,
|
|
react(),
|
|
svgr(),
|
|
VitePWA({
|
|
srcDir: 'src',
|
|
filename: 'sw.ts',
|
|
strategies: 'injectManifest',
|
|
injectRegister: false,
|
|
manifest: false,
|
|
injectManifest: {
|
|
injectionPoint: undefined,
|
|
},
|
|
devOptions: {
|
|
enabled: true,
|
|
type: 'module',
|
|
},
|
|
}),
|
|
cloudflare({
|
|
config: {
|
|
compatibility_date: '2026-03-03',
|
|
assets: {
|
|
not_found_handling: 'single-page-application',
|
|
},
|
|
},
|
|
}),
|
|
compression({
|
|
algorithms: [
|
|
defineAlgorithm('brotliCompress', {
|
|
params: { [zlibConstants.BROTLI_PARAM_QUALITY]: zlibConstants.BROTLI_MAX_QUALITY },
|
|
}),
|
|
],
|
|
include: /\.(html|xml|css|json|js|mjs|svg|yaml|yml|toml|wasm|txt|map)$/,
|
|
}),
|
|
// Sentry source map upload — only active when credentials are provided at build time
|
|
...(process.env.SENTRY_AUTH_TOKEN && process.env.SENTRY_ORG && process.env.SENTRY_PROJECT
|
|
? [
|
|
sentryVitePlugin({
|
|
org: process.env.SENTRY_ORG,
|
|
project: process.env.SENTRY_PROJECT,
|
|
authToken: process.env.SENTRY_AUTH_TOKEN,
|
|
sourcemaps: {
|
|
filesToDeleteAfterUpload: ['dist/**/*.map'],
|
|
},
|
|
release: {
|
|
name: appVersion,
|
|
},
|
|
// Annotate React components with data-sentry-* attributes at build
|
|
// time so Sentry can show component names in breadcrumbs, spans,
|
|
// and replay search instead of raw CSS selectors.
|
|
reactComponentAnnotation: { enabled: true },
|
|
}),
|
|
]
|
|
: []),
|
|
],
|
|
optimizeDeps: {
|
|
// Rebuild dep optimizer cache on each dev start to avoid stale API shapes.
|
|
force: true,
|
|
// Keep matrix-widget-api prebundled so matrix-js-sdk can import its named exports in dev.
|
|
// Force CJS interop for stability across optimizer cache rebuilds.
|
|
include: [
|
|
'matrix-widget-api',
|
|
'workbox-precaching',
|
|
'@vanilla-extract/recipes/createRuntimeFn',
|
|
],
|
|
needsInterop: ['matrix-widget-api'],
|
|
esbuildOptions: {
|
|
define: {
|
|
global: 'globalThis',
|
|
},
|
|
plugins: [
|
|
// Enable esbuild polyfill plugins
|
|
NodeGlobalsPolyfillPlugin({
|
|
process: false,
|
|
buffer: true,
|
|
}),
|
|
],
|
|
},
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
sourcemap: true,
|
|
copyPublicDir: false,
|
|
rollupOptions: {
|
|
plugins: [inject({ Buffer: ['buffer', 'Buffer'] }) as PluginOption],
|
|
},
|
|
},
|
|
}));
|