flow: Flow page title is not propagated to the top part of the app layout in a Hilla main layout
Description of the bug
When using a Hilla main menu from start.vaadin.com, the page title of a Flow view (set using @PageTitle or HasDynamicTitle) is applied to document.title but the same value is not shown in the top area above the view (the <h2 slot="navbar"> element). Instead, the title in the navbar falls back to the application name. This is inconsistent with how it works for Hilla views in the same application and with how it works in an application with a main layout implemented in Flow.
Even though this should probably be ultimately fixed in Hilla or Start, I’m filing it against Flow since I expect that some new feature will have to be added to Flow first and then only enabled through Hilla or Start.
Expected behavior
Expected that the Flow view title is shown in the same way as Hilla page titles.
Minimal reproducible example
- Create an application at start.vaadin.com with one Hilla view and one Flow view. Give each view a distinct name (e.g. “Hilla” and “Flow”)
mvn- Navigate to the Hilla view. Observe that that the name of the view is shown in the top of the main layout.
- Navigate to the Flow view (not that it’s not in the menu so you need to type the URL or go thorough the dev mode 404 view). Observe that the value shown in the top of the main layout is the name of the app rather than the name of the view.
Versions
- Vaadin / Flow version: Vaadin 24.4.0.alpha22 (or alpha21 which is what you get from Start today)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (16 by maintainers)
Commits related to this issue
- fix: set page title to documentTitleSignal `UIInternals#setTitle(String)` sets page title via JavaScript to `document.title` and optionally `window.Vaadin.documentTitleSignal.value` where documentTit... — committed to vaadin/flow by tltv 3 years ago
- fix: set page title to documentTitleSignal (#19329) `UIInternals#setTitle(String)` sets page title via JavaScript to `document.title` and optionally `window.Vaadin.documentTitleSignal.value` where do... — committed to vaadin/flow by tltv 3 years ago
- fix: set page title to documentTitleSignal (#19329) `UIInternals#setTitle(String)` sets page title via JavaScript to `document.title` and optionally `window.Vaadin.documentTitleSignal.value` where do... — committed to vaadin/flow by tltv 3 years ago
- fix: set page title to documentTitleSignal (#19329) (#19359) `UIInternals#setTitle(String)` sets page title via JavaScript to `document.title` and optionally `window.Vaadin.documentTitleSignal.value`... — committed to vaadin/flow by vaadin-bot 3 years ago
- fix: Use documentTitleSignal for page title (#41) Uses signal for dynamically updated page title. Part of vaadin/flow#19200 — committed to vaadin/flow-hilla-hybrid-example by mshabarov 3 years ago
- docs: document documentTitleSignal RelatedTo: vaadin/flow#19200 — committed to vaadin/docs by tltv 3 years ago
- docs: document documentTitleSignal (#3439) * docs: document documentTitleSignal RelatedTo: vaadin/flow#19200 * First full pass at editing additions. * Second pass: edited full document. *... — committed to vaadin/docs by tltv 3 years ago
- fix: Use signals for page title (#231) Uses signal for dynamically updated page title. Part of https://github.com/vaadin/flow/issues/19200 — committed to vaadin/skeleton-starter-hilla-react by mshabarov 2 years ago
- Downgrade vaadin to 24.3.12 vaadin 24.4.x introduces issues with routing. So this downgrade ensures the switching of url and page tile. Related to https://github.com/vaadin/flow/issues/19200 — committed to qbicsoftware/data-manager-app by KochTobi 2 years ago
- Introduce single sign-on (SSO) (#651) * Save progress * Save progress and first successful auth * wip * create user after visiting /auth * show datamanager menu * undo landing page rou... — committed to qbicsoftware/data-manager-app by KochTobi 2 years ago
All the actual logic for interpreting the value that Flow sets in the signal instance is in
@layout.tsxwhich is owned by the application. The application developer can remove all the new logic from that file and then everything will work like in Vaadin 24.3. Or they can modify the logic to e.g. combine thedocumentTitleSignalvalue with the value of an application-specific signal to form the actualdocument.titlevalue.To summarize all so far, following
@layout.tsxworks with the start.vaadin.com app with #19329 change in Flow:I don’t think there’s any reason to have
vaadin.documentTitleSignal.value = currentTitle;insideuseEffect. All thatuseEffectdoes in that case is to avoid running the callback again ifcurrentTitlehasn’t changed but that’s something that is already handled by thedocumentTitleSignalinstance.For
defaultTitle, I’m starting suspect that it’s never correct to update the title in the layout’s render function. But we should maybe accept the flickering for now and then separately check with the Hilla team to see if they have some idea for how to better update the title for Hilla views.That example might work in this particular case but it can be improved for clarity and to work as expected also in other cases.
The first problem is that the signal instance is now owned by a
MainLayoutcomponent instance but it’s exported to a wider scope (sincewindow.Vaadinmay outlive theMainLayoutinstance). The signal instance should instead be created outside the render function (but it can still be in the same module for now).The second problem is that
document.titleis updated only in a ReactuseEffectwhich means that it’s updated only when the main layout is re-rendered. If the application has this kind of signal available, then it would be quite natural for a view to e.g. update the signal value based on updates received asynchronously from the server. With the current implementation, that would update the value in the layout but it wouldn’t updatedocument.title. The update should be done in a signal effect rather than in a React effect.With those two adjustments, we would have these lines of code before the render function:
With those changes, the React
useEffectwould be redundant and we could instead directly assign the signal value in the render function (vaadin.documentTitleSignal.value = currentTitle) since the signal implementation already takes care of change detection.The menu title does not necessarily have anything to do with the page title, especially in the case of
HasDynamicTitleand views that aren’t even directly shown in the menu.The view title needs to be propagated to the
<h2>in the main layout at runtime in a way that is consistent with howdocument.titleis set rather than based on the declarative menu configuration.Furthermore, the page title should be updated even if the application doesn’t use the automatic main menu feature at all but instead defines the menu manually.