Fixes for bugs in the mod portal

A place to talk about the official Factorio mod portal (https://mods.factorio.com)
Post Reply
beiju
Inserter
Inserter
Posts: 42
Joined: Thu Feb 02, 2017 3:52 pm
Contact:

Fixes for bugs in the mod portal

Post by beiju »

There are (at least) two well-known bugs in the mod portal. I assume they're "Won't Fix" because its replacement is in the works, but I hope if the devs have the exact solutions that will take minutes to implement, they'll fix the current one. For tl;dr just read the bolded portions.

The first is the bug with expanding preview images. This is caused by an overeager shouldComponentUpdate on line 54 of the Gallery component (static/src/js/components/Gallery/Gallery.jsx). It's telling the component not to update unless the props.mediaFiles array is changed. Clicking the image changes state.selected, which works correctly, but the shouldComponentUpdate tells React not to change the page in response. The workaround (clicking the mod title after clicking the thumbnail) only works because of another bug. The shouldComponentUpdate is testing the props.mediaFiles array for object identity, not content equality. When the mod title is clicked, the props are updated with a different array object with the exact same contents, so the !== returns true even though the array contents are the same.

The best fix is to delete shouldComponentUpdate from the Gallery component. As far as I can tell, there's nothing in the props or state that would slow down the default shouldComponentUpdate, which does deep equality checks, enough to make it worth implementing your own. If I missed something, and you do need to implement your own, it should (a) check the state as well as the props (the new state is passed as the second argument, and is used the same way as the new props), and (b) check content equality on props.mediaFiles instead of object identity.

The second bug is with NaN dates in Safari. This happens because the format of the datetime string received from the server is nearly compliant with the Javascript spec, but it differs in that a space character is used to separate the date and time instead of the spec-mandated 'T'. Whether or not browsers accept a format other than the ones defined by the spec is implementation-defined. Chrome does, Safari doesn't.

The simple fix is to replace the space with a 'T' in the date string before passing it to new Date(). In /static/src/js/lib/utils.js, replace line 30 (the first line of the timeAgo function) with this line:

Code: Select all

var then = (new Date(date.replace(' ', 'T')).valueOf()

User avatar
HanziQ
Former Staff
Former Staff
Posts: 630
Joined: Fri Mar 27, 2015 7:07 am
Contact:

Re: Fixes for bugs in the mod portal

Post by HanziQ »

Thank you for the fixes, there is really no one here who knows their way around React and such, so that's the other reason that these things are not getting fixed. If you have any other suggestions/fixes, feel free to post them or PM me directly so I actually notice.

Daid
Fast Inserter
Fast Inserter
Posts: 163
Joined: Sun Jul 03, 2016 7:42 am
Contact:

Re: Fixes for bugs in the mod portal

Post by Daid »

HanziQ wrote:Thank you for the fixes, there is really no one here who knows their way around React and such, so that's the other reason that these things are not getting fixed. If you have any other suggestions/fixes, feel free to post them or PM me directly so I actually notice.
Wild idea, maybe give some trusted community members access to the code till a replacement is made?

The positive is that bugs get fixed, and the whole thing becomes a bit more usable.
The negative is usually that maintainability of the code goes down. As they are usually not aiming for long term maintainability or are not really good software engineers.

I work for a company that has open sourced our older products software, and we are getting an occasional fix and feature for almost free :-) but I can understand if there are parts in the mod portal that are not for everyone's eyes.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Fixes for bugs in the mod portal

Post by DaveMcW »

One of the main goals of the mod portal is to drive traffic away from competing mod portals. Giving away the complete source code makes that harder.

Daid
Fast Inserter
Fast Inserter
Posts: 163
Joined: Sun Jul 03, 2016 7:42 am
Contact:

Re: Fixes for bugs in the mod portal

Post by Daid »

DaveMcW wrote:One of the main goals of the mod portal is to drive traffic away from competing mod portals. Giving away the complete source code makes that harder.
That's not what I proposed. I didn't say "open it to everyone", I said, give a few trusted people access. A simple licence/NDA is all it needs if you do not want any copies to pop up anywhere.

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Fixes for bugs in the mod portal

Post by Mooncat »

I browsed the Mod Portal like usual, and realized the image preview issue no longer exists. :o
Then I came to this forum and saw this post!
Wow! Good job beiju! (thumbs up)
It has already bugged me for 8 months!

I agree with the suggestion of open sourcing the Mod Portal code, especially when there is no dev in the team familiar with it.

Is it possible to also fix the search bug? Search only works on the first page. It doesn't work if any of the later pages is selected. :mrgreen:

Post Reply

Return to “Mod portal Discussion”