Pre Fetching Custom Post Types beforeSSR

Hello,

I pre fetch CPT before server side rendereding, but for some reasons it is very inconsistent (sometimes some CPT do not get added to the state at all)

This is the code im using in src / index.js

actions: {
    theme: {
      beforeSSR: ({ state, actions }) => {
        actions.source.fetch('/article',{ force: true });
        actions.source.fetch('/expertise',{ force: true });
        actions.source.fetch('/casestudy',{ force: true });
      },

Usually happens when the first loaded page is not the home page
Works just fine when first page to be loaded is home page
What could cause that?
Any chance someone knows what is wrong and/or a better way to do it?

update :

using
actions.source.fetch(state.source.get("/article")); actions.source.fetch(state.source.get("/expertise")); actions.source.fetch(state.source.get("/casestudy"));

seems to have “partially” fixed the issue, however the initial loading is much much much slower for some reason… way too slow

1 Like

Did you figure out how to make it load a lot faster? I’m experiencing the same issue. It works, it’s just that the whole site jumps after 3-4 seconds because it’s loading so slowly