Skip to content

Commit

Permalink
Fix: useTarget + useState (#1596)
Browse files Browse the repository at this point in the history
* f

* f
  • Loading branch information
samijaber authored Oct 17, 2024
1 parent 628211d commit 0aa642a
Show file tree
Hide file tree
Showing 27 changed files with 303 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-pears-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@builder.io/mitosis': patch
---

[All]: Fix: accessing `useState()` getter/setter within `useTarget()`
8 changes: 4 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
cache-install-state: true

- name: Build
run: yarn ci:build --verbose
run: yarn ci:build

test:
runs-on: ubuntu-latest
Expand All @@ -71,7 +71,7 @@ jobs:
cache-install-state: true

- name: Run tests
run: yarn ci:test --verbose
run: yarn ci:test

site:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
cache-install-state: true

- name: Build
run: yarn ci:build --verbose
run: yarn ci:build

- name: Run E2E tests
run: yarn ci:e2e --verbose
run: yarn ci:e2e
12 changes: 10 additions & 2 deletions packages/core/src/__tests__/__snapshots__/alpine.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2771,8 +2771,12 @@ exports[`Alpine.js > jsx > Javascript Test > useTarget 1`] = `
},
lastName: \\"bar\\",
foo: \\"bar\\",
init() {},
init() {
console.log(this.foo);
this.foo = \\"bar\\";
},
}));
});
</script>
Expand Down Expand Up @@ -5577,8 +5581,12 @@ exports[`Alpine.js > jsx > Typescript Test > useTarget 1`] = `
},
lastName: \\"bar\\",
foo: \\"bar\\",
init() {},
init() {
console.log(this.foo);
this.foo = \\"bar\\";
},
}));
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6858,9 +6858,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down Expand Up @@ -14273,9 +14276,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6971,9 +6971,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down Expand Up @@ -14504,9 +14507,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7076,9 +7076,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down Expand Up @@ -14734,9 +14737,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6132,9 +6132,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down Expand Up @@ -12805,9 +12808,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/__tests__/__snapshots__/angular.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12868,9 +12868,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down Expand Up @@ -12909,9 +12912,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down Expand Up @@ -26852,9 +26858,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down Expand Up @@ -26893,9 +26902,12 @@ export default class UseTargetComponent {
return prefix + \\"foo\\";
}
lastName = \\"bar\\";
foo = \\"bar\\";

ngOnInit() {
if (typeof window !== \\"undefined\\") {
console.log(this.foo);
this.foo = \\"bar\\";
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/__tests__/__snapshots__/html.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6831,6 +6831,7 @@ exports[`Html > jsx > Javascript Test > useTarget 1`] = `
return prefix + \\"foo\\";
},
lastName: \\"bar\\",
foo: \\"bar\\",
};

let context = null;
Expand Down Expand Up @@ -6865,6 +6866,9 @@ exports[`Html > jsx > Javascript Test > useTarget 1`] = `
update();

// onMount
console.log(state.foo);
state.foo = \\"bar\\";
update();

// Helper text DOM nodes
function renderTextNode(el, text) {
Expand Down Expand Up @@ -13784,6 +13788,7 @@ exports[`Html > jsx > Typescript Test > useTarget 1`] = `
return prefix + \\"foo\\";
},
lastName: \\"bar\\",
foo: \\"bar\\",
};

let context = null;
Expand Down Expand Up @@ -13818,6 +13823,9 @@ exports[`Html > jsx > Typescript Test > useTarget 1`] = `
update();

// onMount
console.log(state.foo);
state.foo = \\"bar\\";
update();

// Helper text DOM nodes
function renderTextNode(el, text) {
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/__tests__/__snapshots__/lit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4172,13 +4172,17 @@ export default class UseTargetComponent extends LitElement {
}

@state() lastName = \\"bar\\";
@state() foo = \\"bar\\";

get name() {
const prefix = \\"li\\";
return prefix + \\"foo\\";
}

connectedCallback() {}
connectedCallback() {
console.log(this.foo);
this.foo = \\"bar\\";
}

render() {
return html\`
Expand Down Expand Up @@ -8849,13 +8853,17 @@ export default class UseTargetComponent extends LitElement {
}

@state() lastName = \\"bar\\";
@state() foo = \\"bar\\";

get name() {
const prefix = \\"li\\";
return prefix + \\"foo\\";
}

connectedCallback() {}
connectedCallback() {
console.log(this.foo);
this.foo = \\"bar\\";
}

render() {
return html\`
Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/__tests__/__snapshots__/marko.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2509,10 +2509,13 @@ exports[`Marko > jsx > Javascript Test > useTarget 1`] = `
}
onCreate() {
this.state = { lastName: \\"bar\\" };
this.state = { lastName: \\"bar\\", foo: \\"bar\\" };
}
onMount() {}
onMount() {
console.log(this.state.foo);
this.state.foo = \\"bar\\";
}
}
<div>\${component.name}</div>"
Expand Down Expand Up @@ -5017,10 +5020,13 @@ exports[`Marko > jsx > Typescript Test > useTarget 1`] = `
}
onCreate() {
this.state = { lastName: \\"bar\\" };
this.state = { lastName: \\"bar\\", foo: \\"bar\\" };
}
onMount() {}
onMount() {
console.log(this.state.foo);
this.state.foo = \\"bar\\";
}
}
<div>\${component.name}</div>"
Expand Down
Loading

0 comments on commit 0aa642a

Please sign in to comment.