From de2f38bc57510405ae9396bb241b058185c22791 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Tue, 16 Dec 2025 14:33:26 -0800 Subject: [PATCH 1/5] Fix server rendered components to also utilize the WorkerPool * This commit is untested because I have no way to test. * Also I went in and fixed up usage of the component to use our diff tag constant, to be more future proof if the tagname ever changes * Ensure the WorkerPool can only instantiate in a browser environment * Lower total worker count because 8 is probably overkill * Safari is much slower with spinning up webworkers anyways, so probably more effective this way --- packages/ui/src/components/diff-ssr.tsx | 22 ++++++++------- packages/ui/src/custom-elements.d.ts | 5 +++- packages/ui/src/pierre/worker.ts | 36 +++++++++++++++---------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/packages/ui/src/components/diff-ssr.tsx b/packages/ui/src/components/diff-ssr.tsx index b38b4a34fc37..d4ceafaca28e 100644 --- a/packages/ui/src/components/diff-ssr.tsx +++ b/packages/ui/src/components/diff-ssr.tsx @@ -1,8 +1,9 @@ -import { FileDiff } from "@pierre/diffs" +import { DIFFS_TAG_NAME, FileDiff } from "@pierre/diffs" import { PreloadMultiFileDiffResult } from "@pierre/diffs/ssr" import { onCleanup, onMount, Show, splitProps } from "solid-js" -import { isServer } from "solid-js/web" +import { Dynamic, isServer } from "solid-js/web" import { createDefaultOptions, styleVariables, type DiffProps } from "../pierre" +import { workerPool } from "../pierre/worker" export type SSRDiffProps = DiffProps & { preloadedDiff: PreloadMultiFileDiffResult @@ -18,11 +19,14 @@ export function Diff(props: SSRDiffProps) { onMount(() => { if (isServer || !props.preloadedDiff) return - fileDiffInstance = new FileDiff({ - ...createDefaultOptions(props.diffStyle), - ...others, - ...props.preloadedDiff, - }) + fileDiffInstance = new FileDiff( + { + ...createDefaultOptions(props.diffStyle), + ...others, + ...props.preloadedDiff, + }, + workerPool, + ) // @ts-expect-error - fileContainer is private but needed for SSR hydration fileDiffInstance.fileContainer = fileDiffRef fileDiffInstance.hydrate({ @@ -65,11 +69,11 @@ export function Diff(props: SSRDiffProps) { return (
- +