Centralize route matching in one place
Description
This PR extracts some refactoring I did in #1933 .
So far, we were matching routes for API and, if no matched API route was found, we ran again similar logic to match Server Components. The matching process is basically iterating over every route, converting string keys to regular expressions and testing them until we find a route match.
With the changes proposed here, we only run the matching logic once at the beginning and store the result for later. It should reduce code size and CPU a little but, more importantly, it centralizes the route matching in one place so that we can implement plugins later.
Before submitting the PR, please make sure you do the following:
- [x] Read the Contributing Guidelines
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
fixes #123) - [ ] Update docs in this repository according to your change
- [ ] Run
yarn changeset addif this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning
We detected some changes in packages/*/package.json or packages/*/src, and there are no updates in the .changeset.
If the changes are user-facing and should cause a version bump, run "yarn changeset add" to track your changes and include them in the next release CHANGELOG.
If you are making simple updates to examples or documentation, you do not need to add a changeset.
Oxygen deployed a preview of your fd-fix-debug-info branch. Details:
| Storefront | Status | Preview link | Deployment details | Last update (UTC) |
|---|---|---|---|---|
| custom-cart-method | ✅ Successful (Logs) | Preview deployment | Inspect deployment | April 19, 2024 2:50 PM |
| third-party-queries-caching | ✅ Successful (Logs) | Preview deployment | Inspect deployment | April 19, 2024 2:50 PM |
| vite | ✅ Successful (Logs) | Preview deployment | Inspect deployment | April 19, 2024 2:50 PM |
| subscriptions | ✅ Successful (Logs) | Preview deployment | Inspect deployment | April 19, 2024 2:50 PM |
| optimistic-cart-ui | ✅ Successful (Logs) | Preview deployment | Inspect deployment | April 19, 2024 2:50 PM |
| skeleton | ✅ Successful (Logs) | Preview deployment | Inspect deployment | April 19, 2024 2:50 PM |
Learn more about Hydrogen's GitHub integration.