Skip to content

🎥 Make videos programmatically with React

fix audio updating when source staying the same

Jonny Burgerc4abd311c843
diff --git a/packages/core/src/audio/shared-audio-tags.tsx b/packages/core/src/audio/shared-audio-tags.tsx
index a08efaddc4..37ac694f7b 100644
--- a/packages/core/src/audio/shared-audio-tags.tsx
+++ b/packages/core/src/audio/shared-audio-tags.tsx
@@ -66,6 +66,26 @@ const compareProps = (
return true;
};
+const didPropChange = (key: string, newProp: unknown, prevProp: unknown) => {
+ // /music.mp3 and http://localhost:3000/music.mp3 are the same
+ if (
+ key === 'src' &&
+ !(prevProp as string).startsWith('data:') &&
+ !(newProp as string).startsWith('data:')
+ ) {
+ return (
+ new URL(prevProp as string, window.location.origin).toString() !==
+ new URL(newProp as string, window.location.origin).toString()
+ );
+ }
+
+ if (prevProp === newProp) {
+ return false;
+ }
+
+ return true;
+};
+
export const SharedAudioContext = createContext<SharedContext | null>(null);
export const SharedAudioContextProvider: React.FC<{
@@ -110,7 +130,13 @@ export const SharedAudioContextProvider: React.FC<{
throw new TypeError('Expected audio data to be there');
}
- Object.assign(current, data.props);
+ Object.keys(data.props).forEach((key) => {
+ // @ts-expect-error
+ if (didPropChange(key, data.props[key], current[key])) {
+ // @ts-expect-error
+ current[key] = data.props[key];
+ }
+ });
});
}, [refs]);