next-sanity
next-sanity copied to clipboard
Optimizing Bundle Size
I'm currently trying to optimize my bundle size and this module has become a sticking point. I've follow the instructions in the README but @sanity/client is still being included in the bundle.
If I remove the import import { createPreviewSubscriptionHook } from "next-sanity";
from my sanity.ts and add
export const usePreviewSubscription = (query: string, options: PreviewOptions) => { //createPreviewSubscriptionHook(config);
return {
data: options.initialData,
};
}
in place of export const usePreviewSubscription = createPreviewSubscriptionHook(config);
I no longer see @sanity/client included in the bundle.
I'm testing this with nextjs-12.2.3-canary.10 using webpack5 configuration, unmodified from the default and @next/bundle-analyzer-12.1.6
I am also experiencing this.
Hi, we're working on a new version of preview mode that is easier to keep out of your bundle until it's actually needed.
It's an early version so we haven't added the code-splitting we want to yet (it loads a hefty eventsource
polyfill that's really only needed if Safari fails to use cookies with the groq subscription).
Feel free to share your thoughts on what the API should look like etc 🙂
We've just released v2.0.0
which encourages code-splitting out of the box by using React.lazy
. You shouldn't see @sanity/client
in your bundle anymore, unless it's actually used 😌