Override the default directory used by the disk-based editing cache implementation
The disk-based cache used for integrating JSS Next.js apps with advanced Sitecore content and layout editors uses, by default, the operating system temp directory. When hosting your Next.js application on Vercel, the default temp directory works fine. However, on other platforms, using the default temp directory can cause the editing data middleware to malfunction, resulting in intermittent 500 errors in Experience Editor.
You must override the directory used for the disk-based cache to resolve the errors.
To override the default temp directory:
-
In a new file, for example,
/src/lib/editing.ts, create an editing data disk cache, overriding the defaulttempdirectory with one of your choosing and a new editing data service that uses the new cache: -
In the
/src/pages/api/editing/data/[key].tsfile, update theEditingDataMiddlewarehandler to use the new editing data disk cache: -
In the
/src/pages/api/editing/render.tsfile, update the existing handler with a new instance of theEditingRenderMiddlewareclass that uses the new editing data service: -
Update the
src/lib/page-props-factory/plugins/preview-mode.tsfile so that thePreviewModePluginclass uses the new editing data service: