fix: complete PowerPoint slide auto-detection#25
Conversation
getSelectedDataAsync(CoercionType.SlideRange) fails when the taskpane has focus, so it could never detect the current slide or total count. Replace with PowerPoint.run() + getSelectedSlides() (PowerPointApi 1.5) which works independently of keyboard focus. Also fixes slide count detection since PowerPoint.slides.items.length is always available. Legacy getSelectedDataAsync path kept as fallback for older Office builds that don't support PowerPointApi 1.5. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
isOfficeAvailable() checks Office.context which may not be set up yet when the useEffect fires. This caused officeDetected=false and the bridge was never initialized even inside PowerPoint. Fix: check only typeof Office !== "undefined" (script loaded) before calling initOfficeBridge. officeDetected is now set after Office.onReady resolves, which is the correct time to know we are truly in PowerPoint. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughModified PowerPoint add-in detection and bridge logic: replaced prior Office availability gating with direct global Office presence checks, changed bridge initialization to reflect sync capability, added modern PowerPoint.run path with legacy Office API fallback, adjusted polling/debounce timings, and tightened lifecycle teardown. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as PowerPointAddinClient
participant Bridge as officeBridge
participant ModernAPI as PowerPoint.run
participant LegacyAPI as Office API
Client->>Bridge: initOfficeBridge(callbacks)
activate Bridge
Bridge->>Bridge: isPowerPointApiAvailable()?
alt modern API available
Bridge->>ModernAPI: PowerPoint.run(context => getSelectedSlides())
activate ModernAPI
ModernAPI-->>Bridge: selected slide id(s) & slides list
deactivate ModernAPI
Bridge->>Bridge: map slide id -> slideNumber
else fallback
Bridge->>LegacyAPI: getSelectedDataAsync(SlideRange)
activate LegacyAPI
LegacyAPI-->>Bridge: slide range data
LegacyAPI->>LegacyAPI: getSlideCountAsync() (optional)
deactivate LegacyAPI
Bridge->>Bridge: build slide info from legacy data
end
Bridge-->>Client: resolve SyncCapability (mode)
deactivate Bridge
Client->>Client: set officeDetected = (mode !== "manual_only")
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
typeof Office causes a TS error in files without declare const Office. Use typeof (globalThis as any).Office instead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Greptile SummaryThis PR fixes two related issues with PowerPoint slide auto-detection in the Office Add-in: (1) a timing problem where
Confidence Score: 3/5The PR partially fixes the Office.js timing race but leaves the root guard inside initOfficeBridge unchanged, meaning the bug can still reproduce. The component-level guard change and the new PowerPoint.run/getSelectedSlides primary path are sound improvements. However, initOfficeBridge still calls isOfficeAvailable() (requiring Office.context) before Office.onReady(), which means the stated fix for the timing race can still be defeated in the exact scenario described in the PR. That one-line change on line 44 is the critical missing piece. apps/web/src/lib/powerpoint/officeBridge.ts line 44 — the isOfficeAvailable() guard in initOfficeBridge must be replaced with typeof Office === undefined to complete the timing fix. Important Files Changed
Sequence DiagramsequenceDiagram
participant Component as PowerPointAddinClient
participant Bridge as officeBridge.ts
participant Office as Office.js Runtime
Component->>Component: useEffect fires
Component->>Component: typeof Office !== undefined? Yes
Component->>Bridge: initOfficeBridge(callbacks)
Bridge->>Bridge: isOfficeAvailable()? checks Office.context too
alt Office.context still undefined
Bridge-->>Component: resolve(manual_only) bug not fully fixed
else Office.context already defined
Bridge->>Office: Office.onReady()
Office-->>Bridge: host PowerPoint
Bridge->>Bridge: isInitialized = true
Bridge->>Bridge: syncCurrentSlide + startPolling
Bridge->>Office: addHandlerAsync DocumentSelectionChanged
Office-->>Bridge: success
Bridge-->>Component: resolve(auto)
Component->>Component: setOfficeDetected(true)
end
loop Poll every 800ms
Bridge->>Office: PowerPoint.run getSelectedSlides
alt API available
Office-->>Bridge: slide ids
Bridge->>Component: onSlideChange
else Fallback
Bridge->>Office: getSelectedDataAsync
Office-->>Bridge: slide index
Bridge->>Office: getSlideCountAsync
Office-->>Bridge: totalSlides
Bridge->>Component: onSlideChange
end
end
Component->>Bridge: destroyOfficeBridge
Bridge->>Bridge: clearInterval + clearTimeout
Bridge->>Office: removeHandlerAsync
Bridge->>Bridge: isInitialized = false
|
Probleme & Fixes
1. Office.js Timing-Bug (Hauptursache)
isOfficeAvailable()prüftOffice.context— das war nochundefinedwenn deruseEffectlief. Dadurch wurdeofficeDetected = falsegesetzt undinitOfficeBridgenie aufgerufen, obwohl das Add-in in PowerPoint geöffnet war.Fix: Nur
typeof Office !== "undefined"prüfen (Script geladen?), danninitOfficeBridgeaufrufen.officeDetectedwird erst nachOffice.onReady()gesetzt — der einzige Zeitpunkt, wo sicher feststeht, dass wir wirklich in PowerPoint sind.2.
getSelectedDataAsyncfunktioniert nicht im TaskpaneDie alte API schlägt fehl, wenn der Taskpane-Fokus aktiv ist.
Fix:
PowerPoint.run()+getSelectedSlides()(PowerPointApi 1.5) als primäre Methode — fokusunabhängig. Legacy-API als Fallback.Ergebnis
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes