What are you trying to do? (please be as specific as possible and include relevant screenshots, code snippets)
I have created a code component with some data fetching logic and registered it on plasmic.
Then i have created a page on plasmic.
Now i have created a setup for SSR in my code base but page is not loading server side. When i am using PlasmicRootProvider by passing loading={PLASMIC} then i am getting.
“Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported.“
"use client";
import { PLASMIC, PlasmicRootProvider } from "@stadium/services/plasmic";
import MenuFetcherContainer from "@components/swagmagic/slices/menu-fetcher-container";
// You can register any code components that you want to use here; see
// https://docs.plasmic.app/learn/code-components-ref/
// And configure your Plasmic project to use the host url pointing at
// the /plasmic-host page of your nextjs app (for example,
// http://localhost:3000/plasmic-host). See
// https://docs.plasmic.app/learn/app-hosting/#set-a-plasmic-project-to-use-your-app-host
PLASMIC.registerComponent(MenuFetcherContainer, {
name: "MenuFetcherContainer",
isDefaultExport: true,
providesData: true,
importPath: "@components/swagmagic/slices/menu-fetcher-container",
props: {
children: {
type: "slot",
defaultValue: {
type: "text",
value: "Add your UI elements here",
},
},
className: {
type: "string",
},
storeNumber: {
type: "string",
defaultValue: "",
},
countryCode: {
type: "string",
defaultValue: "US",
},
showAllCategories: {
type: "boolean",
defaultValue: false,
defaultValueHint: true,
},
overrideSlugs: {
type: "array",
defaultValue: [],
},
},
});
/**
* PlasmicClientRootProvider is a Client Component that passes in the loader for you.
*
* Why? Props passed from Server to Client Components must be serializable.
* https://beta.nextjs.org/docs/rendering/server-and-client-components#passing-props-from-server-to-client-components-serialization
* However, PlasmicRootProvider requires a loader, but the loader is NOT serializable.
*/
export function PlasmicClientRootProvider(props) {
return <PlasmicRootProvider loader={PLASMIC} {...props}></PlasmicRootProvider>;
}
I have integrated Plasmic into my existing project; it was not created using create-plasmic-app.
I have added this component to one of my pages and populated its children using repeatElement based on the data. The component registers correctly in the Plasmic editor, but when I place it on a Plasmic-created page, it does not render on the server side. I want the entire page, including this component and its data, to load on the server side.
i have shared almost everything related plasmic i have in my project.
Please help me load the page (created in the Plasmic editor) on the server side.
@lokesh_mudgal It’s difficult to say exactly what’s causing this, but here are a few things you can try:
Remove component registration in your code component, it should only be registered once in plasmic-init-client.tsx (or plasmic-client.tsx, in your case)
Make sure you are initializing plasmic in a server-safe way, e.g. a simple plasmic-init.ts looks like:
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
import * as NextNavigation from "next/navigation";
export const PLASMIC = initPlasmicLoader({
nextNavigation: NextNavigation,
projects: [
{
id: "your-project-id",
token: "your-project-token",
},
],
preview: true, // Set to false in production
});
Make sure you’re using the server safe PLASMIC in your catchall
Basically, component registration must happen in a client component, and the loader instance should never be passed as a prop from server to client
components.
Core Plasmic Service → `packages/services/plasmic/index.ts`
import { initPlasmicLoader } from "@plasmicapp/loader-nextjs/react-server-conditional";
export const PLASMIC = initPlasmicLoader({
projects: [
{
id: *****,
token: *****,
},
],
// Fetches the latest revisions, whether or not they were unpublished!
// Disable for production to ensure you render only published changes.
preview: process.env.NODE_ENV === "development",
});
export {
PlasmicComponent,
PlasmicRootProvider,
PlasmicCanvasHost,
DataProvider,
usePlasmicQueryData,
} from "@plasmicapp/loader-nextjs";