SSR with app router

What we are trying to do is,

  • Create code components, register on plasmic and then by using those code components we will create pages on plasmic and publish them from there.

    • With Nextjs apps directory and by using plasmic loader.
  • Currently everything is working fine its just pages are rendering on client side. i want them to load complete page on server side.

How we have done that,

  • We have 3 code components, A wrapper which fetches data, and other 2 components will be added as its children on plasmic which uses data fetched in the Wrapper.

    • data is fetched using usePlasmicQueryData
  • Earlier i was passing fetched data in children like this

inside Wrapper

return (
    <div>
      {children &&
        React.Children.map(children, (child) => {
          if (!React.isValidElement(child)) return child;

          if (child.type === ChildOne) {
            return React.cloneElement(child, {
              ...<child one data evaluated from fetched data>
              ...child.props,
            });
          }

          if (child.type === ChildTwo)
             return React.cloneElement(child, {
              ...<child two data evaluated from fetched data>
              ...child.props,
            });

          return React.cloneElement(child, child.props);
        })}
    </div>
  );

now i am doing like this

inside Wrapper

 return (
    <div>
      <DataProvider name="data-key" data={fetchedData}>
        {children}
      </DataProvider>
    </div>
  );
  • and using useSelector in the child component for required data.
  • both of the methods are not working to render page completely on server side. UI is still created on client side.

What have you tried so far?

Relevant links:

1 Like

We will soon be launching a new way to fetch data that is compatible with Next.js app router and React Server Components. If you’d like to be a guinea pig, we can let you have early access and give us feedback on it.

@jason Yes, we would like to get early access.

Hey @jason, following up on this - any update ?

We’re still working on getting it ready for testing. I’ll notify you around the end of the week.

Alright @jason, Thanks.

Looking forward to your response

Hey @jason , following up on this - any update regarding new way to fetch data in server component ?