From https://github.com/IHaskell/IHaskell/commit/5bf443fb7c96d561295cf5eb83513db677d54e1a
From: Hypercube <hypercube@0x01.me>
Date: Tue, 19 Jul 2022 00:00:00 +0000
Subject: [PATCH] avoid switching directory in ihaskell-display

--- a/IHaskell/Display/Charts.hs
+++ b/IHaskell/Display/Charts.hs
@@ -7,6 +7,8 @@ import           Data.Default.Class
 import           Graphics.Rendering.Chart.Renderable
 import           Graphics.Rendering.Chart.Backend.Cairo
 import qualified Data.ByteString.Char8 as Char
+import qualified Data.Text.Encoding as T (decodeUtf8)
+import           System.IO.Temp
 import           System.IO.Unsafe
 
 import           IHaskell.Display
@@ -29,19 +31,18 @@ instance IHaskellDisplay (Renderable a) where
 
 chartData :: Renderable a -> FileFormat -> IO DisplayData
 chartData renderable format = do
-  switchToTmpDir
-
-  -- Write the PNG image.
-  let filename = ".ihaskell-chart.png"
-      opts = def { _fo_format = format, _fo_size = (width, height) }
-  mkFile opts filename renderable
-
-  -- Convert to base64.
-  imgData <- Char.readFile filename
-  return $
-    case format of
-      PNG -> png width height $ base64 imgData
-      SVG -> svg $ Char.unpack imgData
+  withSystemTempFile "ihaskell-chart.png" $ \path _ -> do
+
+    -- Write the PNG image.
+    let opts = def { _fo_format = format, _fo_size = (width, height) }
+    renderableToFile opts path renderable
+
+    -- Convert to base64.
+    imgData <- Char.readFile path
+    return $
+      case format of
+        PNG -> png width height $ base64 imgData
+        SVG -> svg . T.decodeUtf8 $ imgData
 #if MIN_VERSION_Chart_cairo(1,3,0)
 mkFile opts filename renderable = renderableToFile opts filename renderable
 #else
--- a/ihaskell-charts.cabal
+++ b/ihaskell-charts.cabal
@@ -58,6 +58,8 @@ library
                        bytestring,
                        data-default-class,
                        directory,
+                       temporary,
+                       text,
                        Chart,
                        Chart-cairo >=1.2,
                        ihaskell >= 0.6.2
-- 
2.48.1

