Repository navigation
Overview
This release introduces a number of long standing JSX features and bug fixes, as well as "correctness" fixes to WCC's JSX transformer. Please see the breaking changes section for more information regarding this upgrade.
Changelog
https://github.com/ProjectEvergreen/wcc/issues?q=label%3A0.24.0
- feature(jsx): #292 support conditionals (non reactive)
- feature(jsx): #291 loops (non reactive)
- feature(jsx): #294 generate custom definition for mapping html attributes to jsx
- feature(jsx): #88 support this references
- feature(jsx): #137 fragment tag
- fix(jsx): #301 correctly parse inferred observability export
- fix(jsx): #319 remove duplicate
<br>tags
Breaking Changes
JSX Escaping By Default (innerHTML)
Previously, interpolating an HTML string rendered it as markup:
const markup = '<strong>Hello</strong>';
return <div>{markup}</div>;
// <div><strong>Hello</strong></div>Now, the same code displays the string as text:
<div><strong>Hello</strong></div>To intentionally render an HTML string, use the new innerHTML attribute:
const markup = '<strong>Hello</strong>';
return <div innerHTML={markup} />;
// <div><strong>Hello</strong></div>And the same for Light DOM use case:
// before
const { innerHTML } = this;
return <section>{innerHTML}</section>;
// after
return <section innerHTML={this.innerHTML} />;
innerHTMLdoes not sanitize its value. Use trusted or sanitized markup, and do not combine it with JSX children or place it on a void element such as<img>.
HTML and SVG Attributes Types Conformance
Previously, JSX types were (incorrectly) derived from DOM interfaces coming TypeScript, allowing property names and values that were not valid HTML attributes:
// previous, this was allowed
<label htmlFor="email">Email</label>
<input valueAsNumber={42} />
<img loading="lzy" />Now, use HTML attribute names and valid attribute values:
<label for="email">Email</label>
<input value={42} />
<img loading="lazy" />DOM methods and computed properties such as cloneNode and clientWidth are no longer accepted as attributes. SVG attributes also no longer have a permissive catch-all.
Event callbacks now receive typed events:
<button
onclick={(event) => {
// event is inferred as MouseEvent
console.log(event.clientX);
}}
>
Click
</button>JSX Children
Previously, interpolated arrays could rely on JavaScript string conversion, which inserts commas:
const values = ['First', 'Second'];
return <p>{values}</p>;
// before: First,Second
// after: FirstSecondIf you want separators, add them explicitly:
return <p>{values.join(', ')}</p>;
// First, Secondnull, undefined, and boolean children now render nothing. Convert them to strings if you want them displayed:
const enabled = false;
// renders an empty paragraph
return <p>{enabled}</p>;
// displays "false"
return <p>{String(enabled)}</p>;For lists of JSX elements, keep the elements in an array rather than joining them into a string:
// avoid converting JSX values into a string
return <ul>{items.map((item) => <li>{item.label}</li>).join('')}</ul>;
// pass the array directly
return <ul>{items.map((item) => <li>{item.label}</li>)}</ul>;Nested arrays render in order without commas, and numeric values such as 0 remain visible.
Generated Event Handling Output
For render templates and direct loops, WCC now generates addEventListener bindings instead of inline HTML event attributes.
Previously, generated HTML contained an inline handler resembling:
<button onclick="this.parentElement.increment(event)">Increment</button>Now, WCC generates a listener in the component’s JavaScript:
button.addEventListener('click', (event) => this.increment(event));Update tests that inspect
onclickattributes to verify the resulting interaction instead. Code that clears or replaces.onclickwill also no longer control WCC’s generated listener.
If you relied on returning false from an inline handler to cancel a browser action, cancel it explicitly:
// before: relying on inline-handler return semantics
<a href="/next" onclick={() => false}>Stay here</a>
// after
<a href="/next" onclick={(event) => event.preventDefault()}>
Stay here
</a>Saved JSX values and helper returns currently retain an inline-handler path.
Known Issues
N / A