-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated the AppRouter API to explicitly define the ReactRouter as a children * Some fixes * Fixed logging issues and a racing condition with protected date and deferred data * Added a signal to onLoadPublicData and onLoadProtectedData handlers * Fixed AppRouter tests * Updated documentation with the new AppRouter props * Documentation touch ups * Removed useRefState * Fixing CI * AppRouter children now accept a function returning a ReactNode * Added changeset files * Reverted AppRouter children function to ReactElement
- Loading branch information
1 parent
10e340e
commit 7caa44b
Showing
27 changed files
with
2,538 additions
and
1,592 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@squide/core": minor | ||
--- | ||
|
||
- Added a `usePlugin` hook. |
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,72 @@ | ||
--- | ||
"@squide/firefly": major | ||
--- | ||
|
||
- The `AppRouter` component now requires to define a `RouterProvider` as a child. This change has been made to provide more flexibility on the consumer side about the definition of the React Router router. | ||
|
||
Before: | ||
|
||
```tsx | ||
<AppRouter | ||
fallbackElement={...} | ||
errorElement={...} | ||
waitForMsw={...} | ||
/> | ||
``` | ||
|
||
Now: | ||
|
||
```tsx | ||
<AppRouter | ||
fallbackElement={...} | ||
errorElement={...} | ||
waitForMsw={...} | ||
> | ||
{(routes, providerProps) => ( | ||
<RouterProvider router={createBrowserRouter(routes)} {...providerProps} /> | ||
)} | ||
</AppRouter> | ||
``` | ||
|
||
- When in development and using React strict mode, the public and protected handler can be called twice. This issue highlighted that the `AppRouter` component doesn't equipe correctly the handlers to dispose of previous HTTP requests if they are called multiple times because of re-renders. Therefore, the handlers now receives an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that should be forwared to the HTTP client initiating the fetch request. | ||
- The fix also requires the consumer to provide new properties (`isPublicDataLoaded` and `isProtectedDataLoaded`) indicating whether or not the public and/or protected data has been loaded. | ||
|
||
```tsx | ||
async function fetchPublicData(setFeatureFlags: (featureFlags: FeatureFlags) => void, signal: AbortSignal) { | ||
try { | ||
const response = await fetch("/api/feature-flags", { | ||
signal | ||
}); | ||
|
||
if (response.ok) { | ||
const data = await response.json(); | ||
|
||
setFeatureFlags(data); | ||
} | ||
} catch (error: unknown) { | ||
if (!signal.aborted) { | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
const [featureFlags, setFeatureFlags] = useState<FeatureFlags>(); | ||
|
||
const handleLoadPublicData = useCallback((signal: AbortSignal) => { | ||
return fetchPublicData(setFeatureFlags, signal); | ||
}, []); | ||
|
||
<AppRouter | ||
onLoadPublicData={handleLoadPublicData} | ||
isPublicDataLoaded={!!featureFlags} | ||
fallbackElement={...} | ||
errorElement={...} | ||
waitForMsw={...} | ||
> | ||
{(routes, providerProps) => ( | ||
<RouterProvider router={createBrowserRouter(routes)} {...providerProps} /> | ||
)} | ||
</AppRouter> | ||
``` | ||
|
||
- Fixed an issue where the deferred registrations could be completed before the protected data has been loaded. |
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,17 @@ | ||
--- | ||
"@squide/react-router": major | ||
--- | ||
|
||
- To be consistent with the other API of Squide, the `useNavigationItems` hook now accept an object literal of options rather than an optional `menuId` argument. | ||
|
||
Before: | ||
|
||
```tsx | ||
const items = useNavigationItems("my-custom-menu"); | ||
``` | ||
|
||
Now: | ||
|
||
```tsx | ||
const items = useNavigationItems({ menuId: "my-custom-menu" }); | ||
``` |
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.