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 broken angular block #1705

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Fix broken angular block #1705

wants to merge 12 commits into from

Conversation

armgjoka
Copy link
Contributor

@armgjoka armgjoka commented Feb 27, 2025

Description

Updated parsing of innerHtml which was causing issues on code gen for angular.

  • 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.

@armgjoka armgjoka requested a review from samijaber as a code owner February 27, 2025 16:50
Copy link

changeset-bot bot commented Feb 27, 2025

🦋 Changeset detected

Latest commit: 81e48f0

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 27, 2025

View your CI Pipeline Execution ↗ for commit 81e48f0.

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

☁️ Nx Cloud last updated this comment at 2025-03-20 21:51:37 UTC


// The generated Angular code should not have nested double quotes
expect(template).not.toMatch(/="[^"]*"[^"]*"/);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, we have the approach of using expect(template).toMatchInlineSnapshot() so that we can notice any surprising changes across all tests when new PRs are made.

If you don't mind adding inline snapshots for relevant objects. See https://github.com/BuilderIO/mitosis/blob/main/packages/core/src/__tests__/builder.test.ts for examples of how we use it.

oyou just write toMatchInlineSnapshot(), and once you run the tests it will populate it. See https://vitest.dev/guide/snapshot#inline-snapshots

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samijaber thanks for the suggestion, updated it

str += ` [innerHTML]="sanitizer.bypassSecurityTrustHtml('${safeValue}')" `;
} else {
// For standard attribute (though this won't work in Angular)
str += ` innerHTML="${safeValue}" `;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need to convert this to [innerHTML]="'${safeValue}'" right?

import {Component} from '@angular/core';
import {bootstrapApplication} from '@angular/platform-browser';

@Component({
  selector: 'app-root',
  template: `
    <div [innerHTML]="'hello &quot;'">

    </div>
  `,
})
export class PlaygroundComponent {}

bootstrapApplication(PlaygroundComponent);

innerHTML="text" doesn't work in https://angular.dev/playground

Copy link
Collaborator

@sidmohanty11 sidmohanty11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last bit, can we please add a test for this? From Mitosis -> Angular generation?

For example, we can use this as the *.raw.tsx

export default function MyComponent(props) {
  return (
    <div innerHTML='hello "'>
      Hello! I can run natively in React, Vue, Svelte, Qwik, and many more frameworks!
    </div>
  );
}

this should convert the quote and update the innerHTML to [innerHTML]

To do this,

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.

3 participants