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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle low cli-app-scripts version #1349

Merged
merged 5 commits into from
Dec 14, 2023

Conversation

KaiVandivier
Copy link
Contributor

@KaiVandivier KaiVandivier commented May 10, 2023

Implements LIBS-501

Description

With the connection status changes in 3.9.0, I inadvertently created a dependency in PWA apps on @dhis2/cli-app-scripts > 10.3.0 -- if an app fits these kinda specific circumstances, it will get an error:

  1. PWA is enabled
  2. @dhis2/app-runtime >= 3.9.0
  3. @dhis2/cli-app-scripts between 10.0.0 and 10.3.0,

The circumstance is pretty narrow... but it could happen to the Data Entry app right now if it upgraded @dhis2/app-runtime to take advantage of the daylight savings timezone fix 馃槵

The changes in this PR handle these missing cli-app-scripts features in versions below 10.3.0 to avoid a breaking change in app-runtime for PWA apps (apps not using PWA won't use the connection status):

  • offlineInterface.latestIsConnected
  • offlineInterface.subscribeToDhis2ConnectionStatus

There's also a small (but I think important) fix for fail-safe logic to prevent app UI from being blocked in case something else fails

Known issues

  • In PWA apps with cli-app-scripts < 10.3.0, since the header bar doesn't yet use the connection status in the header bar, there might be pings sent even though there are no consumers of the hook
  • In that scenario, pings would be sent more often because the service worker isn't providing updates to the status

I believe these two drawbacks are both unlikely and non-breaking which makes them non-ideal but tolerable. The console warning advises upgrading cli-app-scripts versions to improve on those two points

Testing

Here's how I tested this:

  1. In the app-platform repo, I checked out the v10.2.3 tag (and ran yarn I think)
  2. Back in app-runtime, I built the @dhis2/app-service-offline package
  3. I dropped the new build dir into the node_modules in the root of the app-platform dir (<app-runtime>/services/offline/build => <app-platform>/node_modules/@dhis2/app-service-offline/build)
  4. I deleted the examples/pwa-app/.d2/shell/node_modules/.cache dir
  5. Then I ran the PWA example app in app-platform to verify that it doesn't crash (yarn workspace pwa-app start)

Screenshots

Before:
The PWA app in the app-platform repo @ v10.2.3 tag, with @dhis2/app-runtime at 3.9.0 in the app-shell:

before

After:
Same conditions, after building app-service-offline from @dhis2/app-runtime from this branch and manually adding it to the node_modules in the app-platform repo:

after

@KaiVandivier KaiVandivier requested a review from a team May 10, 2023 15:11
Comment on lines -186 to +204
const contextValue = useMemo(
() => ({
// in the unlikely circumstance that offlineInterface.latestIsConnected
// is `null` when this initializes, fail safe by defaulting to
// `isConnected: false`
isConnected: Boolean(isConnected),
isDisconnected: !isConnected,
lastConnected: isConnected
const contextValue = useMemo(() => {
// in the unlikely circumstance that offlineInterface.latestIsConnected
// is `null` or `undefined` when this initializes, fail safe by defaulting to
// `isConnected: true`. A ping or SW update should update the status shortly.
const validatedIsConnected = isConnected ?? true
return {
isConnected: validatedIsConnected,
isDisconnected: !validatedIsConnected,
lastConnected: validatedIsConnected
Copy link
Contributor Author

@KaiVandivier KaiVandivier Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small fix: the correct fail-safe should be to default to isConnected: true so the app can be accessed (the UI might be blocked or changed if isConnected === false)

Comment on lines +177 to +186
if (!offlineInterface.subscribeToDhis2ConnectionStatus) {
// Missing this functionality from the offline interface --
// use a ping on startup to get the status
smartIntervalRef.current?.invokeCallbackImmediately()
console.warn(
'Please upgrade to @dhis2/cli-app-scripts@>10.3.8 for full connection status features'
)
return
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit protects against the compatibility error

Comment on lines -158 to +160
expect(result.current.isConnected).toBe(false)
expect(result.current.isDisconnected).toBe(true)
expect(result.current.lastConnected).toEqual(testCurrentDate)
expect(result.current.isConnected).toBe(true)
expect(result.current.isDisconnected).toBe(false)
expect(result.current.lastConnected).toBe(null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the fix to the fail-safe below

@KaiVandivier KaiVandivier enabled auto-merge (squash) December 14, 2023 11:22
@KaiVandivier KaiVandivier merged commit d15bce1 into master Dec 14, 2023
9 checks passed
@KaiVandivier KaiVandivier deleted the libs-501-fix-pwa-regression branch December 14, 2023 11:27
dhis2-bot added a commit that referenced this pull request Dec 14, 2023
## [3.10.1](v3.10.0...v3.10.1) (2023-12-14)

### Bug Fixes

* handle low cli-app-scripts version [LIBS-501] ([#1349](#1349)) ([d15bce1](d15bce1))
@dhis2-bot
Copy link
Contributor

馃帀 This PR is included in version 3.10.1 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants