diff --git a/src/app/record.tsx b/src/app/record.tsx index 2b2ee4d..0e675a0 100644 --- a/src/app/record.tsx +++ b/src/app/record.tsx @@ -72,7 +72,13 @@ function Recording({ controller }: { controller: SessionController }) { const target = state.labelTargetId ? data.moments.find((m) => m.id === state.labelTargetId) ?? null : null; const bands = recordingBands(target !== null); const sinceValue = sinceLast === null ? '—' : formatElapsed(sinceLast); - const since = sinceTimerFonts(clockFont, { ...sinceBox, label: sinceHeading, value: sinceValue }); + // Destructured: Reanimated's dev Babel plugin warns about any `x.value` in an + // inline style, mistaking it for a shared value read. + const { label: sinceLabelFont, value: sinceValueFont } = sinceTimerFonts(clockFont, { + ...sinceBox, + label: sinceHeading, + value: sinceValue, + }); const milestone = (code: RowMilestoneCode | Extract) => { controller.markMilestone(code); @@ -139,13 +145,13 @@ function Recording({ controller }: { controller: SessionController }) { {/* Sized by sinceTimerFonts, not adjustsFontSizeToFit, which on iOS collapsed the value to a few points in this flex box. */} {sinceHeading} {sinceValue} diff --git a/tests/inlineStyleWarning.test.ts b/tests/inlineStyleWarning.test.ts new file mode 100644 index 0000000..f529cc1 --- /dev/null +++ b/tests/inlineStyleWarning.test.ts @@ -0,0 +1,44 @@ +import { transformFileSync, transformSync } from '@babel/core'; +import { readFileSync, readdirSync, statSync } from 'fs'; +import { join } from 'path'; + +// In development builds the Reanimated / worklets Babel plugin rewrites any +// `x.value` inside an inline `style` object into a console.warn("It looks like +// you might be using shared value's .value inside reanimated inline style"), +// even when x is a plain object. record.tsx did that with sinceTimerFonts()'s +// `value` font size. This compiles every component with the project's own +// babel.config.js and fails if the plugin injected the warning anywhere. + +const ROOT = join(__dirname, '..'); +const MARKER = 'getUseOfValueInStyleWarning'; + +function tsxFiles(dir: string): string[] { + return readdirSync(dir).flatMap((name) => { + const p = join(dir, name); + if (statSync(p).isDirectory()) return tsxFiles(p); + return p.endsWith('.tsx') ? [p] : []; + }); +} + +const OPTIONS = { cwd: ROOT, envName: 'development', babelrc: false, configFile: join(ROOT, 'babel.config.js') }; + +/** Compiled output of a file, or of `code` as if it lived at `filename`. */ +const compile = (filename: string, code?: string) => + (code === undefined ? transformFileSync(filename, OPTIONS) : transformSync(code, { ...OPTIONS, filename }))?.code ?? ''; + +describe('Reanimated inline style warning', () => { + // Positive control: the old record.tsx line. If the plugin stops running in + // this config, this fails instead of every file below passing vacuously. + it('detects the pattern record.tsx used to have', () => { + const record = join(ROOT, 'src', 'app', 'record.tsx'); + const old = readFileSync(record, 'utf8').replace('fontSize: sinceValueFont,', 'fontSize: fonts.value,'); + expect(old).toContain('fonts.value'); + expect(compile(record, old)).toContain(MARKER); + }); + + const files = tsxFiles(join(ROOT, 'src')); + + it.each(files.map((f) => [f.slice(ROOT.length + 1), f]))('%s compiles without the warning', (_, file) => { + expect(compile(file)).not.toContain(MARKER); + }); +});