fix: insert setupBackgroundObservers into multi-line didFinishLaunchingWithOptions - #372
Open
the-woody-kim wants to merge 1 commit into
Open
Conversation
…ngWithOptions
The AppDelegate match used `.+`, which does not cross newlines. Expo SDK 54+
templates spread the didFinishLaunchingWithOptions signature over several
lines, so the match failed and String.replace returned the contents unchanged
-- silently, while the import HealthKit insert above it still succeeded.
Match with [^{]* instead: it spans newlines, and refusing to cross a brace
keeps it from running out of an earlier application(...) overload into this
one. Warn when the insert finds no match rather than failing silently.
🦋 Changeset detectedLatest commit: d6d7de5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
|
Running this in Expo 54, I'm getting the following error when building my app: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
withAppDelegatePlugininsertsBackgroundDeliveryManager.shared.setupBackgroundObservers()by matching:/(func application\(.+didFinishLaunchingWithOptions.+\{)\n/.doesn't match newlines, so this only works when the whole signature is on one line. Expo SDK 54+ generates a multi-line AppDelegate:The match fails,
String.replacereturns the contents unchanged, and the setup call is never inserted.It fails silently, which is what makes it expensive.
String.replacedoesn't throw on no-match, theimport HealthKitinsert immediately above it still succeeds, and the entitlement and Info.plist plugins still apply — soprebuildsucceeds, the AppDelegate is visibly modified, and the entitlements are correct. Everything looks configured.The runtime symptom is subtle too:
subscribeToChangesstill registers its own observer, so background delivery appears to work while the app is alive. It just never survives termination, since no observer is registered at launch. That's a long way from this regex.The fix
Match with
[^{]*instead of.+. It spans newlines, and refusing to cross a{also keeps the match from running out of an earlierapplication(...)overload into this one — the SDK 57 template has threefunc application(methods.Also
console.warnwhen the insert finds no match, so the next template change surfaces at prebuild instead of as missing background updates weeks later.Verification
Against two fixtures, where the multi-line one deliberately places an
application(_:open:options:)overload beforedidFinishLaunchingWithOptionsto confirm the match can't span into it:So this fixes SDK 54+ without regressing the older single-line template.
Context
Follow-up to #365. @nopitown reported there that background updates stop arriving after a few deliveries on Expo — on a managed project this is at least one contributing cause, since without the launch-time registration only the observers created at runtime by
subscribeToChangesexist, and those die with the process.Biome passes on the changed file. Changeset included as a patch bump.