-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(ssr-compiler): define setters for reflected attributes #4611
Conversation
) | ||
), | ||
]) | ||
) |
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.
This would benefit from a code comment showing an example output. ASTs are hard to read...
setAttribute(attrName: string, value: string | null): void { | ||
this.__attrs[attrName] = String(value); | ||
setAttribute(attrName: string, attrValue: unknown): void { | ||
this.#setAttribute(attrName, String(attrValue)); |
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 bit confusing to have two methods named setAttribute
and #setAttribute
. Maybe #setAttributeWithoutTypeCoercion
or something?
} | ||
|
||
hasAttribute(attrName: unknown): boolean { | ||
return typeof attrName === 'string' && typeof this.__attrs[attrName] === 'string'; |
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.
The fact that we have to check for strings here because we don't ensure that the values in this.__attrs
is only a string type is odd to me. We should probably do the validation/coercion on the way in.
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.
OK, so the reason for this is that we can't call delete
because that would delete the getter/setter which is required for prop/attr reflection.
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.
Define setters for reflected attributes. Needed to add a private
#setAttribute()
method that can setnull
without turning it into a string so thatremoveAttribute()
works as expected.Also
for-of
was also changed tofor-in
inrenderAttrs
so that we can iterate over non-string (accessor) enumerable entries.This implementation is now more correct than
engine-server
as it seems the latter may not be handingsetAttribute(null)
correctly for standard reflected attributes: