-
Notifications
You must be signed in to change notification settings - Fork 280
fix(harmony): cache buildTime and packageVersion to prevent thread-safety sync errors #590
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| function requireConfigPlugins() { | ||
| try { | ||
| return require("@expo/config-plugins"); | ||
| } catch { | ||
| return require(require.resolve("@expo/config-plugins", { | ||
| paths: [process.cwd()], | ||
| })); | ||
| } | ||
| } | ||
|
|
||
| const { withDangerousMod } = requireConfigPlugins(); | ||
|
|
||
| const RCT_BRIDGE_IMPORT = "#import <React/RCTBridge.h>"; | ||
|
|
||
| function withPushyRCTBridgeImport(config) { | ||
| return withDangerousMod(config, [ | ||
| "ios", | ||
| (config) => { | ||
| const { platformProjectRoot, projectName } = config.modRequest; | ||
| const bridgingHeaderPath = path.join( | ||
| platformProjectRoot, | ||
| projectName, | ||
| `${projectName}-Bridging-Header.h` | ||
| ); | ||
|
|
||
| const contents = fs.readFileSync(bridgingHeaderPath, "utf8"); | ||
|
|
||
| if (!contents.includes(RCT_BRIDGE_IMPORT)) { | ||
| fs.writeFileSync( | ||
| bridgingHeaderPath, | ||
| `${contents.trimEnd()}\n\n${RCT_BRIDGE_IMPORT}\n` | ||
| ); | ||
| } | ||
|
|
||
| return config; | ||
| }, | ||
| ]); | ||
| } | ||
|
|
||
| module.exports = withPushyRCTBridgeImport; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ export class UpdateContext { | |
| private static DEBUG: boolean = false; | ||
| private static isUsingBundleUrl: boolean = false; | ||
| private static ignoreRollback: boolean = false; | ||
| private static cachedPackageVersion: string = ''; | ||
| private static cachedBuildTime: string = ''; | ||
|
Comment on lines
+29
to
+30
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. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift This still allows the first background-thread read to hit the unsafe sync APIs. The cache is only populated lazily, so if the first Also applies to: 65-78, 80-96 🤖 Prompt for AI Agents |
||
|
|
||
| constructor(context: common.UIAbilityContext) { | ||
| this.context = context; | ||
|
|
@@ -60,28 +62,38 @@ export class UpdateContext { | |
| } | ||
|
|
||
| public getPackageVersion(): string { | ||
| if (UpdateContext.cachedPackageVersion) { | ||
| return UpdateContext.cachedPackageVersion; | ||
| } | ||
| try { | ||
| const bundleInfo = bundleManager.getBundleInfoForSelfSync( | ||
| this.getBundleFlags(), | ||
| ); | ||
| return bundleInfo?.versionName || 'Unknown'; | ||
| UpdateContext.cachedPackageVersion = bundleInfo?.versionName || 'Unknown'; | ||
| return UpdateContext.cachedPackageVersion; | ||
| } catch (error) { | ||
| console.error('Failed to get bundle info:', error); | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| public getBuildTime(): string { | ||
| if (UpdateContext.cachedBuildTime) { | ||
| return UpdateContext.cachedBuildTime; | ||
| } | ||
| try { | ||
| const content = | ||
| this.context.resourceManager.getRawFileContentSync('meta.json'); | ||
| const metaData = JSON.parse( | ||
| new util.TextDecoder().decodeToString(content), | ||
| ) as Record<string, string | number | boolean | null | undefined>; | ||
| if (metaData.pushy_build_time) { | ||
| return String(metaData.pushy_build_time); | ||
| UpdateContext.cachedBuildTime = String(metaData.pushy_build_time); | ||
| return UpdateContext.cachedBuildTime; | ||
| } | ||
| } catch {} | ||
| } catch (error) { | ||
| console.error('Failed to read build time from raw file:', error); | ||
| } | ||
| return ''; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,5 +100,4 @@ log('bootup status', { | |
| isFirstTimeDebug, | ||
| isDebugChannel, | ||
| cInfo, | ||
| uuid, | ||
| }); | ||
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Point the plugin entry at the file added in this PR.
app.plugin.jsis added at the repo root, but Line 30 registers./plugins/with-rct-bridge-bridging-header. Unless another file exists at that exact path, Expo will fail to resolve the plugin and the bridging-header patch never runs.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents