-
Notifications
You must be signed in to change notification settings - Fork 161
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
Conversation
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.
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.
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.
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.
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.
Reviewed 1 of 6 files at r1.
Reviewable status: 4 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @manolo)
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.
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
.
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.
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 tolocalhost: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.
d29940f
to
7c97f84
Compare
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.
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?
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.
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
ddf1793
to
13db7ad
Compare
13db7ad
to
3daf2f3
Compare
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.
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)
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.
Reviewable status: 2 unresolved discussions, 2 of 1 LGTMs obtained (waiting on @manolo)
@@ -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 |
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.
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.
Dismissed @vaadin-bot from a discussion.
Reviewable status: complete! all discussions resolved, 2 of 1 LGTMs obtained
Fixes #6256
This change is