Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unwrap router target class in getRouteTarget (#19151)
AbstractNavigationStateRenderer.getRouteTarget filters the active router targets chain comparing collection items class with the route target type. The filter may fail if routes instances are proxy objects created by frameworks like spring, since the class will not match the required one. This cahnge ensures that synthetic and proxy classes are discarded, allowing for more accurate comparison when filtering objects based on their real application class. Fixes #19100
- Loading branch information
1 parent
b3ddbdc
commit 68a1ead
Showing
11 changed files
with
293 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...test-spring-common/src/main/java/com/vaadin/flow/spring/test/ProxiedNavigationTarget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.spring.test; | ||
|
||
import java.util.UUID; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.context.annotation.ScopedProxyMode; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.BeforeEvent; | ||
import com.vaadin.flow.router.HasUrlParameter; | ||
import com.vaadin.flow.router.OptionalParameter; | ||
import com.vaadin.flow.router.Route; | ||
import com.vaadin.flow.router.RouterLink; | ||
|
||
import static com.vaadin.flow.spring.scopes.VaadinUIScope.VAADIN_UI_SCOPE_NAME; | ||
|
||
@Route("proxied") | ||
public class ProxiedNavigationTarget extends Div | ||
implements HasUrlParameter<Integer> { | ||
|
||
private final String uuid = UUID.randomUUID().toString(); | ||
private final AtomicInteger counter = new AtomicInteger(); | ||
private final RouterLink routerLink; | ||
private final Div clickCounter; | ||
|
||
public ProxiedNavigationTarget() { | ||
Div uuid = new Div(this.uuid); | ||
uuid.setId("COMPONENT_ID"); | ||
add(uuid); | ||
|
||
clickCounter = new Div("P:0, C:0"); | ||
clickCounter.setId("CLICK_COUNTER"); | ||
add(clickCounter); | ||
|
||
// Self navigation should use the same view instance | ||
routerLink = new RouterLink("Self Link", ProxiedNavigationTarget.class, | ||
counter.incrementAndGet()); | ||
add(routerLink); | ||
} | ||
|
||
// @Async annotation should cause Spring to create a proxy for the | ||
// bean instance | ||
@Async | ||
public void asyncMethod() { | ||
|
||
} | ||
|
||
@Override | ||
public void setParameter(BeforeEvent event, | ||
@OptionalParameter Integer parameter) { | ||
if (parameter != null) { | ||
clickCounter.setText("P:" + parameter + ", C:" + counter.get()); | ||
routerLink.setRoute(ProxiedNavigationTarget.class, | ||
counter.incrementAndGet()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.