-
Notifications
You must be signed in to change notification settings - Fork 973
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
diagnostics throws error if a notfound route is within a Private tag #1325
Conversation
yield err( | ||
this.jsxNode!, | ||
"The 'Not Found' page cannot be within a <Private> tag" | ||
) | ||
if (this.isAuthenticated && this.isNotFound) |
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.
references to isAuthenticated
should be removed in #917 there's a comment by @aldonline indicating that references to authenticated
are no longer being used in favor of private
however, it can't be removed safely without modifying the outline file which is still referencing isAuthenticated
.
You'll notice that there is some old code/stub that references a property called route.isAuthenticated. The "isAuthenticated" name is from before the "Private" tag name was chosen.
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.
Yeah. We need to clean that up :)
if (typeof this.jsxNode.getAttribute('notfound') !== 'undefined') { | ||
return this.jsxNode.compilerNode.parent | ||
.getFullText() | ||
.startsWith('<Private') |
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 was the best way I could figure out how to access the tagName
for parent
as the methods available to jsxNode
aren't available for the parent
node but I am open to suggestions re: different approaches to determining if the parent node is a Private tag.
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.
Hi Monica,
(edit)
- I'm not 100% sure, but I think this heuristic might break if there is trivia before the
<Private>
tag (like a comment). ThegetFullText()
method might return the trivia as well. Please be sure to check this. - Once you've found a good strategy to test for this, please extract it to a separate getter
@lazy() get isPrivate(): boolean {...}
. It is important to keep all these heuristics consistent. We don't want some algorithms to use your strategy, and then someone else reinventing the wheel.
FYI: the ts-morph way of doing this would be something like this:
const tagText = this.jsxNode
.getParentIfKind(tsm.SyntaxKind.JsxElement)
?.getOpeningElement()
?.getTagNameNode()
?.getText()
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.
Thanks for the feedback. I refactored the code based on your feedback and it worked both with and without a comment infront of the tag from my manual testing.
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.
Thanks for your PR!
I added a few comments suggesting changes ;)
@@ -38,6 +38,16 @@ export class RWRoute extends BaseNode { | |||
return LocationLike_toLocation(this.jsxNode) | |||
} | |||
|
|||
@lazy() get hasInvalidPrivateRoute() { | |||
// Return `true` when a notfound route is nested within a Private Tag | |||
if (typeof this.jsxNode.getAttribute('notfound') !== 'undefined') { |
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.
if (typeof this.jsxNode.getAttribute('notfound') !== 'undefined') { | |
if (this.isNotFound) { |
if (typeof this.jsxNode.getAttribute('notfound') !== 'undefined') { | ||
return this.jsxNode.compilerNode.parent | ||
.getFullText() | ||
.startsWith('<Private') |
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.
Hi Monica,
(edit)
- I'm not 100% sure, but I think this heuristic might break if there is trivia before the
<Private>
tag (like a comment). ThegetFullText()
method might return the trivia as well. Please be sure to check this. - Once you've found a good strategy to test for this, please extract it to a separate getter
@lazy() get isPrivate(): boolean {...}
. It is important to keep all these heuristics consistent. We don't want some algorithms to use your strategy, and then someone else reinventing the wheel.
FYI: the ts-morph way of doing this would be something like this:
const tagText = this.jsxNode
.getParentIfKind(tsm.SyntaxKind.JsxElement)
?.getOpeningElement()
?.getTagNameNode()
?.getText()
yield err( | ||
this.jsxNode!, | ||
"The 'Not Found' page cannot be within a <Private> tag" | ||
) | ||
if (this.isAuthenticated && this.isNotFound) |
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.
Yeah. We need to clean that up :)
Hi @M0nica excited to see others helping out with the structure package! You're in good hands with @aldonline who's been teaching us all the ins and outs about how to do this. |
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.
Thanks @M0nica!
I think this is ok to merge now (pending rebasing to "main", but let's wait for @thedavidprice or @peterp to suggest if that's necessary)
It also works in the IDE ;)
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.
Love it, thanks!
This should resolve (Add error diagnostic: notfound page cannot be private) #920.
I tested it locally by running a test app alongside the redwood instance and checking that an error was only thrown when running the diagnostics command when a
Private tag
contained aRoute
with thenotfound
attribute.Below is a screenshot of how the error renders for me when running
![Screen Shot 2020-10-10 at 6 32 36 PM](https://user-images.githubusercontent.com/6998954/95666382-f90d6700-0b26-11eb-8cf4-69a76051f42e.png)
yarn rw check