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

Execute BeforeEnter listeners starting with top parent. #7130

Merged
merged 31 commits into from Jan 14, 2020

Conversation

bogdanudrescu
Copy link
Contributor

@bogdanudrescu bogdanudrescu commented Dec 11, 2019

Fixes #4595

Route layouts and target component are created right before the event is fired. So if a parent layout beforeEnter redirects, then the rest of the layouts in the chain and the component target itself won't be created.

Before this change the order of events was as follow:

  1. target component and layouts are created.
  2. setParameter event is triggered.
  3. Global handlers are invoked.
  4. BeforeEnter events is triggered starting with target component and ending with the first layout.

After the change:

  1. Global handlers are invoked.
  2. components are created starting with first layout in the chain and ending with the target component.
  3. each BeforeEvent is triggered right after the layout or component is created (if implementing BeforeEventHandler) and before the next layout or component in the chain is created.
  4. setParameter is invoked right before the target's beforeEnter or any of its children or last if no BeforeEnterHandler is implemented in target or its children.

This PR also fixes the case when a route layout redirects to the navigation target currently navigating to.

This change is Reviewable

@bogdanudrescu bogdanudrescu self-assigned this Dec 11, 2019
@bogdanudrescu bogdanudrescu marked this pull request as ready for review January 2, 2020 07:32
Copy link
Contributor

@caalador caalador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @bogdanudrescu, @caalador, and @Legioth)


flow-server/src/main/java/com/vaadin/flow/router/BeforeEvent.java, line 439 at r8 (raw file):

     * @deprecated use {@link #getRerouteTargetType()} instead.
     */
    @deprecated

It should be @Deprecated


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 466 at r7 (raw file):

Previously, bogdanudrescu (Bogdan Udrescu) wrote…

Then may we leave it as it is? Inside createChain... we need to reverse it back and forth since there it's either created or it comes in with target first and we need to send the events the other way then we need to output it with target first, although it's create starting with root.

Could we just part them into two methods where one handles new chain creation and one handles a prepopulated one?

Copy link
Contributor Author

@bogdanudrescu bogdanudrescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @bogdanudrescu, @caalador, and @Legioth)


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 466 at r7 (raw file):

Previously, caalador wrote…

Could we just part them into two methods where one handles new chain creation and one handles a prepopulated one?

One moment, I'll make a bit of changes and add one more test.

Copy link
Contributor Author

@bogdanudrescu bogdanudrescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @bogdanudrescu, @caalador, and @Legioth)


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 466 at r7 (raw file):

Previously, bogdanudrescu (Bogdan Udrescu) wrote…

One moment, I'll make a bit of changes and add one more test.

Yes, we can do that too.

Copy link
Contributor Author

@bogdanudrescu bogdanudrescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @bogdanudrescu, @caalador, and @Legioth)


flow-server/src/main/java/com/vaadin/flow/router/BeforeEvent.java, line 439 at r8 (raw file):

Previously, caalador wrote…

It should be @Deprecated

Done.

@vaadin-bot vaadin-bot added +0.1.0 and removed +1.0.0 labels Jan 10, 2020
caalador
caalador previously approved these changes Jan 10, 2020
Copy link
Contributor

@caalador caalador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ask someone else from the to also have a look.

Reviewed 3 of 3 files at r9.
Reviewable status: 1 unresolved discussion, 0 of 1 LGTMs obtained (waiting on @bogdanudrescu and @Legioth)

OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Changes Requested to Reviewer approved Jan 10, 2020
@caalador caalador moved this from Reviewer approved to External Reviews in OLD Vaadin Flow ongoing work (Vaadin 10+) Jan 10, 2020
Copy link
Contributor

@joheriks joheriks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 7 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @bogdanudrescu and @Legioth)


