🎥 Make videos programmatically with React
Revert "further simplification"
Jonny Burger97032a460bdc
diff --git a/packages/bundler/src/hot-middleware/client.ts b/packages/bundler/src/hot-middleware/client.tsindex 8f056fac7d..77e206074d 100644--- a/packages/bundler/src/hot-middleware/client.ts+++ b/packages/bundler/src/hot-middleware/client.ts@@ -17,6 +17,10 @@ if (typeof window === 'undefined') {connect();}+function setOptionsAndConnect() {+ connect();+}+function eventSourceWrapper() {let source: EventSource;let lastActivity = Date.now();@@ -95,7 +99,9 @@ function connect() {try {processMessage(JSON.parse(event.data));} catch (ex) {- console.warn('Invalid HMR message: ' + event.data + '\n' + ex);+ if (hotMiddlewareOptions.warn) {+ console.warn('Invalid HMR message: ' + event.data + '\n' + ex);+ }}}}@@ -124,6 +130,11 @@ function createReporter() {let previousProblems: string | null = null;function log(type: 'errors' | 'warnings', obj: HotMiddlewareMessage) {+ if (obj.action === 'building') {+ console.log('[Fast Refresh] Building');+ return;+ }+const newProblems = obj[type].map((msg) => {return stripAnsi(msg as string);@@ -159,7 +170,9 @@ function createReporter() {previousProblems = null;},problems(type: 'errors' | 'warnings', obj: HotMiddlewareMessage) {- log(type, obj);+ if (hotMiddlewareOptions.warn) {+ log(type, obj);+ }return true;},@@ -167,22 +180,68 @@ function createReporter() {};}+let customHandler: ((msg: HotMiddlewareMessage) => void) | undefined;+let subscribeAllHandler: ((msg: HotMiddlewareMessage) => void) | undefined;+function processMessage(obj: HotMiddlewareMessage) {- let applyUpdate = true;- if (obj.errors.length > 0) {- if (reporter) reporter.problems('errors', obj);- applyUpdate = false;- } else if (obj.warnings.length > 0) {- if (reporter) {- const overlayShown = reporter.problems('warnings', obj);- applyUpdate = overlayShown;+ switch (obj.action) {+ case 'building':+ console.log(+ '[Fast refresh] bundle ' ++ (obj.name ? "'" + obj.name + "' " : '') ++ 'rebuilding'+ );++ break;+ case 'built':+ console.log(+ '[Fast refresh] bundle ' ++ (obj.name ? "'" + obj.name + "' " : '') ++ 'rebuilt in ' ++ obj.time ++ 'ms'+ );++ // fall through+ case 'sync': {+ let applyUpdate = true;+ if (obj.errors.length > 0) {+ if (reporter) reporter.problems('errors', obj);+ applyUpdate = false;+ } else if (obj.warnings.length > 0) {+ if (reporter) {+ const overlayShown = reporter.problems('warnings', obj);+ applyUpdate = overlayShown;+ }+ } else if (reporter) {+ reporter.cleanProblemsCache();+ reporter.success();+ }++ if (applyUpdate) {+ processUpdate(obj.hash, obj.modules, hotMiddlewareOptions);+ }++ break;}- } else if (reporter) {- reporter.cleanProblemsCache();- reporter.success();++ default:+ if (customHandler) {+ customHandler(obj);+ }}- if (applyUpdate) {- processUpdate(obj.hash, obj.modules, hotMiddlewareOptions);+ if (subscribeAllHandler) {+ subscribeAllHandler(obj);}}++module.exports = {+ subscribeAll(handler: (msg: HotMiddlewareMessage) => void) {+ subscribeAllHandler = handler;+ },+ subscribe(handler: (msg: HotMiddlewareMessage) => void) {+ customHandler = handler;+ },+ setOptionsAndConnect,+};diff --git a/packages/bundler/src/hot-middleware/index.tsx b/packages/bundler/src/hot-middleware/index.tsxindex 888a6971c4..fedc2a4c66 100644--- a/packages/bundler/src/hot-middleware/index.tsx+++ b/packages/bundler/src/hot-middleware/index.tsx@@ -36,12 +36,16 @@ export const webpackHotMiddleware = (compiler: webpack.Compiler) => {if (closed) return;latestStats = null;console.log('webpack building...');+ eventStream?.publish({+ action: 'building',+ });}function onDone(statsResult: webpack.Stats) {if (closed) return;// Keep hold of latest stats so they can be propagated to new clientslatestStats = statsResult;+ publishStats('built', latestStats, eventStream);}const middleware = function (diff --git a/packages/bundler/src/hot-middleware/process-update.ts b/packages/bundler/src/hot-middleware/process-update.tsindex 80f1fb43ff..53abbf0a78 100644--- a/packages/bundler/src/hot-middleware/process-update.ts+++ b/packages/bundler/src/hot-middleware/process-update.ts@@ -61,6 +61,7 @@ export const processUpdate = function () {const {reload} = options;if (!upToDate(hash) && module.hot?.status() === 'idle') {+ console.log('[Fast refresh] Checking for updates on the server...');check();}@@ -72,10 +73,14 @@ export const processUpdate = function (if (err) return handleError(err);if (!updatedModules) {- console.warn('[Fast refresh] Cannot find update (Full reload needed)');- console.warn(- '[Fast refresh] (Probably because of restarting the server)'- );+ if (options.warn) {+ console.warn(+ '[Fast refresh] Cannot find update (Full reload needed)'+ );+ console.warn(+ '[Fast refresh] (Probably because of restarting the server)'+ );+ }performReload();return null;@@ -123,18 +128,22 @@ export const processUpdate = function (}) ?? [];if (unacceptedModules.length > 0) {- console.warn(- "[Fast refresh] The following modules couldn't be hot updated: " +- '(Full reload needed)\n' +- 'This is usually because the modules which have changed ' +- '(and their parents) do not know how to hot reload themselves. ' +- 'See ' +- hmrDocsUrl +- ' for more details.'- );- unacceptedModules.forEach((moduleId) => {- console.warn('[Fast refresh] - ' + (moduleMap[moduleId] || moduleId));- });+ if (options.warn) {+ console.warn(+ "[Fast refresh] The following modules couldn't be hot updated: " ++ '(Full reload needed)\n' ++ 'This is usually because the modules which have changed ' ++ '(and their parents) do not know how to hot reload themselves. ' ++ 'See ' ++ hmrDocsUrl ++ ' for more details.'+ );+ unacceptedModules.forEach((moduleId) => {+ console.warn(+ '[Fast refresh] - ' + (moduleMap[moduleId] || moduleId)+ );+ });+ }performReload();return;@@ -143,10 +152,9 @@ export const processUpdate = function (if (!renewedModules || renewedModules.length === 0) {console.log('[Fast refresh] Nothing hot updated.');} else {+ console.log('[Fast refresh] Updated modules:');renewedModules.forEach((moduleId) => {- console.log(- `[Fast refresh] ${moduleMap[moduleId] || moduleId} updated.`- );+ console.log('[Fast refresh] - ' + (moduleMap[moduleId] || moduleId));});}@@ -157,19 +165,23 @@ export const processUpdate = function (function handleError(err: Error) {if ((module.hot?.status() ?? 'nope') in failureStatuses) {- console.warn(- '[Fast refresh] Cannot check for update (Full reload needed)'- );- console.warn('[Fast refresh] ' + (err.stack || err.message));+ if (options.warn) {+ console.warn(+ '[Fast refresh] Cannot check for update (Full reload needed)'+ );+ console.warn('[Fast refresh] ' + (err.stack || err.message));+ }performReload();return;}- console.warn(- '[Fast refresh] Update check failed: ' + (err.stack || err.message)- );- window.location.reload();+ if (options.warn) {+ console.warn(+ '[Fast refresh] Update check failed: ' + (err.stack || err.message)+ );+ window.location.reload();+ }}function performReload() {@@ -177,7 +189,7 @@ export const processUpdate = function (return;}- console.warn('[Fast refresh] Reloading page');+ if (options.warn) console.warn('[Fast refresh] Reloading page');window.location.reload();}};diff --git a/packages/bundler/src/hot-middleware/types.ts b/packages/bundler/src/hot-middleware/types.tsindex fa74d487cd..28fb0d503b 100644--- a/packages/bundler/src/hot-middleware/types.ts+++ b/packages/bundler/src/hot-middleware/types.ts@@ -1,21 +1,27 @@import webpack from 'webpack';-export type HotMiddlewareMessage = {- action: 'sync';- name: string;- time: number | undefined;- errors: unknown[];- warnings: unknown[];- hash: string | undefined;- modules: {- [key: string]: string;- };-};+export type HotMiddlewareMessage =+ | {+ action: 'building';+ name?: string;+ }+ | {+ action: 'built' | 'sync';+ name: string;+ time: number | undefined;+ errors: unknown[];+ warnings: unknown[];+ hash: string | undefined;+ modules: {+ [key: string]: string;+ };+ };export const hotMiddlewareOptions = {path: '/__webpack_hmr',timeout: 20 * 1000,reload: true,+ warn: true,heartbeat: 10 * 1000,};diff --git a/packages/example/src/VideoTesting/index.tsx b/packages/example/src/VideoTesting/index.tsxindex ed13d0a4bd..ff978dacbb 100644--- a/packages/example/src/VideoTesting/index.tsx+++ b/packages/example/src/VideoTesting/index.tsx@@ -18,7 +18,7 @@ export const VideoTesting: React.FC<{return (<div>- <Sequence from={10} durationInFrames={durationInFrames}>+ <Sequence from={0} durationInFrames={durationInFrames}><Comp src={codec === 'mp4' ? videoMp4 : videoWebm} /></Sequence></div>