-
Notifications
You must be signed in to change notification settings - Fork 2
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: 🐛 Cannot set property src of #<OpenStoriesElement> which has only a getter #14
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.
hey sorry it took me a while to review.
- getter should always reflect the current content attribute value (in this case full absolute URL for src, number for duration).
- setter should update the content attribute
for example, with HTML,
<form id action="/" method="get">…</form>
Console,
$ form.action
> 'https://github.com/'
$ form.action = '/test'
> '/test'
$ form.action
> 'https://github.com/test'
In the current PR the content attribute is never read. If tested with a plain HTML <open-stories>
element, el.src
would be empty, thus breaking the test page (/demo/
).
Ah, good catch! I wonder if I missed this because a React lifecycle was triggering the setter when I was testing. 🤔 Made some refactors by calling Lemme know what you think or if there's anymore changes needed! |
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.
Just one thing here, could you make sure it follows the current codestyle? ;
and "
. I should've added a ts-standard
lint. Thanks!
👍🏻 done |
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.
- setter should update the content attribute
I see that this is still not the case?
I can do this but don't have time yet. Thanks for the work so far.
Once that's done I can merge it, or I can do a final check, add that, and merge it as well.
Just to clarify are you looking for the internal value of
It would reflect back onto the element after it performs all of the URL changes?
Thinking this through some more this morning, how do you feel about these refactors? set src(path: string) {
this.setAttribute("src", this.formatSrc(path));
}
get src(): string {
return this.getAttribute("src") || "";
}
set duration(value: number) {
this.setAttribute("duration", String(value));
}
get duration(): number {
return Number(this.getAttribute("duration") || 5);
}
static get observedAttributes(): string[] {
return ["src", "duration"];
}
attributeChangedCallback(
attr: string,
oldValue: string,
newValue: string
): void {
if (attr === "duration" && oldValue !== newValue) {
this.duration = Number(newValue);
}
if (attr === "src" && oldValue !== newValue) {
this.src = newValue;
}
} This results in the following behavior when Screen.Recording.2023-09-13.at.9.48.29.AM.mov |
No, the content attribute to should reflect what was set, but the getter should have the fully formed absolute URL. Using $ form = document.createElement('form')
<form></form>
$ form.action = 'x'
'x'
$ form
<form action="x"></form>
$ form.action
'https://github.com/dddddddddzzzz/open-stories-element/pull/x' I do think |
Co-authored-by: Mu-An Chiou <[email protected]>
Changes published in 0.0.25. Thank you! Tracking remaining work in #15. |
Related: dddddddddzzzz/OpenStories#10
I kept running into the following error intermittently, I thought it was because I was providing
src
incorrectly but it appears I was wrong. Because of the type of error being thrown here, in certain frameworks such as Next.js it prevents the whole page from rendering.From my understanding of this error, this is due to the usage of the
get
keyword without an accompanyingset
keyword. In this pull request, I've refactoredsrc
andduration
so they implementset
which resolves the error for me.I've validated the best I can but would appreciate it if you pulled this down locally to test everything out too (if you wish to merge this that is) as you all know the ins and outs of this better than I do 😄