Skip to content

feat: Partial preserve on refresh #4338

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

Merged
merged 2 commits into from
May 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions articles/flow/advanced/preserving-state-on-refresh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,19 @@

Any elements that aren't direct children of the view component, such as notifications and dialogs, are also preserved. This means that if your `@PreserveOnRefresh` annotated view class opens a dialog in which the user makes edits and then refreshes, the dialog remains visible in its edited state.

=== Partial View Chain Preservation

Partial chain preservation is supported by setting `partialMatch = true` for the [annotationname]`PreserveOnRefresh` annotation.
This will enable reusing partial chain components from the preserved view chain.

Check warning on line 61 in articles/flow/advanced/preserving-state-on-refresh.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.Will] Avoid using 'will'. Raw Output: {"message": "[Vaadin.Will] Avoid using 'will'.", "location": {"path": "articles/flow/advanced/preserving-state-on-refresh.adoc", "range": {"start": {"line": 61, "column": 6}}}, "severity": "WARNING"}

This means that when navigating from a preserve on refresh target to a new url in the same client window context, where windowName matches, the router layouts that have been preserved will be reused without re-creation for the new route.

Check warning on line 63 in articles/flow/advanced/preserving-state-on-refresh.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.Will] Avoid using 'will'. Raw Output: {"message": "[Vaadin.Will] Avoid using 'will'.", "location": {"path": "articles/flow/advanced/preserving-state-on-refresh.adoc", "range": {"start": {"line": 63, "column": 185}}}, "severity": "WARNING"}

Check failure on line 63 in articles/flow/advanced/preserving-state-on-refresh.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'windowName'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'windowName'?", "location": {"path": "articles/flow/advanced/preserving-state-on-refresh.adoc", "range": {"start": {"line": 63, "column": 121}}}, "severity": "ERROR"}

Check failure on line 63 in articles/flow/advanced/preserving-state-on-refresh.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'url'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'url'?", "location": {"path": "articles/flow/advanced/preserving-state-on-refresh.adoc", "range": {"start": {"line": 63, "column": 76}}}, "severity": "ERROR"}

== Preconditions and Limitations

Using the `@PreserveOnRefresh` annotation has some conditions and limitations. They are as follows:

- The annotation must be placed in a component class that's a route target -- typically annotated with `@Route` -- or on a component that implements [interfacename]`RouterLayout`.

- The annotation doesn't support partial preserving.
You can't preserve only some components on the route chain. If the annotation is present on any component in the chain, the entire chain is preserved.

- The component is made to persist only when reloaded in the same browser tab -- the `window.name` client-side property is used to identify the tab -- and only if the URL stays the same.
Visiting another route or changing a URL parameter discards the component state permanently.

Expand Down