flow-server/src/main/java/com/vaadin/flow/router/BeforeEvent.java, line 445 at r9 (raw file):

    /**
     * Get the route target for rerouting.

With his API addition, there will be one method called getRerouteTarget() and one calledgetRerouteTargetType(), and the JavaDoc for getRerouteTarget() also says effectively ´gets the reroute target`. It could be good to write that this methods gets route target type for better consistency in the terminology.


flow-server/src/main/java/com/vaadin/flow/router/EventUtil.java, line 132 at r9 (raw file):

                .flatMap(chainRoot -> collectBeforeEnterObserversStream(
                        chainRoot.getElement(),
                        getElements(childrenExclusions)))

Evaluating getElements(childrenExclusions) inside the lambda is suboptimal as it leads to the childrenExclusionsstream being materialized multiple times. The subexpression could be lifted outside the flatMap expression.


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 82 at r9 (raw file):

    private Postpone postponed = null;

    private LocationChangeEvent locationChangeEvent;

Not blocking, but maybe initialize this also explicitly to null for clarity.


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 196 at r9 (raw file):

                // We're returning because the preserved chain is not ready to
                // be used as is, and requires client data requested within
                // `createOrRehandlePreserveOnRefreshComponent`. Once the data

Since method createOrRehandlerPreserveOnRefreshComponent is renamed in the change, update also the comment to reduce confusion.


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 593 at r9 (raw file):

    /*
     * Check whether the eventHandler is the component itself ot a child of it.

Typo: "ot" -> "or"


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 595 at r9 (raw file):

     * Check whether the eventHandler is the component itself ot a child of it.
     */
    private boolean isEqualsOrChild(BeforeEnterHandler eventHandler,

Method could be static and the name improved, since the method doesn't return true if the arguments are equal (but rather, if their contained elements are equal).

OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from External Reviews to Changes Requested Jan 10, 2020
Copy link
Contributor Author

@bogdanudrescu bogdanudrescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 7 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @bogdanudrescu, @caalador, @joheriks, and @Legioth)


flow-server/src/main/java/com/vaadin/flow/router/BeforeEvent.java, line 445 at r9 (raw file):

Previously, joheriks (Johannes Eriksson) wrote…

With his API addition, there will be one method called getRerouteTarget() and one calledgetRerouteTargetType(), and the JavaDoc for getRerouteTarget() also says effectively ´gets the reroute target`. It could be good to write that this methods gets route target type for better consistency in the terminology.

Done.


flow-server/src/main/java/com/vaadin/flow/router/EventUtil.java, line 132 at r9 (raw file):

Previously, joheriks (Johannes Eriksson) wrote…

Evaluating getElements(childrenExclusions) inside the lambda is suboptimal as it leads to the childrenExclusionsstream being materialized multiple times. The subexpression could be lifted outside the flatMap expression.

Done.


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 82 at r9 (raw file):

Previously, joheriks (Johannes Eriksson) wrote…

Not blocking, but maybe initialize this also explicitly to null for clarity.

Done.


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 196 at r9 (raw file):

Previously, joheriks (Johannes Eriksson) wrote…

Since method createOrRehandlerPreserveOnRefreshComponent is renamed in the change, update also the comment to reduce confusion.

Done.


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 595 at r9 (raw file):

Previously, joheriks (Johannes Eriksson) wrote…

Method could be static and the name improved, since the method doesn't return true if the arguments are equal (but rather, if their contained elements are equal).

Done.

Copy link
Contributor Author

@bogdanudrescu bogdanudrescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 7 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @bogdanudrescu, @caalador, @joheriks, and @Legioth)


flow-server/src/main/java/com/vaadin/flow/router/internal/AbstractNavigationStateRenderer.java, line 593 at r9 (raw file):

Previously, joheriks (Johannes Eriksson) wrote…

Typo: "ot" -> "or"

Done.

@vaadin-bot
Copy link
Collaborator

SonarQube analysis reported 3 issues

  • INFO 3 info

Watch the comments in this conversation to review them.

2 extra issues

Note: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:

  1. INFO BeforeEvent.java#L64: Do not forget to remove this deprecated code someday. rule
  2. INFO BeforeEvent.java#L106: Do not forget to remove this deprecated code someday. rule

@vaadin-bot vaadin-bot added +1.0.0 and removed +0.1.0 labels Jan 14, 2020
Copy link
Contributor

@joheriks joheriks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 3 of 3 files at r10.
Reviewable status: 1 unresolved discussion, 1 of 1 LGTMs obtained (waiting on @bogdanudrescu and @Legioth)

OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Changes Requested to Reviewer approved Jan 14, 2020
Copy link
Contributor

@joheriks joheriks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dismissed @vaadin-bot from a discussion.
Reviewable status: :shipit: complete! all discussions resolved, 1 of 1 LGTMs obtained (waiting on @Legioth)

@bogdanudrescu bogdanudrescu merged commit a0bfec3 into master Jan 14, 2020
OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Reviewer approved to Done - pending release Jan 14, 2020
@bogdanudrescu bogdanudrescu deleted the bu/beforeevents-order branch January 14, 2020 08:00
@pleku pleku added +0.1.0 and removed +1.0.0 labels Jan 15, 2020
@pleku pleku added this to the 2.2.0.alpha12 milestone Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Development

Successfully merging this pull request may close these issues.

Route target instances are created before beforeEnter is called
5 participants