Removed redundant nullish coalescing operator#10719
Conversation
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
|
Hello! Thank you for opening your first PR to Astro’s Docs! 🎉 Here’s what will happen next:
|
✅ Deploy Preview for astro-docs-2 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
Hi @chasoft, and thanks for taking the time to fix the docs! I'm a bit confused here because I remember adding that (in #10120) because Typescript was complaining without. So, I tested again to be sure it was safe to remove the nullish coalescing operator (some changes might have happen since), and it doesn't seem to be the case every time. First I used the default branch ( Then I remembered that we were working on the To be honest, I don't understand why there is a difference between the two branches. This is the same component. But since the error may be raised, I'm not sure it's safe to remove the operator from the docs... |
|
Don't know if it helps but in general I'd avoid the double call to get stuff from local storage and do something like this instead: if (typeof localStorage !== 'undefined') {
const theme = localStorage.getItem('theme');
if (theme) return theme;
} |
|
I was just confused about Typescript behavior on two files that seem identical (once the operator removed)... Refactoring didn't come to my mind. 😄 But yes, this is another solution and it might also be easier to understand while preventing Typescript errors/nullish coalescing operator. |
|
So Fryuni has found the difference between the two branches. 🙌🏽 One uses But I think Chris' suggestion is a good idea to prevent the error if someone forgot the |
Thank you for your response. I'll take another look at this by tomorrow. |
Refactor theme retrieval from localStorage to avoid using `is:inline` for bypassing type checking. This approach ensures better code quality and highlights areas in our implementation that require improvement.
|
hi @ArmandPhilippot, I've just submitted a new commit to remove Reason: refactor theme retrieval from localStorage to avoid using If this meets your approval, I'd be happy to update the demo branch at this link. https://github.com/withastro/blog-tutorial-demo/tree/87937ec6397d1a458a3bd4ec3fec49ca57b74ab2. |
|
I think we do want to keep the
|
ArmandPhilippot
left a comment
There was a problem hiding this comment.
Thanks @chasoft, your refactoring works with and without Typescript parsing so looks good to me!
I only left a suggestion to add back is:inline which is needed to prevent FOUC (we miss that in the content-collection branch).
After that, looks ready to merge! Welcome to Team Docs! 🚀
And you're very welcome to apply those changes to the blog-tutorial-demo. Thanks for willing to do that! 🙌🏽
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
ArmandPhilippot
left a comment
There was a problem hiding this comment.
Thanks for the update! LGTM!

Description (required)
This PR removes the redundant nullish coalescing operator (??) from the code that retrieves the theme from localStorage. The nullish coalescing operator is unnecessary in this context because the existence of the theme in localStorage is already checked.
Related issues & labels (optional)