Skip to content

Commit d4291ba

Browse files
authored
fix: extract browser details earlier (#23412)
Extract the browserDetails earlier so that they are available when UiInitListeners are fired. Fixes #23396
1 parent c2e7ae7 commit d4291ba

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

flow-server/src/main/java/com/vaadin/flow/server/BootstrapHandler.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
import com.vaadin.flow.component.PushConfiguration;
6161
import com.vaadin.flow.component.UI;
62+
import com.vaadin.flow.component.page.ExtendedClientDetails;
6263
import com.vaadin.flow.component.page.Inline;
6364
import com.vaadin.flow.component.page.Push;
6465
import com.vaadin.flow.component.page.Viewport;
@@ -1354,6 +1355,9 @@ protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass,
13541355

13551356
push.map(Push::transport).ifPresent(pushConfiguration::setTransport);
13561357

1358+
// Parse browser details from request parameters and store in UI
1359+
extractAndStoreBrowserDetails(request, ui);
1360+
13571361
// Set thread local here so it is available in init
13581362
UI.setCurrent(ui);
13591363
ui.doInit(request, session.getNextUIid(), context.getAppId());
@@ -1367,6 +1371,34 @@ protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass,
13671371
return context;
13681372
}
13691373

1374+
/**
1375+
* Extracts browser details from the request JSON parameter and stores them
1376+
* in the UI's internals as ExtendedClientDetails.
1377+
*
1378+
* @param request
1379+
* the request containing browser details as JSON parameter
1380+
* @param ui
1381+
* the UI instance to store the details in
1382+
*/
1383+
private void extractAndStoreBrowserDetails(VaadinRequest request, UI ui) {
1384+
// Extract browser details JSON parameter from request
1385+
// This is sent by the client in the v-r=init request
1386+
String browserDetailsJson = request.getParameter("v-browserDetails");
1387+
1388+
if (browserDetailsJson != null && !browserDetailsJson.isEmpty()) {
1389+
try {
1390+
JsonNode json = JacksonUtils.readTree(browserDetailsJson);
1391+
ExtendedClientDetails details = ExtendedClientDetails
1392+
.fromJson(ui, json);
1393+
ui.getInternals().setExtendedClientDetails(details);
1394+
} catch (Exception e) {
1395+
// Log and continue without browser details
1396+
getLogger().debug(
1397+
"Failed to parse browser details from init request", e);
1398+
}
1399+
}
1400+
}
1401+
13701402
protected void initializeUIWithRouter(BootstrapContext context, UI ui) {
13711403
if (ui.getInternals().getRouter() != null) {
13721404
ui.getInternals().getRouter().initializeUI(ui, context.getRoute());

flow-server/src/main/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandler.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import com.vaadin.flow.component.PushConfiguration;
3030
import com.vaadin.flow.component.UI;
31-
import com.vaadin.flow.component.page.ExtendedClientDetails;
3231
import com.vaadin.flow.internal.BootstrapHandlerHelper;
3332
import com.vaadin.flow.internal.DevModeHandler;
3433
import com.vaadin.flow.internal.DevModeHandlerManager;
@@ -171,40 +170,9 @@ protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass,
171170

172171
config.put("requestURL", requestURL);
173172

174-
// Parse browser details from request parameters and store in UI
175-
extractAndStoreBrowserDetails(request, context.getUI());
176-
177173
return context;
178174
}
179175

180-
/**
181-
* Extracts browser details from the request JSON parameter and stores them
182-
* in the UI's internals as ExtendedClientDetails.
183-
*
184-
* @param request
185-
* the request containing browser details as JSON parameter
186-
* @param ui
187-
* the UI instance to store the details in
188-
*/
189-
private void extractAndStoreBrowserDetails(VaadinRequest request, UI ui) {
190-
// Extract browser details JSON parameter from request
191-
// This is sent by the client in the v-r=init request
192-
String browserDetailsJson = request.getParameter("v-browserDetails");
193-
194-
if (browserDetailsJson != null && !browserDetailsJson.isEmpty()) {
195-
try {
196-
JsonNode json = JacksonUtils.readTree(browserDetailsJson);
197-
ExtendedClientDetails details = ExtendedClientDetails
198-
.fromJson(ui, json);
199-
ui.getInternals().setExtendedClientDetails(details);
200-
} catch (Exception e) {
201-
// Log and continue without browser details
202-
getLogger().debug(
203-
"Failed to parse browser details from init request", e);
204-
}
205-
}
206-
}
207-
208176
@Override
209177
protected void initializeUIWithRouter(BootstrapContext context, UI ui) {
210178
}

0 commit comments

Comments
 (0)