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

refactor: change defaultProps generation for react #1661

Merged
merged 25 commits into from
Feb 28, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
08601cc
refactor: change defaultProps generation for react
nmerget Jan 15, 2025
89fa706
chore: update snapshots
nmerget Jan 15, 2025
2f2a09f
Merge branch 'refs/heads/main' into refactor-react-default-props
nmerget Jan 16, 2025
fb0f169
refactor: default props passing for react
nmerget Jan 16, 2025
ea0a513
fix: issues with e2e tests
nmerget Jan 16, 2025
ae011cb
fix: issue with e2e for stencil
nmerget Jan 16, 2025
af767e2
chore: run fmt
nmerget Jan 16, 2025
d976239
fix: issue with vue default props
nmerget Jan 16, 2025
c979fce
fix: issue with default props for e2e tests
nmerget Jan 16, 2025
45dcee4
fix: issue with stencil e2e test for default props
nmerget Jan 16, 2025
37d430e
fix: issue with stencil types for e2e
nmerget Jan 16, 2025
e79fc03
fix: issue with stencil local exports
nmerget Jan 17, 2025
4019365
chore: add test results upload to find issues with e2e tests
nmerget Jan 17, 2025
3a280dc
chore: rename default-props.lite.tsx to fix issue with react e2e
nmerget Jan 17, 2025
d319ea5
chore: provide e2e builds on failure
nmerget Jan 17, 2025
d5fd05a
chore: exclude node_modules
nmerget Jan 17, 2025
95b5378
test: trigger avoiding nx remote cache
nmerget Jan 17, 2025
aba9846
Merge remote-tracking branch 'builderIO/main' into refactor-react-def…
nmerget Feb 25, 2025
d1bd12e
fix: issue with rsc functions
nmerget Feb 25, 2025
f0909e4
chore: update snapshots
nmerget Feb 26, 2025
8f9309c
Merge remote-tracking branch 'builderIO/main' into refactor-react-def…
nmerget Feb 28, 2025
18fd018
fix: issue with doubled variable name
nmerget Feb 28, 2025
69033a3
Merge branch 'main' into refactor-react-default-props
nmerget Feb 28, 2025
dcc8d32
chore: update snapshots
nmerget Feb 28, 2025
d3346e5
Merge remote-tracking branch 'origin/refactor-react-default-props' in…
nmerget Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: default props passing for react
nmerget committed Jan 16, 2025
commit fb0f16977fb2f98211d9e43c562ffe909ceee836
1 change: 1 addition & 0 deletions e2e/e2e-app/src/component-paths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const COMPONENT_PATHS = [
'/default-props/',
'/one-component/',
'/two-components/',
'/types/',
22 changes: 22 additions & 0 deletions e2e/e2e-app/src/components/default-props.lite.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useDefaultProps, useStore } from '@builder.io/mitosis';

type Props = {
foo?: string;
bar?: string;
};

type State = {
getProps: () => string;
};

useDefaultProps<Props>({ foo: 'abc', bar: 'foo' });

