Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDU-159: Remix Gen1 - Advanced child sub components #3750

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

uttej-vsk
Copy link
Contributor

Description

This PR introduces remix gen 1 example for Advanced child sub-components in the custom components page in the docs.

ticket: https://builder-io.atlassian.net/browse/EDU-324
@samijaber Please review

@uttej-vsk uttej-vsk marked this pull request as ready for review November 19, 2024 17:47
@uttej-vsk uttej-vsk requested review from mrkoreye and removed request for a team November 19, 2024 17:47
Copy link

changeset-bot bot commented Nov 19, 2024

⚠️ No Changeset found

Latest commit: 03214c0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -45,4 +45,19 @@ test.describe('Editable regions in custom components', () => {
const secondText = await columns.nth(1).textContent();
expect(secondText?.trim().toLowerCase()).toBe('column 2 text');
});

test.describe('Remix gen1 editable regions text validation', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does remix gen1= have its own special test here? why aren't we enabling the existing tests in this spec for remix?

const page = await builder
.get("editable-regions", {
userAttributes: {
urlPath: `/${request.url.split("/").pop()}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of request.url.split("/").pop(), we can rely on remix's file naming conventions to extract the URL path as a param. See

};
export const loader: LoaderFunction = async ({ params }) => {
const { initializeNodeRuntime } = await import(
'@builder.io/sdk-react/node/init'
);
await initializeNodeRuntime();
return await getProps({ pathname: `/${params.slug || ''}` });
};

by naming the file ($slug).tsx, remix will automatically pass the URL path value to params.slug. This is far cleaner as an approach, so let's do things this way for Remix moving forward

Copy link
Contributor

@samijaber samijaber Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do it in the snippets already too. See:

export const loader = async ({ params, request }: LoaderFunctionArgs) => {
const announcementBar = await builder
.get('announcement-bar', {
userAttributes: {
urlPath: `/announcements/${params.slug ? params.slug : ''}`,
},
})
.toPromise();
const isPreviewing = new URL(request.url).searchParams.has('builder.preview');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just realized this suggestion of mine doesn't work because the routes you added in this PR are hardcoded with exact URLs 🤔

forget what i said for now, and let's stick with your approach

export const CustomHero = (props: CustomHeroProps) => {
return (
<>
<div>This is your component&apos;s text</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&apos; here is not pretty. can we use a '?

<>
<BuilderBlocks
parentElementId={props.builderBlock.id}
dataPath={`column1.blocks`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dataPath={`column1.blocks`}
dataPath="column1.blocks"


<BuilderBlocks
parentElementId={props.builderBlock.id}
dataPath={`column2.blocks`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dataPath={`column2.blocks`}
dataPath="column2.blocks"

name: "column1",
type: "uiBlocks",
broadcast: true,
hideFromUI: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we need hideFromUI for uiBlocks input types. Test that everything works as expected in the editor (that the UI block doesn't show up as an input in the Content Editor sidebase). If that's the case, let's remove it from everywhere in the snippets (this PR and elsewhere)


Builder.registerComponent(CustomHero, {
name: 'CustomHero',
inputs: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to provide an empty array, we can drop this altogether. If you can confirm that, go ahead and remove all empty inputs: []

Comment on lines +1 to +7
import { ReactNode } from 'react';

interface CustomHeroProps {
children: ReactNode;
}

export const CustomHero = (props: CustomHeroProps) => {
Copy link
Contributor

@samijaber samijaber Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { ReactNode } from 'react';
interface CustomHeroProps {
children: ReactNode;
}
export const CustomHero = (props: CustomHeroProps) => {
import { type PropsWithChildren } from 'react';
export const CustomHero = (props: PropsWithChildren) => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants