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(client): update invalid stored code #44437
fix(client): update invalid stored code #44437
Conversation
|
|
|
@raisedadead what do you think about purging the saved javascript challenge code? Just the challenge code, mind, nothing else. |
Does this include user code too? |
Yes. This is the localStorage for non-certification projects. So, only user code. Only client-side. (the code saved with |
|
@raisedadead We discussed and have decided to go with the "hacky" approach which allows all currently saved code. This is mostly because there are probably a few Campers relying on localStorage for the JS certification projects (before they submit) |
|
Blocked while we discuss what we want to implement |
9f003ff
to
aa59fbd
|
This now restores the old behaviour, but should gracefully handle old saved code and only discard stored code if it isn't valid. @Sembauke this should help a little with the mobile app. |
|
Thanks @ojeytonwilliams , I tried to use the editor on mobile but came across some issues when switching panes and trying to run tests. Also some users report unable to remove text or type at all. Hope this fixes the storing issues. |
|
@Sembauke Monaco really isn't great for mobile. If you're interested, you can try https://microsoft.github.io/monaco-editor/playground.html on mobile, to see what's a Monaco specific issue rather than something we have done. This PR is a relatively minor improvement - I just remembered that inability to save was a source of frustration for some mobile users. |
|
@Sembauke For reference, we have always pointed mobile users to: https://www.freecodecamp.org/news/freecodecamp-mobile/ |
This LGTM
One thing I noticed, even when updating the old code format, the old fields remain behind:
Is there any reason this would be a problem?
{
"fileKey": "scriptjs",
"head": "",
"tail": "",
"editableRegionBoundaries": null,
"history": [
"script.js"
],
"name": "script",
"ext": "js",
"path": "script.js",
"contents": "// The global variable\nvar watchList = [\n {\n \"Title\": \"Inception\",\n \"Year\": \"2010\",\n \"Rated\": \"PG-13\",\n \"Released\": \"16 Jul 2010\",\n \"Runtime\": \"148 min\",\n \"Genre\": \"Action, Adventure, Crime\",\n \"Director\": \"Christopher Nolan\",\n \"Writer\": \"Christopher Nolan\",\n \"Actors\": \"Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page, Tom Hardy\",\n \"Plot\": \"A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.\",\n \"Language\": \"English, Japanese, French\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Won 4 Oscars. Another 143 wins & 198 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg\",\n \"Metascore\": \"74\",\n \"imdbRating\": \"8.8\",\n \"imdbVotes\": \"1,446,708\",\n \"imdbID\": \"tt1375666\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n },\n {\n \"Title\": \"Interstellar\",\n \"Year\": \"2014\",\n \"Rated\": \"PG-13\",\n \"Released\": \"07 Nov 2014\",\n \"Runtime\": \"169 min\",\n \"Genre\": \"Adventure, Drama, Sci-Fi\",\n \"Director\": \"Christopher Nolan\",\n \"Writer\": \"Jonathan Nolan, Christopher Nolan\",\n \"Actors\": \"Ellen Burstyn, Matthew McConaughey, Mackenzie Foy, John Lithgow\",\n \"Plot\": \"A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.\",\n \"Language\": \"English\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Won 1 Oscar. Another 39 wins & 132 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg\",\n \"Metascore\": \"74\",\n \"imdbRating\": \"8.6\",\n \"imdbVotes\": \"910,366\",\n \"imdbID\": \"tt0816692\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n },\n {\n \"Title\": \"The Dark Knight\",\n \"Year\": \"2008\",\n \"Rated\": \"PG-13\",\n \"Released\": \"18 Jul 2008\",\n \"Runtime\": \"152 min\",\n \"Genre\": \"Action, Adventure, Crime\",\n \"Director\": \"Christopher Nolan\",\n \"Writer\": \"Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)\",\n \"Actors\": \"Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine\",\n \"Plot\": \"When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.\",\n \"Language\": \"English, Mandarin\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Won 2 Oscars. Another 146 wins & 142 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_SX300.jpg\",\n \"Metascore\": \"82\",\n \"imdbRating\": \"9.0\",\n \"imdbVotes\": \"1,652,832\",\n \"imdbID\": \"tt0468569\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n },\n {\n \"Title\": \"Batman Begins\",\n \"Year\": \"2005\",\n \"Rated\": \"PG-13\",\n \"Released\": \"15 Jun 2005\",\n \"Runtime\": \"140 min\",\n \"Genre\": \"Action, Adventure\",\n \"Director\": \"Christopher Nolan\",\n \"Writer\": \"Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)\",\n \"Actors\": \"Christian Bale, Michael Caine, Liam Neeson, Katie Holmes\",\n \"Plot\": \"After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.\",\n \"Language\": \"English, Urdu, Mandarin\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Nominated for 1 Oscar. Another 15 wins & 66 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3._V1_SX300.jpg\",\n \"Metascore\": \"70\",\n \"imdbRating\": \"8.3\",\n \"imdbVotes\": \"972,584\",\n \"imdbID\": \"tt0372784\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n },\n {\n \"Title\": \"Avatar\",\n \"Year\": \"2009\",\n \"Rated\": \"PG-13\",\n \"Released\": \"18 Dec 2009\",\n \"Runtime\": \"162 min\",\n \"Genre\": \"Action, Adventure, Fantasy\",\n \"Director\": \"James Cameron\",\n \"Writer\": \"James Cameron\",\n \"Actors\": \"Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang\",\n \"Plot\": \"A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.\",\n \"Language\": \"English, Spanish\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Won 3 Oscars. Another 80 wins & 121 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX300.jpg\",\n \"Metascore\": \"83\",\n \"imdbRating\": \"7.9\",\n \"imdbVotes\": \"876,575\",\n \"imdbID\": \"tt0499549\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n }\n];\n\nfunction getRating(watchList) {\n // Only change code below this line\n \n var averageRating = watchList\n .filter(e => e.Director === \"Christopher Nolan\")\n .map(e => Number(e.imdbRating))\n .reduce((sum, e) => sum + e, 0) / watchList.filter(e => e.Director === \"Christopher Nolan\").length;\n\n // Only change code above this line\n return averageRating;\n}\n\nconsole.log(getRating(watchList));",
"error": null,
"seed": "// The global variable\nvar watchList = [\n {\n \"Title\": \"Inception\",\n \"Year\": \"2010\",\n \"Rated\": \"PG-13\",\n \"Released\": \"16 Jul 2010\",\n \"Runtime\": \"148 min\",\n \"Genre\": \"Action, Adventure, Crime\",\n \"Director\": \"Christopher Nolan\",\n \"Writer\": \"Christopher Nolan\",\n \"Actors\": \"Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page, Tom Hardy\",\n \"Plot\": \"A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.\",\n \"Language\": \"English, Japanese, French\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Won 4 Oscars. Another 143 wins & 198 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg\",\n \"Metascore\": \"74\",\n \"imdbRating\": \"8.8\",\n \"imdbVotes\": \"1,446,708\",\n \"imdbID\": \"tt1375666\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n },\n {\n \"Title\": \"Interstellar\",\n \"Year\": \"2014\",\n \"Rated\": \"PG-13\",\n \"Released\": \"07 Nov 2014\",\n \"Runtime\": \"169 min\",\n \"Genre\": \"Adventure, Drama, Sci-Fi\",\n \"Director\": \"Christopher Nolan\",\n \"Writer\": \"Jonathan Nolan, Christopher Nolan\",\n \"Actors\": \"Ellen Burstyn, Matthew McConaughey, Mackenzie Foy, John Lithgow\",\n \"Plot\": \"A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.\",\n \"Language\": \"English\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Won 1 Oscar. Another 39 wins & 132 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg\",\n \"Metascore\": \"74\",\n \"imdbRating\": \"8.6\",\n \"imdbVotes\": \"910,366\",\n \"imdbID\": \"tt0816692\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n },\n {\n \"Title\": \"The Dark Knight\",\n \"Year\": \"2008\",\n \"Rated\": \"PG-13\",\n \"Released\": \"18 Jul 2008\",\n \"Runtime\": \"152 min\",\n \"Genre\": \"Action, Adventure, Crime\",\n \"Director\": \"Christopher Nolan\",\n \"Writer\": \"Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)\",\n \"Actors\": \"Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine\",\n \"Plot\": \"When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.\",\n \"Language\": \"English, Mandarin\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Won 2 Oscars. Another 146 wins & 142 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_SX300.jpg\",\n \"Metascore\": \"82\",\n \"imdbRating\": \"9.0\",\n \"imdbVotes\": \"1,652,832\",\n \"imdbID\": \"tt0468569\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n },\n {\n \"Title\": \"Batman Begins\",\n \"Year\": \"2005\",\n \"Rated\": \"PG-13\",\n \"Released\": \"15 Jun 2005\",\n \"Runtime\": \"140 min\",\n \"Genre\": \"Action, Adventure\",\n \"Director\": \"Christopher Nolan\",\n \"Writer\": \"Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)\",\n \"Actors\": \"Christian Bale, Michael Caine, Liam Neeson, Katie Holmes\",\n \"Plot\": \"After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.\",\n \"Language\": \"English, Urdu, Mandarin\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Nominated for 1 Oscar. Another 15 wins & 66 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3._V1_SX300.jpg\",\n \"Metascore\": \"70\",\n \"imdbRating\": \"8.3\",\n \"imdbVotes\": \"972,584\",\n \"imdbID\": \"tt0372784\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n },\n {\n \"Title\": \"Avatar\",\n \"Year\": \"2009\",\n \"Rated\": \"PG-13\",\n \"Released\": \"18 Dec 2009\",\n \"Runtime\": \"162 min\",\n \"Genre\": \"Action, Adventure, Fantasy\",\n \"Director\": \"James Cameron\",\n \"Writer\": \"James Cameron\",\n \"Actors\": \"Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang\",\n \"Plot\": \"A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.\",\n \"Language\": \"English, Spanish\",\n \"Country\": \"USA, UK\",\n \"Awards\": \"Won 3 Oscars. Another 80 wins & 121 nominations.\",\n \"Poster\": \"http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX300.jpg\",\n \"Metascore\": \"83\",\n \"imdbRating\": \"7.9\",\n \"imdbVotes\": \"876,575\",\n \"imdbID\": \"tt0499549\",\n \"Type\": \"movie\",\n \"Response\": \"True\"\n }\n];\n\nfunction getRating(watchList){\n // Only change code below this line\n var averageRating;\n\n\n // Only change code above this line\n return averageRating;\n}\nconsole.log(getRating(watchList));",
"editableContents": "",
"seedEditableRegionBoundaries": [],
"key": "indexjs"
}
|
Do you mean |
This LGTM
The only thing I found was that loading code on the beta projects doesn't update the preview. I may have solved this on the PR where I load users code. I would be fine merging with this problem.
Do we still want to drop the key?
|
I think we are fine moving forward with this, but one final check, @ojeytonwilliams ? |
|
Probably best to get rid of the |

If
loadCodeEpicencounters stored code it cannot parse, it would silently throw an error. This fixes old stored code and then clears out anything it doesn't understand.The text was updated successfully, but these errors were encountered: