generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
chore(docs): create ADR for client-side routing #1033
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
Open
taymoor89
wants to merge
6
commits into
main
Choose a base branch
from
1022-create-routing-adr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
468f2fb
chore(docs): create ADR for client-side routing
taymoor89 6886731
Merge branch 'main' into 1022-create-routing-adr
taymoor89 ca48fd3
chore(docs): add note for Tanstack router issue
taymoor89 dc05251
Merge branch 'main' into 1022-create-routing-adr
taymoor89 b0eb0d4
Merge branch 'main' into 1022-create-routing-adr
taymoor89 7f41b96
Merge branch 'main' into 1022-create-routing-adr
andypf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,69 @@ | ||
# ADR: Unified client side routing in Juno | ||
|
||
## Context | ||
|
||
The application requires robust client-side routing with support for: | ||
|
||
- Configurable mounting base paths so application router can work with a parent router in the shell app. | ||
- Optional hashed routing in case shell app don't want to mount child app on certain path or does not have client side routing at all. | ||
- Data preloading and caching. | ||
- URL-based state persistence. | ||
- Support for optional, UI-level state (e.g., modals or panels) without affecting navigation hierarchy. | ||
|
||
We evaluated several routing libraries including React Router and TanStack Router. After evaluating feature sets, flexibility, and community support, we decided to adopt **TanStack Router**. | ||
|
||
Additionally, to integrate routing with data fetching and ensure URL-driven state management, we considered various combinations of client-side state and URL parsing utilities. | ||
|
||
## Decision | ||
|
||
We adopted the following architecture for client-side routing and state: | ||
|
||
1. **Routing Library**: We use **TanStack Router** to manage client-side routing. | ||
|
||
- The router mounts to a `basePath`, provided via application props, defaulting to `'/'`. | ||
- This allows embedding the app under sub-paths without requiring changes to the router configuration. | ||
|
||
2. **Hashed Routing Support**: | ||
|
||
- The router can optionally use hashed history (`#` URLs) when the prop `enableHashedRouting` is set to `true`. It defaults to `false`. | ||
- This supports deployments where traditional URL rewriting is not available (e.g., GitHub Pages or an External Dashboard). | ||
|
||
- > **Note:** | ||
> TanStack Router has a known [issue/behavior](https://github.com/TanStack/router/issues/4370#issuecomment-3012344925) in **hashed routing mode** where it includes query parameters from the entire URL—not just the hash fragment—when supplying the `searchString`. | ||
> If your application depends on extracting query parameters specifically from the **hash fragment**, you’ll need to handle this manually in the `parseSearch` method within your router configuration. | ||
|
||
3. **Data Loading and Caching**: | ||
|
||
- We use **TanStack Query** for invoking API calls and caching their results. | ||
- Apollo Client is still used for the actual GraphQL operations, but TanStack Query provides better control over caching and fetching behavior during route transitions. | ||
|
||
4. **URL State Encoding/Decoding**: | ||
|
||
- We utilize the `v2/encode` and `v2/decode` utilities from the `url-state-provider` package to handle query string parameters. | ||
andypf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Applications may persist their state in the URL, as long as: | ||
- The state can be serialized by the `encode` utility. | ||
- The state can be correctly interpreted back after `decode` utility is applied. | ||
|
||
5. **Route Definitions and Optional UI State**: | ||
- Routes are defined using TanStack Router's file-based routing to reflect the app’s core navigational paths. | ||
- To control **optional UI elements** such as panels, modals, or drawers (that can appear conditionally on a given page), we use **URL search parameters** rather than path parameters. | ||
- This ensures that opening or closing optional UI components does **not trigger full route transitions** or reload data unnecessarily. | ||
- It also preserves the logical page hierarchy and improves back/forward navigation behavior in the browser. | ||
|
||
## Consequences | ||
|
||
- **Pros**: | ||
|
||
- Flexible routing that supports multiple deployment environments, Shell App(with or without router), External Dashboards. | ||
- Improved control over API call timing and caching via TanStack Query. | ||
- Clear separation of concerns between routing, data loading, and state persistence. | ||
- Clean URL patterns that distinguish between core navigation and optional UI state. | ||
- Enhanced browser UX with predictable back/forward behavior for panels and modals. | ||
|
||
- **Cons**: | ||
- Increases the learning curve slightly due to the use of newer libraries (TanStack Router). | ||
- The encode/decode contract must be strictly followed to prevent inconsistent behavior. | ||
|
||
## Notes | ||
|
||
- Developers must validate state objects before encoding to prevent invalid URL states. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.