Skip to content
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

Reduce bundle size #303

Merged
merged 4 commits into from
Dec 16, 2024
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
7 changes: 7 additions & 0 deletions .changeset/hip-beans-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@quiltt/react": patch
"@quiltt/core": patch
"@quiltt/react-native": patch
---

Reduce bundle size
6 changes: 5 additions & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

`@quiltt/react` provides React Components and Hooks for integrating Quiltt into React-based applications.

See the guides [here](https://www.quiltt.dev/connector/sdks/react).

## Installation

```shell
Expand Down Expand Up @@ -100,7 +102,9 @@ A provider component for passing Session and settings down to the rest of your a
import { QuilttProvider } from '@quiltt/react'

const Layout = ({ children }) => {
return <QuilttProvider token="{SESSION_TOKEN}">{children}</QuilttProvider>
const sessionToken = "<SESSION_TOKEN_FROM_SERVER>"

return <QuilttProvider token={sessionToken}>{children}</QuilttProvider>
}

export default Layout
Expand Down
19 changes: 12 additions & 7 deletions packages/react/src/providers/QuilttAuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import type { FC, PropsWithChildren } from 'react'
import { useEffect } from 'react'
import { useEffect, useMemo } from 'react'

import { ApolloProvider } from '@apollo/client'
import { InMemoryCache, QuilttClient } from '@quiltt/core'
Expand All @@ -12,10 +12,6 @@ type QuilttAuthProviderProps = PropsWithChildren & {
token?: string
}

export const GraphQLClient = new QuilttClient({
cache: new InMemoryCache(),
})

/**
* If a token is provided, will validate the token against the api and then import
* it into trusted storage. While this process is happening, the component is put
Expand All @@ -26,6 +22,15 @@ export const GraphQLClient = new QuilttClient({
export const QuilttAuthProvider: FC<QuilttAuthProviderProps> = ({ token, children }) => {
const { session, importSession } = useQuilttSession()

// @todo: extract into a provider so it can accessed by child components
const graphQLClient = useMemo(
() =>
new QuilttClient({
cache: new InMemoryCache(),
}),
[]
)

// Import passed in token
useEffect(() => {
if (token) importSession(token)
Expand All @@ -34,10 +39,10 @@ export const QuilttAuthProvider: FC<QuilttAuthProviderProps> = ({ token, childre
// Reset Client Store when logging in or out
// biome-ignore lint/correctness/useExhaustiveDependencies: We should reset the store whenever the session changes
useEffect(() => {
GraphQLClient.resetStore()
graphQLClient.resetStore()
}, [session])

return <ApolloProvider client={GraphQLClient}>{children}</ApolloProvider>
return <ApolloProvider client={graphQLClient}>{children}</ApolloProvider>
}

export default QuilttAuthProvider
Loading