🎥 Make videos programmatically with React
`@remotion/studio-server`: Remove module stats overhead from Fast Refresh
Jonny Burger20f0186495ac
diff --git a/packages/example/e2e/fast-refresh-node-paths.test.mts b/packages/example/e2e/fast-refresh-node-paths.test.mtsnew file mode 100644index 0000000000..08bb83e1cf--- /dev/null+++ b/packages/example/e2e/fast-refresh-node-paths.test.mts@@ -0,0 +1,109 @@+import fs from 'fs';+import path from 'path';+import {expect, test} from '@playwright/test';+import type {SubscribeToSequencePropsResponse} from '@remotion/studio-shared';+import {exampleDir, STUDIO_URL} from './constants.mts';+import {startStudio, stopStudio} from './studio-server.mts';++test('consecutive visual edits target the correct siblings after fast refresh', async ({+ page,+}) => {+ const sourceFile = path.join(exampleDir, 'src/BarChart.tsx');+ const original = fs.readFileSync(sourceFile, 'utf8');+ try {+ await startStudio();+ const initialProps = page.waitForResponse(async (response) => {+ if (!response.url().endsWith('/api/subscribe-to-sequence-props')) {+ return false;+ }+ const result = await response.json();+ return result.data?.results?.some(+ (item: SubscribeToSequencePropsResponse) =>+ item.success &&+ item.status.canUpdate &&+ item.status.props.name?.status === 'static' &&+ item.status.props.name.codeValue === 'Eyebrow',+ );+ });+ await page.goto(`${STUDIO_URL}/AnimatedBarChart`);+ await initialProps;+ await page.getByRole('button', {name: '0', exact: true}).click();+ await page.getByRole('textbox', {name: '0', exact: true}).fill('120');+ await page.keyboard.press('Enter');+ const canvas = page.locator('.remotion-studio-composition-container');+ await expect(+ canvas.getByText('Regional growth', {exact: true}),+ ).toBeVisible();++ // These unkeyed siblings reuse runtime instances when an earlier one is+ // removed. A successful API response alone can hide deleting the wrong node.+ for (const [label, text] of [+ ['Eyebrow', 'Performance overview'],+ ['Title', 'Regional growth'],+ ]) {+ await expect(canvas.getByText(text, {exact: true})).toBeVisible();+ await page.getByTitle(label, {exact: true}).first().click();+ const response = page.waitForResponse((r) =>+ r.url().endsWith('/api/delete-jsx-nodes'),+ );+ await page.keyboard.press('Delete');+ expect((await (await response).json()).data.success).toBe(true);+ const source = fs.readFileSync(sourceFile, 'utf8');+ expect(source).not.toContain(`name="${label}"`);+ expect(source).toContain('name="Chart panel"');+ expect(source).toContain('name="Peak badge"');+ await expect(canvas.getByText(text, {exact: true})).toHaveCount(0);+ }++ // An editor save has no codemod remapping event. Stack refresh must still+ // discover the new source positions before the next visual edit.+ const beforeEditorSave = fs.readFileSync(sourceFile, 'utf8');+ fs.writeFileSync(+ sourceFile,+ beforeEditorSave.replace(+ '<Interactive.Div\n\t\t\t\tname="Chart panel"',+ '<Interactive.Div name="Editor insertion">External edit</Interactive.Div>\n\t\t\t<Interactive.Div\n\t\t\t\tname="Chart panel"',+ ),+ );+ await expect(+ canvas.getByText('External edit', {exact: true}),+ ).toBeVisible();+ await page.getByTitle('Chart panel', {exact: true}).first().click();+ const response = page.waitForResponse((r) =>+ r.url().endsWith('/api/delete-jsx-nodes'),+ );+ await page.keyboard.press('Delete');+ expect((await (await response).json()).data.success).toBe(true);+ const source = fs.readFileSync(sourceFile, 'utf8');+ expect(source).not.toContain('name="Chart panel"');+ expect(source).toContain('name="Editor insertion"');+ expect(source).toContain('name="Peak badge"');+ await expect(+ canvas.getByText('External edit', {exact: true}),+ ).toBeVisible();+ await expect(canvas.getByText('West leads at 87%')).toBeVisible();++ // Insertion must select the new element after refresh. Delete it without+ // selecting a row, so this also verifies automatic selection.+ await page.keyboard.press('Escape');+ await page.getByRole('button', {name: 'Expand right sidebar'}).click();+ await page.getByRole('button', {name: 'Add Solid', exact: true}).click();+ await expect(+ page.getByTitle('<Solid>', {exact: true}).first(),+ ).toBeVisible();+ await expect(+ page.getByRole('button', {name: 'Add Solid', exact: true}),+ ).toHaveCount(0);+ expect(fs.readFileSync(sourceFile, 'utf8')).toContain('<Solid');+ const deleteInserted = page.waitForResponse((r) =>+ r.url().endsWith('/api/delete-jsx-nodes'),+ );+ await page.keyboard.press('Delete');+ expect((await (await deleteInserted).json()).data.success).toBe(true);+ expect(fs.readFileSync(sourceFile, 'utf8')).not.toContain('<Solid');+ expect(fs.readFileSync(sourceFile, 'utf8')).toContain('name="Peak badge"');+ } finally {+ fs.writeFileSync(sourceFile, original);+ await stopStudio();+ }+});diff --git a/packages/studio-server/src/preview-server/hot-middleware/index.tsx b/packages/studio-server/src/preview-server/hot-middleware/index.tsxindex f2b3ebfa8e..76fe16e841 100644--- a/packages/studio-server/src/preview-server/hot-middleware/index.tsx+++ b/packages/studio-server/src/preview-server/hot-middleware/index.tsx@@ -7,7 +7,7 @@import type {webpack} from '@remotion/bundler';import type {LogLevel} from '@remotion/renderer';import {RenderInternals} from '@remotion/renderer';-import type {HotMiddlewareMessage, ModuleMap} from '@remotion/studio-shared';+import type {HotMiddlewareMessage} from '@remotion/studio-shared';import {logHmrTiming} from '../hmr-timing';import type {LiveEventsServer} from '../live-events';import type {WebpackStats} from './types';@@ -175,14 +175,16 @@ function publishStats() {const stats = statsResult.toJson({all: false,- cached: true,children: true,- modules: true,timings: true,hash: true,});- // For multi-compiler, stats will be an object with a 'children' array of stats- const bundles = extractBundles(stats);+ // A single compilation may also have child compilations. Only MultiStats+ // should publish its children instead of the parent compilation.+ const bundles =+ statsResult.compilation || !stats.children?.length+ ? [stats]+ : stats.children;bundles.forEach((_stats: WebpackStats) => {let name = _stats.name || '';@@ -198,31 +200,9 @@ function publishStats(hash: _stats.hash,warnings: _stats.warnings || [],errors: _stats.errors || [],- modules: buildModuleMap(_stats.modules),+ // Module names only label browser console messages. The client already+ // falls back to module IDs, which are named in development builds.+ modules: {},});});}--function extractBundles(stats: WebpackStats) {- // Stats has modules, single bundle- if (stats.modules) return [stats];-- // Stats has children, multiple bundles- if (stats.children?.length) return stats.children;-- // Not sure, assume single- return [stats];-}--function buildModuleMap(modules: WebpackStats['modules']): ModuleMap {- const map: {[key: string]: string} = {};- if (!modules) {- return map;- }-- modules.forEach((module) => {- const id = module.id as string;- map[id] = module.name as string;- });- return map;-}