Skip to content
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

fix: check for client route conflicts #20188

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

tepi
Copy link
Contributor

@tepi tepi commented Oct 8, 2024

Fixes #20144

@tepi tepi marked this pull request as draft October 8, 2024 15:26
@tepi
Copy link
Contributor Author

tepi commented Oct 8, 2024

Please feel free to test/review. Does need tests still.

Copy link

github-actions bot commented Oct 8, 2024

Test Results

1 142 files  ±0  1 142 suites  ±0   1h 27m 37s ⏱️ +24s
7 461 tests +2  7 411 ✅ +2  50 💤 ±0  0 ❌ ±0 
7 831 runs  +3  7 771 ✅ +3  60 💤 ±0  0 ❌ ±0 

Results for commit 055fed8. ± Comparison against base commit 4924daa.

♻️ This comment has been updated with latest results.

@vaadin-bot vaadin-bot added +1.0.0 and removed +0.0.1 labels Oct 10, 2024
@vaadin-bot vaadin-bot added +0.0.1 and removed +1.0.0 labels Oct 10, 2024
@tepi tepi marked this pull request as ready for review October 10, 2024 13:17
@tltv tltv self-assigned this Oct 11, 2024
Copy link
Member

@tltv tltv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client file-route like Frontend/views/hello-world/{{optionalId}}.tsx would end up matching with both hello-world and hello-world/:optionalId?. This might be OK with optional route param.

But it's same thing with required param with Frontend/views/hello-world/{requiredId}.tsx + hello-world/:requiredId? which seems wrong.

To avoid throwing exception in this case, there can be a check for viewInfo.children() to skip validation of client routes that have children.

@tepi
Copy link
Contributor Author

tepi commented Oct 11, 2024

But it's same thing with required param with Frontend/views/hello-world/{requiredId}.tsx + hello-world/:requiredId? which seems wrong.

To avoid throwing exception in this case, there can be a check for viewInfo.children() to skip validation of client routes that have children.

So to be clear, we want to allow a flow route 'hello-world' and hilla route 'hello-world/required-id' at the same time?

Edit: And I guess the same thing should work also if flow<->hilla routes are the other way around

@tltv
Copy link
Member

tltv commented Oct 11, 2024

So to be clear, we want to allow a flow route 'hello-world' and hilla route 'hello-world/required-id' at the same time?

Edit: And I guess the same thing should work also if flow<->hilla routes are the other way around

On second thought, I changed my mind.

It's actually hard to think of any real use cases for allowing that. It would be confusing to have /hello-world showing Flow view and hello-world/12345 showing Hilla view. Let's keep it strict unless someone has better reason to allow it anyway.

Docs is not saying anything regarding mixing or not mixing server and client routes this way

@tepi
Copy link
Contributor Author

tepi commented Oct 11, 2024

It's actually hard to think of any real use cases for allowing that. It would be confusing to have /hello-world showing Flow view and hello-world/12345 showing Hilla view. Let's keep it strict unless someone has better reason to allow it anyway.

I agree, and it can get even more complicated:

Screenshot 2024-10-11 at 14 02 32

So in this case we could tentatively have the items/show on Flow side and items/:identifier on Hilla side. I'm not even sure what would happen with such configuration right now, my guess is items/show would just go the the parameterized Hilla view anyway.

Maybe we should instead document that at least currently such combinations with identical base route are not supported for mixing.

tltv
tltv previously approved these changes Oct 11, 2024
@tepi
Copy link
Contributor Author

tepi commented Oct 11, 2024

Please hold on merging for now. Still need to figure out at which phase it is best to check for the conflicts.

tltv
tltv previously approved these changes Oct 11, 2024
@tepi
Copy link
Contributor Author

tepi commented Oct 14, 2024

Update: Moved checking to end of VaadinService#init - everything seems to be ready for checking at that point.

Co-authored-by: Tomi Virtanen <tltv@vaadin.com>
Copy link

sonarcloud bot commented Oct 14, 2024

@tltv
Copy link
Member

tltv commented Oct 14, 2024

Update: Moved checking to end of VaadinService#init - everything seems to be ready for checking at that point.

Adding or changing client routes would not be detected even after page refresh. Could conflict check go to MenuRegistry#collectClientMenuItems(...), but only do the check if Map<String, AvailableViewInfo> is changed. Meaning that map hash should be stored somewhere and next call would check it for changes, before doing any validation. Point would be to make sure conflicts are checked on page refresh at least, if it's not possible to do it immediately after changes.

Hash or maybe even copy of the whole Map could be stored in VaadinContext in VaadinService.getCurrent().getContext(). But only in dev mode (AbstractConfiguration is already available in collectClientMenuItems).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Router swallow Hilla or Flow route when both routes have the same name
4 participants