export default function DefaultProps(props: Props) {
const state = useStore<State>({
getProps: () => {
return JSON.stringify({ foo: props.foo, bar: props.bar });
},
});

return <div data-testid="default-props">{state.getProps()}</div>;
}
5 changes: 5 additions & 0 deletions e2e/e2e-app/src/homepage.lite.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { For, onMount, Show, useStore } from '@builder.io/mitosis';
import { COMPONENT_PATHS } from './component-paths';
import ComponentWithTypes from './components/component-with-types.lite';
import DefaultProps from './components/default-props.lite';
import DisabledInput from './components/disabled-input/disabled-input.lite';
import NestedParent from './components/nested/nested-parent.lite';
import OneComponent from './components/one-component.lite';
@@ -42,6 +43,10 @@ export default function Homepage(props: { pathname?: string }) {
<NestedParent />
</Show>

<Show when={state.pathToUse.startsWith('/default-props')}>
<DefaultProps bar="xyz" />
</Show>

<Show when={state.pathToUse.startsWith('/types')}>
<ComponentWithTypes name="Lorem ipsum" />
</Show>
7 changes: 7 additions & 0 deletions e2e/e2e-app/tests/main.spec.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,13 @@ const test = playwrightTest.extend<{ packageName: PackageName | 'DEFAULT' }>({
});

test.describe('e2e', () => {
test('default props', async ({ page }) => {
await page.goto('/default-props/');
const text = await page.getByTestId('default-props').allTextContents();

expect(text.includes('abc')).toBeTruthy();
expect(text.includes('xyz')).toBeTruthy();
});
test('todo list add', async ({ page }) => {
await page.goto('/one-component/');

74 changes: 42 additions & 32 deletions packages/core/src/__tests__/__snapshots__/mitosis.test.ts.snap
Original file line number Diff line number Diff line change
@@ -15416,9 +15416,13 @@ exports[`Mitosis, format: react > jsx > Javascript Test > ContentSlotJSX 1`] = `
import * as React from \\"react\\";
import { useState } from \\"react\\";

function ContentSlotJsxCode(
props = { content: \\"\\", slotReference: undefined, slotContent: undefined }
) {
function ContentSlotJsxCode(props) {
props = {
...props,
content: \\"\\",
slotReference: undefined,
slotContent: undefined,
};
const [name, setName] = useState(() => \\"king\\");

const [showContent, setShowContent] = useState(() => false);
@@ -16933,16 +16937,16 @@ exports[`Mitosis, format: react > jsx > Javascript Test > defaultProps 1`] = `
"\\"use client\\";
import * as React from \\"react\\";

function Button(
function Button(props) {
props = {
...props,
text: \\"default text\\",
link: \\"https://builder.io/\\",
openLinkInNewTab: false,
onClick: () => {
console.log(\\"hi\\");
},
}
) {
};
return (
<div>
{props.link ? (
@@ -16975,14 +16979,14 @@ exports[`Mitosis, format: react > jsx > Javascript Test > defaultPropsOutsideCom
"\\"use client\\";
import * as React from \\"react\\";

function Button(
function Button(props) {
props = {
...props,
text: \\"default text\\",
link: \\"https://builder.io/\\",
openLinkInNewTab: false,
onClick: () => {},
}
) {
};
return (
<div>
{props.link ? (
@@ -19119,9 +19123,13 @@ import * as React from \\"react\\";
import { useState } from \\"react\\";
import type { JSX } from \\"../../../../jsx-runtime\\";

function ContentSlotJsxCode(
props = { content: \\"\\", slotReference: undefined, slotContent: undefined }
) {
function ContentSlotJsxCode(props) {
props = {
...props,
content: \\"\\",
slotReference: undefined,
slotContent: undefined,
};
const [name, setName] = useState(() => \\"king\\");

const [showContent, setShowContent] = useState(() => false);
@@ -20644,16 +20652,16 @@ exports[`Mitosis, format: react > jsx > Typescript Test > defaultProps 1`] = `
"\\"use client\\";
import * as React from \\"react\\";

function Button(
function Button(props) {
props = {
...props,
text: \\"default text\\",
link: \\"https://builder.io/\\",
openLinkInNewTab: false,
onClick: () => {
console.log(\\"hi\\");
},
}
) {
};
return (
<div>
{props.link ? (
@@ -20686,14 +20694,14 @@ exports[`Mitosis, format: react > jsx > Typescript Test > defaultPropsOutsideCom
"\\"use client\\";
import * as React from \\"react\\";

function Button(
function Button(props) {
props = {
...props,
text: \\"default text\\",
link: \\"https://builder.io/\\",
openLinkInNewTab: false,
onClick: () => {},
}
) {
};
return (
<div>
{props.link ? (
@@ -22293,7 +22301,8 @@ exports[`Mitosis, format: react > svelte > Javascript Test > classDirective 1`]
import * as React from \\"react\\";
import { useState } from \\"react\\";

function MyComponent(props = {}) {
function MyComponent(props) {
props = { ...props };
const [focus, setFocus] = useState(() => true);

return (
@@ -22310,14 +22319,14 @@ export default MyComponent;
`;

exports[`Mitosis, format: react > svelte > Javascript Test > context 1`] = `
"'>' expected. (31:13)
29 | return (
30 |
> 31 | <'activeTab'.Provider value={activeTab}><div>{activeTab}</div></'activeTab'.Provider>
"'>' expected. (32:13)
30 | return (
31 |
> 32 | <'activeTab'.Provider value={activeTab}><div>{activeTab}</div></'activeTab'.Provider>
| ^
32 |
33 |
34 |"
34 |
35 |"
`;

exports[`Mitosis, format: react > svelte > Javascript Test > each 1`] = `
@@ -22692,7 +22701,8 @@ exports[`Mitosis, format: react > svelte > Typescript Test > classDirective 1`]
import * as React from \\"react\\";
import { useState } from \\"react\\";

function MyComponent(props = {}) {
function MyComponent(props) {
props = { ...props };
const [focus, setFocus] = useState(() => true);

return (
@@ -22709,14 +22719,14 @@ export default MyComponent;
`;

exports[`Mitosis, format: react > svelte > Typescript Test > context 1`] = `
"'>' expected. (31:13)
29 | return (
30 |
> 31 | <'activeTab'.Provider value={activeTab}><div>{activeTab}</div></'activeTab'.Provider>
"'>' expected. (32:13)
30 | return (
31 |
> 32 | <'activeTab'.Provider value={activeTab}><div>{activeTab}</div></'activeTab'.Provider>
| ^
32 |
33 |
34 |"
34 |
35 |"
`;

exports[`Mitosis, format: react > svelte > Typescript Test > each 1`] = `
Loading