Custom component not showing up

I have implemented Builder in my nextJs codebase and now I am trying to add custom components to it. Unfortunately I am not able to register my components to get uploaded to the builder editor.

import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next';
import { useRouter } from 'next/router';
import { BuilderComponent, Builder, builder } from '@builder.io/react';
import DefaultErrorPage from 'next/error';
import Head from 'next/head';

const BUILDER_API_KEY = 'my_key';
builder.init(BUILDER_API_KEY);

import 'components/shared/NavBar';

// tells you what paths are being built
export async function getStaticProps({ params }: GetStaticPropsContext<{ page: string[] }>) {
	const page =
		(await builder
			.get('page', {
				userAttributes: {
					urlPath: '/' + (params?.page?.join('/') || ''),
				},
			})
			.toPromise()) || null;

	return {
		props: {
			page,
		},
		// Next.js will attempt to re-generate the page:
		// - When a request comes in
		// - At most once every 5 seconds
		revalidate: true,
	};
}

// returns a list
export async function getStaticPaths() {
	const pages = await builder.getAll('page', {
		options: { noTargeting: true },
		omit: 'data.blocks',
	});

	return {
		paths: pages.map((page) => `${page.data?.url}`),
		fallback: true,
	};
}

// React Component
export default function Page({ page }: InferGetStaticPropsType<typeof getStaticProps>) {
	const router = useRouter();
	if (router.isFallback) {
		return <h1>Loading...</h1>;
	}
	const isLive = !Builder.isEditing && !Builder.isPreviewing;
	if (!page && isLive) {
		return (
			<>
				<Head>
					<meta name="robots" content="noindex" />
					<meta name="title"></meta>
				</Head>
				<DefaultErrorPage statusCode={404} />
			</>
		);
	}

	return (
		<>
			<Head>
				<meta name="viewport" content="width=device-width, initial-scale=1" />
			</Head>

			<BuilderComponent model="page" content={page} />
		</>
	);
}

import { Builder } from '@builder.io/react';
import React from 'react';
import { NavBarLink, NavBarLinkProps } from './NavBarLink';

interface NavBarProps {
	links: NavBarLinkProps[];
}

export const NavBar: React.FunctionComponent<NavBarProps> = (props) => {
	const { links } = props;
	return (
		<nav className="w-full bg-black">
			{links.map((x) => (
				<NavBarLink key={x.link} text={x.text} link={x.link} />
			))}
		</nav>
	);
};

Builder.registerComponent(NavBar, {
	name: 'NavBar Coded',
	inputs: [
		{
			name: 'links',
			type: 'list',
			subFields: [
				{ name: 'text', type: 'string' },
				{ name: 'link', type: 'string' },
			],
		},
	],
});

Does anybody may have a suggestion how to tackle this problem?

Hello Niko, thank you for your patience. Did you replace the API key with your own? If so and you’re still having trouble are there any console errors or additional details you could share? I can also help you look into this further if you share a code sandbox and a link to your builder content page.

I am having the same issue. Did this ever get resolved? If so, do you mind sharing your solution?

Hi @hlopez if you share your code and a link to your builder content page I can help you look into it. The code above seems valid. I’ve noticed that often times when users don’t see their custom component in the menu and everything else is working fine it is because the preview URL needs to be updated to your local dev server (e.g. localhost:3000) or the domain where your app is deployed. Let me know if that helps!

Thank you so much @ancheetah, that solved the issue.

1 Like

@ancheetah I’m having a similar issue, right now I’m only working on a proof-of-concept integration locally.

I already had access to my custom components but their availability seems volatile, after a refresh they disappeared and I’m having trouble figuring out how to make them reliably present in the editor.

Any tips would be appreciated.

Hi @Atti , if you’ve followed the steps above and they only disappear intermittently it is possible this could be a bug but hard to tell without seeing it. Since this is occurring locally, it would be great if you could share a reproduction via Github or deploy so I can take a closer look. Thanks!

Hey @manish-sharma , i hope you are doing well

Well, i am facing this problem in only my sections page i mean i have created a Custom Components and i am getting it in my Page Models its showing up there but when i go the the Section Models

its not showing my custom components in there

here you can see im getting my custom component in pages models but when i go to the Section Models im not getting my custom components there

is there any specific reason for this or what ??

Hello @Shami, you can find help at Unable to register custom components - #3 by manish-sharma to resolve the issue where the custom component is not showing.

We are also experiencing issues with our custom components. Within the last 7-10 days they have disappeared. They seem to work on existing pages but not on new ones. We haven’t made any code changes. We have been using custom components for over 2 years.

Here’s a video showing the issue.

@manish-sharma Can you help with this?

Hello @spm922, Could you please confirm the version of the builder SDK you are using and whether you are using builder dev tools?

    "@builder.io/dev-tools": "latest",
    "@builder.io/react": "^3.2.2",
    "@builder.io/sdk": "latest",

We are running the following

    "@builder.io/react": "^3.2.6"

Are @builder.io/dev-tools and builder.io/sdk dependencies of the @builder.io/react? We have never had these in our package.json

@manish-sharma Just wanted to follow up here. Do you know have any thoughts?

Hello @spm922 ,

To assist you better, could you please share a screenshot of your project directory structure? Additionally, it would be helpful if you could provide details on how and where you are registering those custom components within your project.

@manish-sharma Our components are registered within our page model.

Here is directory structure for our custom components

These are imported into [[…page]].tsx which creates the <BuilderComponent model="page" content={page} options={{ includeRefs: true }} key={router.asPath}/>

I think I figured this out. We recently implemented Sentry.io which appears to be sending additional headers as part of it’s preflight requests which is being blocked by the builder CORS policy.

Ideally we would like to see traces to measure performance from builder.io. Is there any way to configure these headers?

Hello @spm922,

Unfortunately, Builder.io does not currently offer a built-in feature to configure headers for tracing purposes. However, you may be able to implement a workaround by modifying your server configuration or using a proxy server.

One possible approach is to set up a proxy server that sits between your application and Builder.io. This proxy server can intercept requests to Builder.io and modify the headers before forwarding them. By configuring the proxy server to add the necessary headers for tracing, you can ensure that traces are captured while still allowing Sentry.io requests to proceed without interference.

Alternatively, you could explore options within Sentry.io to adjust its request behavior and reduce the number of additional headers sent during preflight requests. This may involve adjusting settings or configurations within Sentry.io to minimize its impact on CORS policies.

Ultimately, the specific solution will depend on your infrastructure setup and requirements.

Thanks,