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 JS errors that only require a check for truthy value #1881
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.
I commented on what I saw. Let's not rush this, though - and focus on the remaining planned items for tomorrow's feature freeze.
@@ -92,7 +92,9 @@ export default class DiscussionComposer extends ComposerBody { | |||
app.store.createRecord('discussions').save(data).then( | |||
discussion => { | |||
app.composer.hide(); | |||
app.cache.discussionList.addDiscussion(discussion); | |||
|
|||
if (app.cache.discussionList) app.cache.discussionList.addDiscussion(discussion); |
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 is likely made obsolete by #1868.
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.
That PR would still need a check anyway... I'll remove the extra lines I added so maybe git just sees it as adding the if
before, and not changing the whole line.
js/src/common/utils/anchorScroll.js
Outdated
@@ -12,10 +12,18 @@ | |||
* @param {Function} callback The callback to run that will change page content. | |||
*/ | |||
export default function anchorScroll(element, callback) { | |||
const $element = $(element); | |||
|
|||
// return if element doesn't exist |
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 comments are stating what's pretty obvious in the code - in this case, it's not even 100% correct, because the callback is still executed.
Please explain why this is necessary, not what it does.
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 reminds me of Clean Code, chapter 4 😄 🚀
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.
@datitisev It seems like you also misunderstood me. I would love to see comments explaining why this is needed (because of something that happens before this code is called), not what error it prevents in that same method. That's mostly obvious from looking at the code.
What I don't see when looking at this code:
- Why would the
discussionList
ever not exist when the post composer is open? - When would somebody pass a not-existing element into
anchorScroll
?
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.
But, again, let's focus on the other PRs first.
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.
Why would the discussionList ever not exist when the post composer is open?
I can only assume during redraws or something
When would somebody pass a not-existing element into anchorScroll?
Not intentionally. If you look at the stack trace, it was because of the PostStream. From there, I assume it tried to scroll to a post (through its index/number) that hadn't been loaded yet.
There's really not much I can gather from the stack traces, and this is a pretty simple fix. This would be a temporary solution, until (or if) we find and & solve the underlying issues.
But yeah, focus on other PRs first.
This comment has been minimized.
This comment has been minimized.
The post composer could have been closed in between scheduling and executing the callback. Fixes flarum/org#58. Refs #1881.
I fixed one of them (the Still unsure about the other ones. I prefer fixing root causes. 😉 |
The post composer could have been closed in between scheduling and executing the callback. Fixes flarum/org#58. Refs flarum#1881.
Please rebase. 🙏 |
Because we now auto-format our JS code with Prettier, this branch now has conflicts with Please take the steps outlined in the forum to resolve the conflicts. |
Sentry > DEMOS-8 TypeError: Cannot read property 'top' of undefined at apply(webpack://@flarum/core/./src/common/components/Dropdown.js:69:15) at apply(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:5237:1) at apply(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:5044:1) at trigger(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:8471:1) at call(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:8549:1) at each(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:367:1) at each(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:202:1) at trigger(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:8548:1) at apply(webpack://@flarum/core/./node_modules/bootstrap/js/dropdown.js:88:1) at apply(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:5237:1) at HTMLDocument.g.handle(webpack://@flarum/core/./node_modules/jquery/dist/jquery.js:5044:1)
Sentry > DEMOS-C TypeError: undefined is not an object (evaluating '.offset().top') at anchorScroll(webpack://@flarum/core/./src/common/utils/anchorScroll.js:16:37) at onSuccess(webpack://@flarum/core/./src/forum/components/PostStream.js:115:17) at notThennable(webpack://@flarum/core/./node_modules/mithril/mithril.js:2033:1) at thennable(webpack://@flarum/core/./node_modules/mithril/mithril.js:2004:1) at fire(webpack://@flarum/core/./node_modules/mithril/mithril.js:2024:1) at resolve(webpack://@flarum/core/./node_modules/mithril/mithril.js:1941:1) at then(webpack://@flarum/core/./node_modules/mithril/mithril.js:1962:1) at loadNearNumber(webpack://@flarum/core/./node_modules/mithril/mithril.js:1905:1) at document(webpack://@flarum/core/./src/forum/components/PostStream.js:66:26) at ? (webpack://@flarum/core/./src/forum/components/DiscussionPage.js:225:7)
Sentry > DEMOS-Q TypeError: Cannot read property 'addDiscussion' of undefined at onSuccess(webpack://@flarum/core/./src/forum/components/DiscussionComposer.js:95:34) at notThennable(webpack://@flarum/core/./node_modules/mithril/mithril.js:2033:1) at thennable(webpack://@flarum/core/./node_modules/mithril/mithril.js:2004:1) at fire(webpack://@flarum/core/./node_modules/mithril/mithril.js:2024:1) at resolve(webpack://@flarum/core/./node_modules/mithril/mithril.js:1941:1) at ? (webpack://@flarum/core/./node_modules/mithril/mithril.js:1976:1)
08a1db6
to
917a55b
Compare
@@ -98,7 +98,9 @@ export default class DiscussionComposer extends ComposerBody { | |||
.save(data) | |||
.then((discussion) => { | |||
app.composer.hide(); | |||
app.cache.discussionList.refresh(); | |||
|
|||
if (app.cache.discussionList) app.cache.discussionList.refresh(discussion); |
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 line should no longer be necessary after #2150
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum. |
I hope this will no longer be necessary with Typescript. Or if so, it will be hopelessly conflicted. |
This should fix a bunch of errors that have been thrown recently on our beta demo.
Fixes: