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: bound call expression styles are preserved in Builder generator #1694

Merged
merged 5 commits into from
Feb 20, 2025

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Feb 20, 2025

Description

When fixing an issue where dynamic styles were not mapped to bindings I inadvertently broke a usecase where a function call could be bound to get the styles (I.e. style={state.getStyles()}. This PR resolves the issue by ensuring that call expressions can be set as styles.

It's possible that I am missing other use cases here, so I added a console warning whenever invalid styles are dropped so it's a bit more obvious that this is happening in the future.

Failing test example:

 FAIL  src/__tests__/builder.test.ts > Builder > preserve bound call expressions for styles
Error: Snapshot `Builder > preserve bound call expressions for styles 2` mismatched

- Expected
+ Received

  {
    "@type": "@builder.io/sdk:Element",
    "actions": {},
-   "bindings": {
-     "style": "state.getStyles()",
-   },
+   "bindings": {},
    "children": [],
    "code": {
      "actions": {},
      "bindings": {},
    },
    "properties": {},
    "tagName": "div",
  }

 ❯ src/__tests__/builder.test.ts:930:42
    928|     const builderJson = componentToBuilder()({ component });
    929| 
    930|     expect(builderJson.data!.blocks![0]).toMatchInlineSnapshot(`
       |                                          ^
    931|     {
    932|       "@type": "@builder.io/sdk:Element",

Make sure to follow the PR preparation steps in CONTRIBUTING.md before submitting your PR:

  • format the codebase: from the root, run yarn fmt:prettier.
  • update all snapshots (in core & CLI): from the root, run yarn test:update
  • add Changeset entry: from the root, run yarn g:changeset and follow the CLI instructions. Alternatively, use the Changeset Github Bot to create the file.

Copy link

changeset-bot bot commented Feb 20, 2025

🦋 Changeset detected

Latest commit: 326504e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@builder.io/mitosis Patch
@builder.io/mitosis-cli Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link

nx-cloud bot commented Feb 20, 2025

View your CI Pipeline Execution ↗ for commit 326504e.

Command Status Duration Result
nx e2e @builder.io/e2e-app ✅ Succeeded 1m 8s View ↗
nx run-many --target test ✅ Succeeded 4m 42s View ↗
nx run-many --target build --exclude @builder.i... ✅ Succeeded 3m 53s View ↗
nx build @builder.io/mitosis-site ✅ Succeeded 2m 22s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-20 16:37:54 UTC

@liamdebeasi liamdebeasi changed the title add failing test fix: bound call expression styles are preserved in Builder generator Feb 20, 2025
@liamdebeasi liamdebeasi marked this pull request as ready for review February 20, 2025 16:41
@liamdebeasi liamdebeasi merged commit 0b55dc3 into BuilderIO:main Feb 20, 2025
7 checks passed
@liamdebeasi liamdebeasi deleted the ld/style-binding-call branch February 20, 2025 17:22
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