-
Notifications
You must be signed in to change notification settings - Fork 319
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
Render any value returned by #render
.
#712
Conversation
…t remove shimmed adopted style sheets.
can you also change the base |
@bicknellr is this ready to go in now? |
src/lit-element.ts
Outdated
* DOM. | ||
* @param {TemplateResult} Template to render. | ||
* Render method used to render the value to the element's DOM. | ||
* @param {unknown} The value to render. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need the property names as the first word following the type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
*/ | ||
protected render(): TemplateResult|void { | ||
protected render(): unknown { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elide the return if you type this as unknown|void
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem like it:
src/lit-element.ts:241:23 - error TS2355: A function whose declared type is neither 'void' nor 'any' must return a value.
241 protected render(): unknown|void {
~~~~~~~~~~~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a shame to add non-observable, non-type annotation code to satisfy the type-checker. Can we cast our way out of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how I would cast the function in place since class syntax isn't expression based (and I assume we don't want to bind it / remove it from the prototype by making it a property), so I tried pulling it out of the class as this:
LitElement.prototype.render = function() {} as () => unknown;
But then I get another couple of errors that seem like TS is no longer recognizing that render
is also on the prototype:
src/lit-element.ts:219:18 - error TS2576: Property 'render' is a static member of type 'LitElement'
219 this.render(),
~~~~~~
src/lit-element.ts:243:22 - error TS2576: Property 'render' is a static member of type 'LitElement'
243 LitElement.prototype.render = function() {} as () => unknown;
~~~~~~
I'm not familiar with pre-classes TS, so maybe that's not the right way to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(from offline) I'm going to leave the return undefined;
as is and assume that any given minifier should be smart enough to remove it.
src/test/lit-element_styling_test.ts
Outdated
@@ -798,6 +798,62 @@ suite('Static get styles', () => { | |||
const bodyStyles = `${cssModule}`; | |||
assert.equal(bodyStyles, '.my-module { color: yellow; }'); | |||
}); | |||
|
|||
test.only( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove .only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
The benchmarks check is stuck (it's been in the 'queued' state all weekend) but I don't know how to restart it. (I already tried clicking "Re-run all checks" under "Tachometer Benchmarks" in the Checks tab.) |
#618 is extremely serious since it affects FireFox and Safari (and others), that's over 20% of the total market share! Please expedite this PR!!! |
- #712 Introduced a breaking behavior change for situations where `render` is unimplemented, and DOM is added before being connected to the document.
) * Only call lit-html render if LitElement subclass implements render - #712 Introduced a breaking behavior change for situations where `render` is unimplemented, and DOM is added before being connected to the document. * update CHANGELOG * Remove `connectedCallback` in render test
Isn't this a breaking change? My team was not returning anything from render in our non-shadow-dom components that accept children, which would previously prevent render from happening. Now, it blows away all children of the component. I figured out a workaround, which is to return |
As of lit/lit#910,
render
accepts any type. This PR causesLitElement
to render anything returned byrender
.Fixes #618, Fixes #168