fix(navigation): load AMap JS SDK for Autocomplete search#304
fix(navigation): load AMap JS SDK for Autocomplete search#304conversun wants to merge 1 commit intoFrogAi:FrogPilotfrom
Conversation
|
Please submit your pull request to the "MAKE-PRS-HERE" branch. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23abff043e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| securityJsCode: state.amap2Key | ||
| }; | ||
|
|
||
| amapLoadPromise = AMapLoader.load({ |
There was a problem hiding this comment.
Handle missing AMapLoader before calling load
If https://webapi.amap.com/loader.js fails to load (e.g., offline device, CDN blocked, or strict CSP), AMapLoader is undefined here and this statement throws a ReferenceError before the promise .catch() can run. In that case both AMap search paths fail with an uncaught error and users never see the intended snackbar fallback, so the new error handling does not actually cover this common failure mode.
Useful? React with 👍 / 👎.
Summary
The AMap (高德地图) JavaScript SDK is referenced in the navigation search code but was never loaded, causing
ReferenceError: AMap is not definedwhen users toggle to the AMap search provider.Bug
navigation_destination.jscallsnew AMap.Autocomplete()in two places (handleSearchKeyandsearchInput) but the AMap JS SDK is never loaded — neither statically inindex.htmlnor dynamically in JavaScript. This means AMap-based destination search is completely broken.Fix
index.html(+1 line):<script src="https://webapi.amap.com/loader.js"></script>to load the AMap JSAPI Loadernavigation_destination.js(+42 lines):ensureAMapLoaded()lazy-load singleton function that:window._AMapSecurityConfigwith the user's security key (AMapKey2)AMapLoader.load()with the user's API key (AMapKey1), version2.0, andAMap.AutocompletepluginshowSnackbar()feedbackhandleSearchKeyandsearchInput) toawait ensureAMapLoaded()before creatingAutocompleteinstancesTesting