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(cc-invoice): <template> content is erased #785

Merged
merged 1 commit into from
Jun 26, 2023

Conversation

florian-sanders-cc
Copy link
Contributor

Fixes #784

What does this PR do?

Move the <template> tag used within cc-invoice inside the unsafeHTML expression because Lit won't allow using expressions inside a <template> tag.

What to review?

  • code
  • UI (in prod, invoice content = blank, in preview, invoice content = heading and text).
More info about the issue and the solution

The <cc-invoice> component allows developers to pass HTML through the invoice.invoiceHtml prop.
This feature used to work with Lit 1.X but it has been broken since we've migrated to Lit 2.X (components version 10 and upper).

The HTML fragment is supposed to be handled by <cc-html-frame> inside the <cc-invoice> component.

To pass HTML to <cc-html-frame>, you need to slot it inside a <template> tag like this:

<cc-html-frame>
  <template>your html</template>
</cc-html-frame>

In <cc-invoice> we used to do it like this:

<cc-html-frame>
  <template>${unsafeHTML(this.invoice.invoiceHtml)}</template>
</cc-html-frame>

But it does not work anymore because you cannot use expressions within a <template> tag (see Lit docs - Invalid locations).
Trying to use unsafeHTML expression within a <template> tag on Lit playground results in the following error:
Uncaught (in promise) Error: Expressions are not supported inside template elements. See https://lit.dev/msg/expression-in-template for more information.

@github-actions
Copy link
Contributor

🔎 A preview has been automatically published : https://clever-components-preview.cellar-c2.services.clever-cloud.com/cc-invoice/fix-html-preview/index.html.

This preview will be deleted once this PR is closed.

Copy link
Member

@roberttran-cc roberttran-cc left a comment

Choose a reason for hiding this comment

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

Thank you very much for the explanations!

@florian-sanders-cc florian-sanders-cc force-pushed the cc-invoice/fix-html-preview branch from 15c3329 to 5a9ffcf Compare June 22, 2023 10:03
Copy link
Contributor

@pdesoyres-cc pdesoyres-cc left a comment

Choose a reason for hiding this comment

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

Nice catch! Thank you for the explanations.

Copy link
Member

@hsablonniere hsablonniere left a comment

Choose a reason for hiding this comment

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

👏 Wow, nice catch, I learnt something today!

Lit does not allow expressions inside `<template>` tags.

Fixes #784
@florian-sanders-cc florian-sanders-cc force-pushed the cc-invoice/fix-html-preview branch from 5a9ffcf to 92b20ec Compare June 26, 2023 11:59
@florian-sanders-cc florian-sanders-cc merged commit b8d5348 into master Jun 26, 2023
@florian-sanders-cc florian-sanders-cc deleted the cc-invoice/fix-html-preview branch June 26, 2023 12:10
@github-actions
Copy link
Contributor

🔎 The preview has been automatically deleted.

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.

The HTML preview in the cc-invoice story is broken
4 participants