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
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/fluffy-eyes-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/mitosis': patch
---

[react]: Changed `defaultProps` generation for react, because defaultProps for function components is deprecated
18 changes: 18 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,21 @@ jobs:

- name: Run E2E tests
run: yarn ci:e2e

- name: 🆙 Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-results
path: ./e2e/e2e-app/test-results
retention-days: 14

- name: 🆙 Upload e2e builds
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-builds
path: |
./e2e/**/dist
!**/node_modules/**
retention-days: 14
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/',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useDefaultProps, useStore } from '@builder.io/mitosis';

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

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

export default function DefaultProps(props: DefaultPropsType) {
const state = useStore({
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
Expand Up @@ -2,6 +2,7 @@ import { For, onMount, Show, useStore } from '@builder.io/mitosis';
import { COMPONENT_PATHS } from './component-paths';
import ComponentOnUpdate from './components/component-on-update.lite';
import ComponentWithTypes from './components/component-with-types.lite';
import DefaultProps from './components/default-props/use-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';
Expand Down Expand Up @@ -43,6 +44,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>
Expand Down
12 changes: 12 additions & 0 deletions e2e/e2e-app/tests/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ const test = playwrightTest.extend<{ packageName: PackageName | 'DEFAULT' }>({
});

test.describe('e2e', () => {
test('default props', async ({ page, packageName }) => {
// TODO: Some targets don't support `defaultProps` :(
if (['e2e-qwik', 'e2e-solid'].includes(packageName)) {
test.skip();
}

await page.goto('/default-props/');
const text = await page.getByTestId('default-props').textContent();

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

Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Mitosis output for not yet include .d.ts, so ignore the types when importing.
// Trigger nx remote cache: 2
// Trigger nx remote cache: 3
// @ts-ignore
import { E2eApp } from '@builder.io/e2e-app/react';

Expand Down
28 changes: 28 additions & 0 deletions packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3086,6 +3086,20 @@ exports[`Alpine.js > jsx > Javascript Test > typeDependency 1`] = `
"
`;

exports[`Alpine.js > jsx > Javascript Test > typeExternalProps 1`] = `
"<div x-data=\\"typeExternalProps()\\">
Hello
<span x-html=\\"name\\"></span>
!
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"typeExternalProps\\", () => ({}));
});
</script>
"
`;

exports[`Alpine.js > jsx > Javascript Test > typeExternalStore 1`] = `
"<div x-data=\\"typeExternalStore()\\">
Hello
Expand Down Expand Up @@ -6323,6 +6337,20 @@ exports[`Alpine.js > jsx > Typescript Test > typeDependency 1`] = `
"
`;

exports[`Alpine.js > jsx > Typescript Test > typeExternalProps 1`] = `
"<div x-data=\\"typeExternalProps()\\">
Hello
<span x-html=\\"name\\"></span>
!
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"typeExternalProps\\", () => ({}));
});
</script>
"
`;

exports[`Alpine.js > jsx > Typescript Test > typeExternalStore 1`] = `
"<div x-data=\\"typeExternalStore()\\">
Hello
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7541,6 +7541,38 @@ export class TypeDependencyModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Javascript Test > typeExternalProps 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component, Input } from \\"@angular/core\\";

@Component({
selector: \\"type-external-props\\",
template: \`
<div>Hello {{name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeExternalProps {
@Input() name;
}

@NgModule({
declarations: [TypeExternalProps],
imports: [CommonModule],
exports: [TypeExternalProps],
})
export class TypeExternalPropsModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Javascript Test > typeExternalStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -15949,6 +15981,40 @@ export class TypeDependencyModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Typescript Test > typeExternalProps 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component, Input } from \\"@angular/core\\";

import { FooProps } from \\"./foo-props\\";

@Component({
selector: \\"type-external-props\\",
template: \`
<div>Hello {{name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeExternalProps {
@Input() name!: FooProps[\\"name\\"];
}

@NgModule({
declarations: [TypeExternalProps],
imports: [CommonModule],
exports: [TypeExternalProps],
})
export class TypeExternalPropsModule {}
"
`;

exports[`Angular with Preserve Imports and File Extensions > jsx > Typescript Test > typeExternalStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7667,6 +7667,39 @@ export class TypeDependencyModule {}
"
`;

exports[`Angular with Import Mapper Tests > jsx > Javascript Test > typeExternalProps 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component, Input } from \\"@angular/core\\";

@Component({
selector: \\"type-external-props\\",
template: \`
<div>Hello {{name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeExternalProps {
@Input() name;
}

@NgModule({
declarations: [TypeExternalProps],
imports: [CommonModule],
exports: [TypeExternalProps],
bootstrap: [SomeOtherComponent],
})
export class TypeExternalPropsModule {}
"
`;

exports[`Angular with Import Mapper Tests > jsx > Javascript Test > typeExternalStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -16212,6 +16245,41 @@ export class TypeDependencyModule {}
"
`;

exports[`Angular with Import Mapper Tests > jsx > Typescript Test > typeExternalProps 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component, Input } from \\"@angular/core\\";

import { FooProps } from \\"./foo-props\\";

@Component({
selector: \\"type-external-props\\",
template: \`
<div>Hello {{name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeExternalProps {
@Input() name!: FooProps[\\"name\\"];
}

@NgModule({
declarations: [TypeExternalProps],
imports: [CommonModule],
exports: [TypeExternalProps],
bootstrap: [SomeOtherComponent],
})
export class TypeExternalPropsModule {}
"
`;

exports[`Angular with Import Mapper Tests > jsx > Typescript Test > typeExternalStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7810,6 +7810,38 @@ export class TypeDependencyModule {}
"
`;

exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Javascript Test > typeExternalProps 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component, Input } from \\"@angular/core\\";

@Component({
selector: \\"type-external-props\\",
template: \`
<div>Hello {{name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeExternalProps {
@Input() name;
}

@NgModule({
declarations: [TypeExternalProps],
imports: [CommonModule],
exports: [TypeExternalProps],
})
export class TypeExternalPropsModule {}
"
`;

exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Javascript Test > typeExternalStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down Expand Up @@ -16546,6 +16578,40 @@ export class TypeDependencyModule {}
"
`;

exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Typescript Test > typeExternalProps 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";

import { Component, Input } from \\"@angular/core\\";

import { FooProps } from \\"./foo-props\\";

@Component({
selector: \\"type-external-props\\",
template: \`
<div>Hello {{name}} !</div>
\`,
styles: [
\`
:host {
display: contents;
}
\`,
],
})
export default class TypeExternalProps {
@Input() name!: FooProps[\\"name\\"];
}

@NgModule({
declarations: [TypeExternalProps],
imports: [CommonModule],
exports: [TypeExternalProps],
})
export class TypeExternalPropsModule {}
"
`;

exports[`Angular with manually creating and handling class properties as bindings (more stable) > jsx > Typescript Test > typeExternalStore 1`] = `
"import { NgModule } from \\"@angular/core\\";
import { CommonModule } from \\"@angular/common\\";
Expand Down
Loading