Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/app/components/app-shell/AppShell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type ReactNode, Suspense, lazy, useState } from 'react';
import { Provider as JotaiProvider } from 'jotai';
import type { createStore } from 'jotai/vanilla';
import { OverlayContainerProvider, PopOutContainerProvider, TooltipContainerProvider } from 'folds';
import { QueryClientProvider } from '@tanstack/react-query';
import { isTauri } from '@tauri-apps/api/core';
Expand All @@ -24,9 +25,10 @@ type AppShellProps = {
children: ReactNode;
queryClient: Parameters<typeof QueryClientProvider>[0]['client'];
screenSize: ScreenSize;
jotaiStore?: ReturnType<typeof createStore>;
};

export function AppShell({ children, queryClient, screenSize }: AppShellProps) {
export function AppShell({ children, queryClient, screenSize, jotaiStore }: AppShellProps) {
const tauriOs = isTauri() ? osType() : undefined;
const useDesktopTitleBar = tauriOs === 'windows' || tauriOs === 'linux';
const useMacTitleBar = tauriOs === 'macos';
Expand All @@ -41,7 +43,7 @@ export function AppShell({ children, queryClient, screenSize }: AppShellProps) {
<OverlayContainerProvider value={portalContainer ?? undefined}>
<ScreenSizeProvider value={screenSize}>
<QueryClientProvider client={queryClient}>
<JotaiProvider>
<JotaiProvider store={jotaiStore}>
<TauriFrontendReady />
<div
style={{
Expand Down
27 changes: 18 additions & 9 deletions src/app/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,18 @@ const ReactQueryDevtools = lazy(async () => {
type BootstrappedAppShellProps = {
clientConfig: ClientConfig;
screenSize: ScreenSize;
jotaiStore: ReturnType<typeof createStore>;
};

function BootstrappedAppShell({ clientConfig, screenSize }: BootstrappedAppShellProps) {
function BootstrappedAppShell({ clientConfig, screenSize, jotaiStore }: BootstrappedAppShellProps) {
normalizeOAuthCallbackUrl(clientConfig.hashRouter);
const jotaiStoreRef = useRef<ReturnType<typeof createStore>>();
if (!jotaiStoreRef.current) {
jotaiStoreRef.current = createStore();
bootstrapSettingsStore(jotaiStoreRef.current, clientConfig.settingsDefaults);
}
bootstrapSettingsStore(jotaiStore, clientConfig.settingsDefaults);
const router = useMemo(() => createRouter(clientConfig, screenSize), [clientConfig, screenSize]);
const reactQueryDevtoolsEnabled = isReactQueryDevtoolsEnabled();

return (
<QueryClientProvider client={queryClient}>
<JotaiProvider store={jotaiStoreRef.current}>
<JotaiProvider store={jotaiStore}>
<RouterProvider router={router} />
</JotaiProvider>
{reactQueryDevtoolsEnabled && (
Expand All @@ -68,13 +65,21 @@ function renderSentryErrorFallback({ error, eventId }: { error: unknown; eventId
function App() {
const screenSize = useScreenSize();
useCompositionEndTracking();
const jotaiStoreRef = useRef<ReturnType<typeof createStore>>();
if (!jotaiStoreRef.current) {
jotaiStoreRef.current = createStore();
}

const renderConfiguredApp = useCallback(
(clientConfig: ClientConfig) => {
setMatrixToBase(clientConfig.matrixToBaseUrl);
return (
<ClientConfigProvider value={clientConfig}>
<BootstrappedAppShell clientConfig={clientConfig} screenSize={screenSize} />
<BootstrappedAppShell
clientConfig={clientConfig}
screenSize={screenSize}
jotaiStore={jotaiStoreRef.current!}
/>
</ClientConfigProvider>
);
},
Expand All @@ -83,7 +88,11 @@ function App() {

return (
<Sentry.ErrorBoundary fallback={renderSentryErrorFallback}>
<AppShell screenSize={screenSize} queryClient={queryClient}>
<AppShell
screenSize={screenSize}
queryClient={queryClient}
jotaiStore={jotaiStoreRef.current}
>
<FeatureCheck>
<ClientConfigLoader>{renderConfiguredApp}</ClientConfigLoader>
</FeatureCheck>
Expand Down
4 changes: 3 additions & 1 deletion src/app/styles/edgeToEdgeInsets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ describe('android edge-to-edge inset contract', () => {
const systemBarShell = readWorkspaceFile('src/app/components/app-shell/SystemBarShell.tsx');

expect(indexHtml).not.toContain('id="portalContainer"');
expect(appTsx).toContain('<AppShell screenSize={screenSize} queryClient={queryClient}>');
expect(appTsx).toContain('<AppShell');
expect(appTsx).toContain('screenSize={screenSize}');
expect(appTsx).toContain('queryClient={queryClient}');
expect(appShell).toContain('const [portalContainer, setPortalContainer] = useState');
expect(appShell).toContain('<SystemBarShell onPortalContainerChange={setPortalContainer}>');
expect(systemBarShell).toContain('ref={onPortalContainerChange}');
Expand Down
Loading