Sitelet https://web.archive.org/web/20220206165831/https://github.com/freeCodeCamp/freeCodeCamp/pull/44437
Skip to content
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

Conversation

@ojeytonwilliams
Copy link
Contributor

@ojeytonwilliams ojeytonwilliams commented Dec 9, 2021 •

If loadCodeEpic encounters 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.

@ojeytonwilliams ojeytonwilliams requested a review from as a code owner Dec 9, 2021
@gitpod-io
Copy link

@gitpod-io gitpod-io bot commented Dec 9, 2021

@codesee-architecture-diagrams
Copy link
Contributor

@codesee-architecture-diagrams codesee-architecture-diagrams bot commented Dec 9, 2021 •

👀 Review this PR in a CodeSee Review Map

Preview the Review Map

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

Copy link
Contributor

@ShaunSHamilton ShaunSHamilton left a comment

Nit-picky, because the fewer types the more betterer.

@ojeytonwilliams
Copy link
Contributor Author

@ojeytonwilliams ojeytonwilliams commented Dec 9, 2021

@raisedadead what do you think about purging the saved javascript challenge code? Just the challenge code, mind, nothing else.

@raisedadead
Copy link
Member

@raisedadead raisedadead commented Dec 9, 2021

what do you think about purging the saved javascript challenge code?

Does this include user code too?

@ShaunSHamilton
Copy link
Contributor

@ShaunSHamilton ShaunSHamilton commented Dec 9, 2021

what do you think about purging the saved javascript challenge code?

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 Ctrl + S in the editor)

@ShaunSHamilton
Copy link
Contributor

@ShaunSHamilton ShaunSHamilton commented Dec 9, 2021

@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)

@ojeytonwilliams
Copy link
Contributor Author

@ojeytonwilliams ojeytonwilliams commented Dec 9, 2021

Blocked while we discuss what we want to implement

@ojeytonwilliams ojeytonwilliams changed the title fix: purge invalid stored code fix: update invalid stored code Dec 20, 2021
@ojeytonwilliams
Copy link
Contributor Author

@ojeytonwilliams ojeytonwilliams commented Dec 20, 2021

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.

@Sembauke
Copy link
Contributor

@Sembauke Sembauke commented Dec 20, 2021 •

Thanks @ojeytonwilliams ,

I tried to use the editor on mobile but came across some issues when switching panes and trying to run tests.
(Most of the time the code would just not save)

Also some users report unable to remove text or type at all.
It is hard to know if these issue's are from the mobile app or from the Monaco Editor itself.

Hope this fixes the storing issues.

@ojeytonwilliams
Copy link
Contributor Author

@ojeytonwilliams ojeytonwilliams commented Dec 20, 2021

@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.

@ShaunSHamilton
Copy link
Contributor

@ShaunSHamilton ShaunSHamilton commented Dec 20, 2021

@Sembauke For reference, we have always pointed mobile users to: https://www.freecodecamp.org/news/freecodecamp-mobile/

@raisedadead raisedadead changed the title fix: update invalid stored code fix(client): update invalid stored code Jan 7, 2022
ShaunSHamilton
ShaunSHamilton previously approved these changes Jan 7, 2022
Copy link
Contributor

@ShaunSHamilton ShaunSHamilton left a comment

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"
}

@ojeytonwilliams
Copy link
Contributor Author

@ojeytonwilliams ojeytonwilliams commented Jan 7, 2022

Do you mean "key"? We can delete that, I think.

moT01
moT01 previously approved these changes Jan 25, 2022
Copy link
Member

@moT01 moT01 left a comment

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?

@ShaunSHamilton
Copy link
Contributor

@ShaunSHamilton ShaunSHamilton commented Jan 31, 2022

I think we are fine moving forward with this, but one final check, @ojeytonwilliams ?

@ojeytonwilliams ojeytonwilliams dismissed stale reviews from moT01 and ShaunSHamilton via 1251bdf Jan 31, 2022
@ojeytonwilliams ojeytonwilliams enabled auto-merge (squash) Jan 31, 2022
@ojeytonwilliams
Copy link
Contributor Author

@ojeytonwilliams ojeytonwilliams commented Jan 31, 2022

Probably best to get rid of the key, rather than leaving it around when we know it's not necessary. I've updated the PR.

Copy link
Contributor

@ShaunSHamilton ShaunSHamilton left a comment

Thank you, Dr. Oliver!

LGTM 👍

moT01
moT01 approved these changes Feb 1, 2022
@ojeytonwilliams ojeytonwilliams merged commit c541baf into freeCodeCamp:main Feb 1, 2022
13 checks passed
@ojeytonwilliams ojeytonwilliams deleted the fix/purge-invalid-stored-code branch Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants