Skip to content
This repository was archived by the owner on Feb 23, 2025. It is now read-only.

chore: enable React.StrictMode #370

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
10 changes: 9 additions & 1 deletion app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { RemixBrowser } from "@remix-run/react";
import React from "react";
import { hydrateRoot } from "react-dom/client";
import { registerServiceWorker } from "./misc/register-service-worker.client";
import { initializePublicConfigClient } from "./utils/config-public";

function main() {
registerServiceWorker();
initializePublicConfigClient();
hydrateRoot(window.document, <RemixBrowser />);
React.startTransition(() => {
hydrateRoot(
window.document,
<React.StrictMode>
<RemixBrowser />
</React.StrictMode>
);
});
}

main();
29 changes: 8 additions & 21 deletions app/utils/youtube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import {
tinyassert,
zip,
} from "@hiogawa/utils";
import { useRefCallbackEffect, useStableCallback } from "@hiogawa/utils-react";
import { useMutation } from "@tanstack/react-query";
import { XMLParser } from "fast-xml-parser";
import React from "react";
import { toast } from "react-hot-toast";
import { z } from "zod";
import { loadScript } from "./dom-utils";
import { useIntersectionObserver } from "./hooks-client-utils";
import {
FILTERED_LANGUAGE_CODES,
LanguageCode,
Expand Down Expand Up @@ -497,27 +495,16 @@ export function usePlayerLoader(
playerOptions: YoutubePlayerOptions,
{ onReady }: { onReady: (player: YoutubePlayer) => void }
) {
onReady = useStableCallback(onReady);

const ref = useRefCallbackEffect<HTMLElement>((el) => {
if (el && mutation.isIdle) {
mutation.mutate(el);
const ref = useIntersectionObserver(([entry]) => {
if (entry && entry.target instanceof HTMLElement && mutation.isIdle) {
mutation.mutate(entry.target);
}
});

const mutation = useMutation(
(el: HTMLElement) => loadYoutubePlayer(el, playerOptions),
{
onSuccess: onReady,
onError: () => {
toast.error("Failed to initialize youtube player");
},
}
);

React.useEffect(() => {
return () => mutation.data?.destroy();
}, []);
const mutation = useMutation({
mutationFn: (el: HTMLElement) => loadYoutubePlayer(el, playerOptions),
onSuccess: onReady,
});

return {
ref,
Expand Down