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

fix: issue with state inside key of Fragment for React and Angular #1641

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .changeset/yellow-coins-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@builder.io/mitosis': patch
---

[React, Angular] fix: issue with ``state`` inside `key` attribute in `Fragment`.

Example:

`<Fragment key={state.xxx + "abc"}...` was generated in React with `state.xxx` and in Angular without `this.`.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: snapshots-updates
path: ./packages/core/src/__tests__/__snapshots__
path: ./packages/core/src/**/__snapshots__
retention-days: 30

site:
Expand Down
32 changes: 30 additions & 2 deletions packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1555,10 +1555,24 @@ exports[`Alpine.js > jsx > Javascript Test > basicForFragment 1`] = `
<div><span x-html=\\"option\\"></span></div>
</div>
</template>
<template x-for=\\"option in ['a', 'b', 'c']\\">
<div x-bind:key=\\"\`\${id}-\${option}\`\\">
<div><span x-html=\\"option\\"></span></div>
</div>
</template>
<select>
<template x-for=\\"option in ['d', 'e', 'f']\\">
<option x-bind:key=\\"\`\${id}-\${option}\`\\" x-bind:value=\\"option\\">
<span x-html=\\"option\\"></span>
</option>
</template>
</select>
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"basicForFragment\\", () => ({}));
Alpine.data(\\"basicForFragment\\", () => ({
id: \\"xyz\\",
}));
});
</script>
"
Expand Down Expand Up @@ -4608,10 +4622,24 @@ exports[`Alpine.js > jsx > Typescript Test > basicForFragment 1`] = `
<div><span x-html=\\"option\\"></span></div>
</div>
</template>
<template x-for=\\"option in ['a', 'b', 'c']\\">
<div x-bind:key=\\"\`\${id}-\${option}\`\\">
<div><span x-html=\\"option\\"></span></div>
</div>
</template>
<select>
<template x-for=\\"option in ['d', 'e', 'f']\\">
<option x-bind:key=\\"\`\${id}-\${option}\`\\" x-bind:value=\\"option\\">
<span x-html=\\"option\\"></span>
</option>
</template>
</select>
</div>
<script>
document.addEventListener(\\"alpine:init\\", () => {
Alpine.data(\\"basicForFragment\\", () => ({}));
Alpine.data(\\"basicForFragment\\", () => ({
id: \\"xyz\\",
}));
});
</script>
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3414,6 +3414,20 @@ import { Component } from \\"@angular/core\\";
<div>{{option}}</div>
</ng-container>
</ng-container>
<ng-container
*ngFor=\\"let option of ['a', 'b', 'c']; trackBy: trackByOption1\\"
>
<ng-container>
<div>{{option}}</div>
</ng-container>
</ng-container>
<select>
<ng-container
*ngFor=\\"let option of ['d', 'e', 'f']; trackBy: trackByOption2\\"
>
<option [attr.value]=\\"option\\">{{option}}</option>
</ng-container>
</select>
</div>
\`,
styles: [
Expand All @@ -3425,9 +3439,16 @@ import { Component } from \\"@angular/core\\";
],
})
export default class BasicForFragment {
id = \\"xyz\\";
trackByOption0(_, option) {
return \`key-\${option}\`;
}
trackByOption1(_, option) {
return \`\${this.id}-\${option}\`;
}
trackByOption2(_, option) {
return \`\${this.id}-\${option}\`;
}
}

@NgModule({
Expand Down Expand Up @@ -11081,6 +11102,20 @@ import { Component } from \\"@angular/core\\";
<div>{{option}}</div>
</ng-container>
</ng-container>
<ng-container
*ngFor=\\"let option of ['a', 'b', 'c']; trackBy: trackByOption1\\"
>
<ng-container>
<div>{{option}}</div>
</ng-container>
</ng-container>
<select>
<ng-container
*ngFor=\\"let option of ['d', 'e', 'f']; trackBy: trackByOption2\\"
>
<option [attr.value]=\\"option\\">{{option}}</option>
</ng-container>
</select>
</div>
\`,
styles: [
Expand All @@ -11092,9 +11127,16 @@ import { Component } from \\"@angular/core\\";
],
})
export default class BasicForFragment {
id = \\"xyz\\";
trackByOption0(_, option) {
return \`key-\${option}\`;
}
trackByOption1(_, option) {
return \`\${this.id}-\${option}\`;
}
trackByOption2(_, option) {
return \`\${this.id}-\${option}\`;
}
}

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3461,6 +3461,20 @@ import { Component } from \\"@angular/core\\";
<div>{{option}}</div>
</ng-container>
</ng-container>
<ng-container
*ngFor=\\"let option of ['a', 'b', 'c']; trackBy: trackByOption1\\"
>
<ng-container>
<div>{{option}}</div>
</ng-container>
</ng-container>
<select>
<ng-container
*ngFor=\\"let option of ['d', 'e', 'f']; trackBy: trackByOption2\\"
>
<option [attr.value]=\\"option\\">{{option}}</option>
</ng-container>
</select>
</div>
\`,
styles: [
Expand All @@ -3472,9 +3486,16 @@ import { Component } from \\"@angular/core\\";
],
})
export default class BasicForFragment {
id = \\"xyz\\";
trackByOption0(_, option) {
return \`key-\${option}\`;
}
trackByOption1(_, option) {
return \`\${this.id}-\${option}\`;
}
trackByOption2(_, option) {
return \`\${this.id}-\${option}\`;
}
}

@NgModule({
Expand Down Expand Up @@ -11254,6 +11275,20 @@ import { Component } from \\"@angular/core\\";
<div>{{option}}</div>
</ng-container>
</ng-container>
<ng-container
*ngFor=\\"let option of ['a', 'b', 'c']; trackBy: trackByOption1\\"
>
<ng-container>
<div>{{option}}</div>
</ng-container>
</ng-container>
<select>
<ng-container
*ngFor=\\"let option of ['d', 'e', 'f']; trackBy: trackByOption2\\"
>
<option [attr.value]=\\"option\\">{{option}}</option>
</ng-container>
</select>
</div>
\`,
styles: [
Expand All @@ -11265,9 +11300,16 @@ import { Component } from \\"@angular/core\\";
],
})
export default class BasicForFragment {
id = \\"xyz\\";
trackByOption0(_, option) {
return \`key-\${option}\`;
}
trackByOption1(_, option) {
return \`\${this.id}-\${option}\`;
}
trackByOption2(_, option) {
return \`\${this.id}-\${option}\`;
}
}

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3543,6 +3543,20 @@ import { Component } from \\"@angular/core\\";
<div>{{option}}</div>
</ng-container>
</ng-container>
<ng-container
*ngFor=\\"let option of ['a', 'b', 'c']; trackBy: trackByOption1\\"
>
<ng-container>
<div>{{option}}</div>
</ng-container>
</ng-container>
<select>
<ng-container
*ngFor=\\"let option of ['d', 'e', 'f']; trackBy: trackByOption2\\"
>
<option [attr.value]=\\"option\\">{{option}}</option>
</ng-container>
</select>
</div>
\`,
styles: [
Expand All @@ -3554,9 +3568,16 @@ import { Component } from \\"@angular/core\\";
],
})
export default class BasicForFragment {
id = \\"xyz\\";
trackByOption0(_, option) {
return \`key-\${option}\`;
}
trackByOption1(_, option) {
return \`\${this.id}-\${option}\`;
}
trackByOption2(_, option) {
return \`\${this.id}-\${option}\`;
}
}

@NgModule({
Expand Down Expand Up @@ -11485,6 +11506,20 @@ import { Component } from \\"@angular/core\\";
<div>{{option}}</div>
</ng-container>
</ng-container>
<ng-container
*ngFor=\\"let option of ['a', 'b', 'c']; trackBy: trackByOption1\\"
>
<ng-container>
<div>{{option}}</div>
</ng-container>
</ng-container>
<select>
<ng-container
*ngFor=\\"let option of ['d', 'e', 'f']; trackBy: trackByOption2\\"
>
<option [attr.value]=\\"option\\">{{option}}</option>
</ng-container>
</select>
</div>
\`,
styles: [
Expand All @@ -11496,9 +11531,16 @@ import { Component } from \\"@angular/core\\";
],
})
export default class BasicForFragment {
id = \\"xyz\\";
trackByOption0(_, option) {
return \`key-\${option}\`;
}
trackByOption1(_, option) {
return \`\${this.id}-\${option}\`;
}
trackByOption2(_, option) {
return \`\${this.id}-\${option}\`;
}
}

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3113,13 +3113,34 @@ import { Component } from \\"@angular/core\\";
<div>{{option}}</div>
</ng-container>
</ng-container>
<ng-container
*ngFor=\\"let option of ['a', 'b', 'c']; trackBy: trackByOption1\\"
>
<ng-container>
<div>{{option}}</div>
</ng-container>
</ng-container>
<select>
<ng-container
*ngFor=\\"let option of ['d', 'e', 'f']; trackBy: trackByOption2\\"
>
<option [attr.value]=\\"option\\">{{option}}</option>
</ng-container>
</select>
</div>
\`,
})
export default class BasicForFragment {
id = \\"xyz\\";
trackByOption0(_, option) {
return \`key-\${option}\`;
}
trackByOption1(_, option) {
return \`\${this.id}-\${option}\`;
}
trackByOption2(_, option) {
return \`\${this.id}-\${option}\`;
}
}

@NgModule({
Expand Down Expand Up @@ -9974,13 +9995,34 @@ import { Component } from \\"@angular/core\\";
<div>{{option}}</div>
</ng-container>
</ng-container>
<ng-container
*ngFor=\\"let option of ['a', 'b', 'c']; trackBy: trackByOption1\\"
>
<ng-container>
<div>{{option}}</div>
</ng-container>
</ng-container>
<select>
<ng-container
*ngFor=\\"let option of ['d', 'e', 'f']; trackBy: trackByOption2\\"
>
<option [attr.value]=\\"option\\">{{option}}</option>
</ng-container>
</select>
</div>
\`,
})
export default class BasicForFragment {
id = \\"xyz\\";
trackByOption0(_, option) {
return \`key-\${option}\`;
}
trackByOption1(_, option) {
return \`\${this.id}-\${option}\`;
}
trackByOption2(_, option) {
return \`\${this.id}-\${option}\`;
}
}

@NgModule({
Expand Down
Loading