🎥 Make videos programmatically with React
further simplification
Jonny Burger8d67b769ed65
diff --git a/packages/bundler/src/hot-middleware/client.ts b/packages/bundler/src/hot-middleware/client.tsindex 77e206074d..8f056fac7d 100644--- a/packages/bundler/src/hot-middleware/client.ts+++ b/packages/bundler/src/hot-middleware/client.ts@@ -17,10 +17,6 @@ if (typeof window === 'undefined') {connect();}-function setOptionsAndConnect() {- connect();-}-function eventSourceWrapper() {let source: EventSource;let lastActivity = Date.now();@@ -99,9 +95,7 @@ function connect() {try {processMessage(JSON.parse(event.data));} catch (ex) {- if (hotMiddlewareOptions.warn) {- console.warn('Invalid HMR message: ' + event.data + '\n' + ex);- }+ console.warn('Invalid HMR message: ' + event.data + '\n' + ex);}}}@@ -130,11 +124,6 @@ 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);@@ -170,9 +159,7 @@ function createReporter() {previousProblems = null;},problems(type: 'errors' | 'warnings', obj: HotMiddlewareMessage) {- if (hotMiddlewareOptions.warn) {- log(type, obj);- }+ log(type, obj);return true;},@@ -180,68 +167,22 @@ function createReporter() {};}-let customHandler: ((msg: HotMiddlewareMessage) => void) | undefined;-let subscribeAllHandler: ((msg: HotMiddlewareMessage) => void) | undefined;-function processMessage(obj: HotMiddlewareMessage) {- 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;+ 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;}-- default:- if (customHandler) {- customHandler(obj);- }+ } else if (reporter) {+ reporter.cleanProblemsCache();+ reporter.success();}- if (subscribeAllHandler) {- subscribeAllHandler(obj);+ if (applyUpdate) {+ processUpdate(obj.hash, obj.modules, hotMiddlewareOptions);}}--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 fedc2a4c66..888a6971c4 100644--- a/packages/bundler/src/hot-middleware/index.tsx+++ b/packages/bundler/src/hot-middleware/index.tsx@@ -36,16 +36,12 @@ 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 53abbf0a78..80f1fb43ff 100644--- a/packages/bundler/src/hot-middleware/process-update.ts+++ b/packages/bundler/src/hot-middleware/process-update.ts@@ -61,7 +61,6 @@ 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();}@@ -73,14 +72,10 @@ export const processUpdate = function (if (err) return handleError(err);if (!updatedModules) {- if (options.warn) {- console.warn(- '[Fast refresh] Cannot find update (Full reload needed)'- );- console.warn(- '[Fast refresh] (Probably because of restarting the server)'- );- }+ console.warn('[Fast refresh] Cannot find update (Full reload needed)');+ console.warn(+ '[Fast refresh] (Probably because of restarting the server)'+ );performReload();return null;@@ -128,22 +123,18 @@ export const processUpdate = function (}) ?? [];if (unacceptedModules.length > 0) {- 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)- );- });- }+ 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;@@ -152,9 +143,10 @@ 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));+ console.log(+ `[Fast refresh] ${moduleMap[moduleId] || moduleId} updated.`+ );});}@@ -165,23 +157,19 @@ export const processUpdate = function (function handleError(err: Error) {if ((module.hot?.status() ?? 'nope') in failureStatuses) {- if (options.warn) {- console.warn(- '[Fast refresh] Cannot check for update (Full reload needed)'- );- console.warn('[Fast refresh] ' + (err.stack || err.message));- }+ console.warn(+ '[Fast refresh] Cannot check for update (Full reload needed)'+ );+ console.warn('[Fast refresh] ' + (err.stack || err.message));performReload();return;}- if (options.warn) {- console.warn(- '[Fast refresh] Update check failed: ' + (err.stack || err.message)- );- window.location.reload();- }+ console.warn(+ '[Fast refresh] Update check failed: ' + (err.stack || err.message)+ );+ window.location.reload();}function performReload() {@@ -189,7 +177,7 @@ export const processUpdate = function (return;}- if (options.warn) console.warn('[Fast refresh] Reloading page');+ 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 28fb0d503b..fa74d487cd 100644--- a/packages/bundler/src/hot-middleware/types.ts+++ b/packages/bundler/src/hot-middleware/types.ts@@ -1,27 +1,21 @@import webpack from 'webpack';-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 type HotMiddlewareMessage = {+ action: '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 ff978dacbb..ed13d0a4bd 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={0} durationInFrames={durationInFrames}>+ <Sequence from={10} durationInFrames={durationInFrames}><Comp src={codec === 'mp4' ? videoMp4 : videoWebm} /></Sequence></div>