Skip to content

Commit

Permalink
chore: Debug AetherPage SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
codinsonn committed Jan 11, 2024
1 parent 3a870b8 commit 4bad170
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 27 deletions.
10 changes: 5 additions & 5 deletions apps/next/app/ClientRootLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ const NextClientRootLayout = (props: { children: React.ReactNode }) => {
const { children } = props

// Auth
const { getToken } = useAuth()
// const { getToken } = useAuth()

// -- Fonts --

useLoadFonts()

// -- Effects --

useEffect(() => {
setGlobal('getAuthToken', getToken)
}, [getToken])
// useEffect(() => {
// setGlobal('getAuthToken', getToken)
// }, [getToken])

// -- Render --

Expand All @@ -48,7 +48,7 @@ const NextClientRootLayout = (props: { children: React.ReactNode }) => {
assets={{}}
icons={{}}
twConfig={tailwindConfig}
getAuthToken={getToken}
// getAuthToken={getToken}
isAppDir
isNextJS
>
Expand Down
16 changes: 15 additions & 1 deletion apps/next/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const nextConfig = {
images: {
domains: ['i3.ytimg.com'],
},
webpack: (config, { isServer }) => {
webpack: (config, { dev, isServer }) => {
// -i- Run aetherspace automation scripts in DEV mode
if (!isServer && process.env.NODE_ENV === 'development') withAutomation()
// Enable top level await in API handlers
Expand All @@ -87,6 +87,20 @@ const nextConfig = {
config.plugins.push(new FilterWarningsPlugin({
exclude: [/the request of a dependency is an expression/],
}))
// Debug during build step?
if (!dev && !isServer) {
config.optimization.minimizer = config.optimization.minimizer.map(plugin => {
if (plugin.constructor.name === 'TerserPlugin') {
plugin.options.terserOptions = {
...plugin.options.terserOptions,
// Prevent discarding or mangling of console statements
compress: { ...plugin.options.terserOptions.compress, drop_console: false },
mangle: { ...plugin.options.terserOptions.mangle, reserved: ['console'] },
}
}
return plugin;
})
}
// Return config
return config
},
Expand Down
2 changes: 1 addition & 1 deletion features/app-core/routes/bio/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as bioScreen from 'links-page/screens/BioScreen'
import { userBioMock } from 'links-page/mocks/userBio.mock'

Expand Down
2 changes: 1 addition & 1 deletion features/app-core/routes/cv/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as ResumeScreen from 'cv-page/screens/ResumeScreen'
import { dummyResumeData } from 'cv-page/mocks/resumeData.mock'

Expand Down
2 changes: 1 addition & 1 deletion features/app-core/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as bioScreen from 'links-page/screens/BioScreen'
import { userBioMock } from 'links-page/mocks/userBio.mock'

Expand Down
8 changes: 4 additions & 4 deletions features/app-core/routes/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import React from 'react'
import ErrorBoundary from '../screens/ErrorBoundary'
import { View } from 'aetherspace/primitives'
import { AetherClerkProvider } from '@aetherspace/clerk-auth/context/ClerkProvider'
// import { AetherClerkProvider } from '@aetherspace/clerk-auth/context/ClerkProvider'

/* --- <RootLayout/> --------------------------------------------------------------------------- */

const RootLayout = ({ children }: { children: React.ReactNode }) => (
<ErrorBoundary>
<AetherClerkProvider>
<View tw="flex flex-col min-h-full w-full">{children}</View>
</AetherClerkProvider>
{/*<AetherClerkProvider>*/}
<View tw="flex flex-col min-h-full w-full">{children}</View>
{/*</AetherClerkProvider>*/}
</ErrorBoundary>
)

Expand Down
2 changes: 1 addition & 1 deletion features/app-core/routes/links/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as bioScreen from 'links-page/screens/BioScreen'
import { userBioMock } from 'links-page/mocks/userBio.mock'

Expand Down
2 changes: 1 addition & 1 deletion features/app-core/routes/resume/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as ResumeScreen from 'cv-page/screens/ResumeScreen'
import { dummyResumeData } from 'cv-page/mocks/resumeData.mock'

Expand Down
2 changes: 1 addition & 1 deletion features/cv-page/routes/cv/[slug]/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
// Navigation
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
// Screens
import * as UpdateResumeScreen from '../../../../screens/UpdateResumeScreen'

Expand Down
2 changes: 1 addition & 1 deletion features/cv-page/routes/cv/[slug]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
// Navigation
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
// Screens
import * as ResumeScreen from '../../../screens/ResumeScreen'

Expand Down
2 changes: 1 addition & 1 deletion features/cv-page/routes/resume/[slug]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as ResumeScreen from '../../../screens/ResumeScreen'

/* --- Config ---------------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion features/links-page/routes/bio/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
// Navigation
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
// Screens
import * as bioScreen from '../../screens/BioScreen'

Expand Down
2 changes: 1 addition & 1 deletion features/user-management/routes/me/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as UserInfoScreen from '../../screens/UserInfoScreen'

/* --- Config ---------------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion features/user-management/routes/sign-in/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as SignInScreen from '../../screens/SignInScreen'

/* --- Config ---------------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion features/user-management/routes/sign-up/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as signUpScreen from '../../screens/SignUpScreen'

/* --- Config ---------------------------------------------------------------------------------- */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Middleware } from 'swr'
import { getEnvList, getEnvVar, getGlobal, setGlobal } from 'aetherspace/utils'
import { AetherFetcherOptions } from 'aetherspace/navigation'
import type { AetherFetcherOptions } from 'aetherspace/navigation'
import axios from 'axios'

/** --- swrClerkAuthMiddleware() --------------------------------------------------------------- */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as {{screenName}} from '{{screenImportPath}}'

/* --- Config ---------------------------------------------------------------------------------- */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { AetherPage } from 'aetherspace/navigation'
import { AetherPage } from 'aetherspace/navigation/AetherPage'
import * as {{screenModuleName}} from '{{screenImportPath}}'

/* --- Config ---------------------------------------------------------------------------------- */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const AetherPage = <SC extends AetherScreenConfig>(props: AetherPageProps
const fallback = hydrationData ? { [fallbackKey]: hydrationData } : {}
const renderHydrationData = !!hydrationData && !hydratedData // Only render the hydration data if it's not already in state

console.warn('AetherPage (Client)', 1, { hydrationData })

return (
<SWRConfig value={{ use: [swrClerkAuthMiddleware], fallback }}>
{renderHydrationData && <div id="ssr-data" data-ssr={JSON.stringify(hydrationData)} />}
Expand All @@ -66,8 +68,12 @@ export const AetherPage = <SC extends AetherScreenConfig>(props: AetherPageProps

// -- Server --

console.warn('AetherPage (SSR)', 1)

const ssrData = use(getGraphqlData(graphqlQuery, { variables }))

console.warn('AetherPage (SSR)', 2, { ssrData })

return (
<SWRConfig value={{ use: [swrClerkAuthMiddleware], fallback: { [fallbackKey]: ssrData } }}>
{!!ssrData && <div id="ssr-data" data-ssr={JSON.stringify(ssrData)} />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useSearchParams } from 'expo-router'
// Types
import { RoutePropsType } from './useRouteParams.types'

/** --- useRouteParams() ----------------------------------------------------------------------- */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useSearchParams } from 'next/navigation'
// Types
import { RoutePropsType } from './useRouteParams.types'

/** --- useRouteParams() ----------------------------------------------------------------------- */
/** -i- Get the route params from the expo (mobile) or next (web) router */
export const useRouteParams = (props: Partial<RoutePropsType>) => {
const routeParams = props.params || {}
console.error('-!- useRouteParams(web) -!-', { routeParams })
const search = useSearchParams()
const searchParams = Object.fromEntries(search.entries())
const params = { ...routeParams, ...searchParams }
Expand Down

0 comments on commit 4bad170

Please sign in to comment.