-
Notifications
You must be signed in to change notification settings - Fork 12
expo-refresh #189
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
base: main
Are you sure you want to change the base?
expo-refresh #189
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| "expo-superwall": patch | ||
| --- | ||
|
|
||
| Refresh Superwall configuration automatically for the hooks SDK after Metro/Fast Refresh in development, so dashboard config updates can be picked up without a full app restart. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,11 @@ export function SuperwallProvider({ | |
| onConfigurationError, | ||
| }: SuperwallProviderProps) { | ||
| const deepLinkEventHandlerRef = useRef<EmitterSubscription>(null) | ||
| const hasObservedConfiguredRef = useRef(false) | ||
| const refreshStateRef = useRef({ | ||
| isLoading: false, | ||
| configurationError: null as string | null, | ||
| }) | ||
| const isUsingCustomPurchaseController = !!useCustomPurchaseController() | ||
|
|
||
| // Handle onBackPressed callback from options | ||
|
|
@@ -95,6 +100,11 @@ export function SuperwallProvider({ | |
| })), | ||
| ) | ||
|
|
||
| refreshStateRef.current = { | ||
| isLoading, | ||
| configurationError, | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| if (!isConfigured && !isLoading && !configurationError) { | ||
| const apiKey = apiKeys[Platform.OS as keyof typeof apiKeys] | ||
|
|
@@ -124,6 +134,23 @@ export function SuperwallProvider({ | |
| configure, | ||
| ]) | ||
|
|
||
| useEffect(() => { | ||
| const { isLoading, configurationError } = refreshStateRef.current | ||
|
|
||
| if (!__DEV__ || !isConfigured || isLoading || configurationError) { | ||
| return | ||
| } | ||
|
|
||
| if (!hasObservedConfiguredRef.current) { | ||
| hasObservedConfiguredRef.current = true | ||
| return | ||
| } | ||
|
|
||
| SuperwallExpoModule.refreshConfiguration().catch((error) => { | ||
| console.error("[Superwall] Failed to refresh configuration after Metro refresh", error) | ||
| }) | ||
| }, [isConfigured]) | ||
|
Comment on lines
+137
to
+152
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A safer alternative is to also depend on useEffect(() => {
if (!__DEV__ || !isConfigured || isLoading || configurationError) {
return
}
if (!hasObservedConfiguredRef.current) {
hasObservedConfiguredRef.current = true
return
}
SuperwallExpoModule.refreshConfiguration().catch((error) => {
console.error("[Superwall] Failed to refresh configuration after Metro refresh", error)
})
}, [isConfigured, isLoading, configurationError])The Prompt To Fix With AIThis is a comment left during a code review.
Path: src/SuperwallProvider.tsx
Line: 137-152
Comment:
**Refresh can be silently skipped when `isLoading` lags behind `isConfigured`**
`isLoading` and `configurationError` are read from `refreshStateRef.current` inside an effect that only depends on `[isConfigured]`. If the store emits `isConfigured = true` in one render and then clears `isLoading` in a subsequent render (i.e. the two state updates are not batched), the effect runs while `isLoading` is still `true` and exits early — the refresh is never attempted, with no log or retry. This is an edge case, but Metro-refresh timing makes it more likely than typical usage.
A safer alternative is to also depend on `isLoading` and `configurationError` directly:
```ts
useEffect(() => {
if (!__DEV__ || !isConfigured || isLoading || configurationError) {
return
}
if (!hasObservedConfiguredRef.current) {
hasObservedConfiguredRef.current = true
return
}
SuperwallExpoModule.refreshConfiguration().catch((error) => {
console.error("[Superwall] Failed to refresh configuration after Metro refresh", error)
})
}, [isConfigured, isLoading, configurationError])
```
The `hasObservedConfiguredRef` already prevents spurious calls, so the extra dependencies don't add refresh invocations — they only ensure the effect re-evaluates when `isLoading` or the error clears after `isConfigured` is set.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| // Notify callback when configuration error changes | ||
| useEffect(() => { | ||
| if (configurationError && onConfigurationError) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The completion closure only ever calls
promise.resolve(nil), so any internal failure inSuperwall.shared.refreshConfigurationis silently swallowed on iOS. The Android counterpart wraps the call intry/catchand callspromise.reject(CodedException(error))on failure. While the TypeScript caller currently uses.catch()for Metro-refresh, future callers awaitingrefreshConfiguration()would receive a resolved promise even when the SDK failed on iOS. Consider adding error propagation — if the SuperwallKit closure provides anError?parameter, reject there; otherwise wrap the call in ado/catch.Prompt To Fix With AI