Skip to content

fix:weather-api-current-compact invisible marker and API key resolution - #1736

Open
willum070 wants to merge 2 commits into
mainfrom
fix-weather-api-current-compact
Open

willum070 wants to merge 2 commits into
mainfrom
fix-weather-api-current-compact

Conversation

@willum070

Copy link
Copy Markdown
Collaborator

This PR fixes two critical issues with the weather-api-current-compact sample that were preventing the map and markers from loading correctly.

1. Fixed API Key Resolution (Vite Config)

The sample was previously bypassing the centralized Vite configuration by hardcoding its start script to vite --port 5173. Because it bypassed the config, the GOOGLE_MAPS_API_KEY placeholder string was never substituted for the local .env key, resulting in an InvalidKeyMapError.

  • Fix: Updated package.json to properly pipe through the workspace vite.config.js and strict TS compilation.

2. Fixed Invisible Markers (TypeScript Elision Bug)

Once strict TypeScript compilation was enabled, it revealed a hidden type error: SimpleWeatherWidget was being imported but was never exported from its definition file.
When fixing this type error by updating the import to a named import (import { SimpleWeatherWidget } from './simple-weather-widget'), a side-effect was triggered: because the class was only used for type annotations in index.ts, the TypeScript compiler optimized the code by completely eliding (erasing) the import statement from the compiled JS.
Because the import was erased, simple-weather-widget.js was never executed at runtime, the custom element was never registered with the browser, and the Maps API attached invisible, unstyled elements to the Advanced Markers.

  • Fix: Exported SimpleWeatherWidget and explicitly split the imports in index.ts to guarantee runtime registration:
    import './simple-weather-widget'; // Guarantees the component is registered at runtime
    import type { SimpleWeatherWidget } from './simple-weather-widget'; // Satisfies the TS compiler

Testing

  • Verified npm start successfully loads the map.
  • Verified clicking "Load Markers" successfully spawns functional weather widgets across the map.
  • Verified clicking the map dynamically spawns a new weather widget.

…esolve api key

Change-Id: I27b82bf399830383104708b67e310661b8a17f8f
…time

Change-Id: I74deb5c82f84ba7afa5d0c1181018332ecc3363f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant