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

CCDM: support server-side routing in client bootstrapping #6511

Merged
merged 5 commits into from
Sep 23, 2019

Conversation

manolo
Copy link
Member

@manolo manolo commented Sep 20, 2019

Fixes #6256


This change is Reviewable

@manolo manolo added the hilla Issues related to Hilla label Sep 20, 2019
@manolo manolo requested a review from qtdzz September 20, 2019 08:23
@manolo manolo self-assigned this Sep 20, 2019
Copy link
Contributor

@qtdzz qtdzz 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: 3 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @manolo and @qtdzz)


flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts, line 65 at r1 (raw file):

  async start(): Promise<any> {
    await this.flowInit(true);
    document.body.appendChild(this.container);

I had a discussion with @vlukashov, we should put the content of server-side in the body instead of the container. So, the result will be closer to application bootstrapped by server-side.


flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts, line 66 at r1 (raw file):

    await this.flowInit(true);
    document.body.appendChild(this.container);
    return this.flowNavigate({

This also means the first start will take two round trips, right? I wonder if we could somehow modify the init request to include information for the first route so that we only need one round trip for initializing the app and loading the first view.


flow-server/src/main/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandler.java, line 140 at r1 (raw file):

    @Override
    protected void initializeUIWithRouter(VaadinRequest request, UI ui) {

I have a concern here. If we don't override this method, it will navigate to the current location (i.e. localhost:8080/VAADIN/?v-r=init) after creating the UI.

Copy link
Contributor

@platosha platosha left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 6 files at r1.
Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @manolo)


flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts, line 63 at r1 (raw file):

   * Initialize flow in full page mode and with server side routing.
   */
  async start(): Promise<any> {

any does not give much sense.

Do we have a use case for this method’s return value? If not, should it be declared as Promise<void> perhaps?

Maybe even omit return here:

async start() {
  await this.flowInit();
  document.body.appendChild(this.container);
  this.flowNavigate(/*...*/);
}

TypeScript will infer Promise<void> then.

Copy link
Contributor

@platosha platosha left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 6 files at r1.
Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @manolo)

Copy link
Contributor

@qtdzz qtdzz left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r1.
Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @manolo)


flow-server/src/main/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandler.java, line 140 at r1 (raw file):

Previously, qtdzz (Tien Nguyen) wrote…

I have a concern here. If we don't override this method, it will navigate to the current location (i.e. localhost:8080/VAADIN/?v-r=init) after creating the UI.

I investigated the failed test ClientIndexHandlerIT.should_preserveView_When_reloadPreservedOnRefreshView. It turns out that this change causes the error. What happened is: when we navigate to a preserved view, it first initializes the app. After creating the UI, the server navigates to localhost:8080/VAADIN/?v-r=init before it can actually navigate to the @PreseveOnRefresh view. The first navigation will clear all the cache because it doesn't have @PreserveOnRefresh.

Copy link
Member Author

@manolo manolo 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 @manolo, @platosha, @qtdzz, and @vlukashov)


flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts, line 63 at r1 (raw file):

Previously, platosha (Anton Platonov) wrote…

any does not give much sense.

Do we have a use case for this method’s return value? If not, should it be declared as Promise<void> perhaps?

Maybe even omit return here:

async start() {
  await this.flowInit();
  document.body.appendChild(this.container);
  this.flowNavigate(/*...*/);
}

TypeScript will infer Promise<void> then.

Done.


flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts, line 65 at r1 (raw file):

Previously, qtdzz (Tien Nguyen) wrote…

I had a discussion with @vlukashov, we should put the content of server-side in the body instead of the container. So, the result will be closer to application bootstrapped by server-side.

Done.


flow-client/src/main/resources/META-INF/resources/frontend/Flow.ts, line 66 at r1 (raw file):

Previously, qtdzz (Tien Nguyen) wrote…

This also means the first start will take two round trips, right? I wonder if we could somehow modify the init request to include information for the first route so that we only need one round trip for initializing the app and loading the first view.

Yes, there was two round-trips.
Changed server side so as during the init request a location string can be passed.


flow-server/src/main/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandler.java, line 140 at r1 (raw file):

Previously, qtdzz (Tien Nguyen) wrote…

I investigated the failed test ClientIndexHandlerIT.should_preserveView_When_reloadPreservedOnRefreshView. It turns out that this change causes the error. What happened is: when we navigate to a preserved view, it first initializes the app. After creating the UI, the server navigates to localhost:8080/VAADIN/?v-r=init before it can actually navigate to the @PreseveOnRefresh view. The first navigation will clear all the cache because it doesn't have @PreserveOnRefresh.

Good catch. Added back the method which only initializes the route during the init phase when passing an extra location parameter.

Copy link
Contributor

@qtdzz qtdzz left a comment

Choose a reason for hiding this comment

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

Reviewed 8 of 8 files at r2.
Reviewable status: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @manolo and @platosha)


flow-server/src/main/java/com/vaadin/flow/component/internal/JavaScriptBootstrapUI.java, line 221 at r2 (raw file):

                ui.getElement().removeAllChildren();
                ui.getElement().appendChild(newRoot.getElement());
                return;

I think we should call UIInternalUpdater.super.updateRoot(ui, oldRoot, newRoot); here, otherwise, it won't be able to reuse instances, e.g. Layout instances.


flow-server/src/main/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandler.java, line 145 at r2 (raw file):

            try {
                route = URLDecoder.decode(route, "UTF-8").replaceFirst("^/+", "");
            } catch (UnsupportedEncodingException e) {

Sonarqube probably will complain about this empty block.


flow-server/src/main/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandler.java, line 148 at r2 (raw file):

            Location location = new Location(route);
            ui.getRouter().initializeUI(ui, location);

Should we put this inside the try block?

Copy link
Member Author

@manolo manolo 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: 6 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @manolo, @platosha, and @qtdzz)


flow-server/src/main/java/com/vaadin/flow/component/internal/JavaScriptBootstrapUI.java, line 221 at r2 (raw file):

Previously, qtdzz (Tien Nguyen) wrote…
                ui.getElement().removeAllChildren();
                ui.getElement().appendChild(newRoot.getElement());
                return;

I think we should call UIInternalUpdater.super.updateRoot(ui, oldRoot, newRoot); here, otherwise, it won't be able to reuse instances, e.g. Layout instances.

Nice, thanks. Done


flow-server/src/main/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandler.java, line 145 at r2 (raw file):

Previously, qtdzz (Tien Nguyen) wrote…

Sonarqube probably will complain about this empty block.

Done.


flow-server/src/main/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandler.java, line 148 at r2 (raw file):

Previously, qtdzz (Tien Nguyen) wrote…
            Location location = new Location(route);
            ui.getRouter().initializeUI(ui, location);

Should we put this inside the try block?

I don't think so, let don't shadow any error that might produce this code and let the server container to throw

Copy link
Contributor

@qtdzz qtdzz 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 4 files at r4, 1 of 1 files at r5.
Reviewable status: 3 unresolved discussions, 1 of 1 LGTMs obtained (waiting on @manolo and @platosha)

Copy link
Contributor

@platosha platosha left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 2 unresolved discussions, 2 of 1 LGTMs obtained (waiting on @manolo)

OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from External Reviews to Reviewer approved Sep 23, 2019
@@ -123,9 +126,6 @@ protected BootstrapContext createAndInitUI(

config.put(ApplicationConstants.SERVICE_URL, serviceUrl);

// Do not listen to pushState and routerLink events.
config.put(ApplicationConstants.APP_WC_MODE, true);

// TODO(manolo) this comment is left intentionally because we
Copy link
Collaborator

Choose a reason for hiding this comment

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

INFO Complete the task associated to this TODO comment. rule

@vaadin-bot
Copy link
Collaborator

SonarQube analysis reported 1 issue

  • INFO 1 info

Watch the comments in this conversation to review them.

Copy link
Member Author

@manolo manolo 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, 2 of 1 LGTMs obtained

@manolo manolo merged commit d527c98 into ccdm Sep 23, 2019
OLD Vaadin Flow ongoing work (Vaadin 10+) automation moved this from Reviewer approved to Done - pending release Sep 23, 2019
@manolo manolo deleted the mcm/ccdm/flow-start branch September 23, 2019 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hilla Issues related to Hilla +0.1.0
Projects
OLD Vaadin Flow ongoing work (Vaadin ...
  
Done - pending release
Development

Successfully merging this pull request may close these issues.

None yet

5 participants