Skip to content

resolve frontend rendering issue#1671

Open
huongcodecb1992 wants to merge 6 commits into
masterfrom
fix/map-display-error
Open

resolve frontend rendering issue#1671
huongcodecb1992 wants to merge 6 commits into
masterfrom
fix/map-display-error

Conversation

@huongcodecb1992

Copy link
Copy Markdown
Contributor

No description provided.

@huongcodecb1992 huongcodecb1992 requested a review from rilwis May 12, 2026 02:05
@opencode-agent

Copy link
Copy Markdown

Based on my review of the PR changes, here are the issues I found:

Issues

1. location.protocol Reference Error (Bug)

File: js/map.js:80

if ( location.protocol.includes( 'https' ) && navigator.geolocation ) {

location is a parameter from the getCurrentPosition callback that shadows the global window.location object. The callback receives a GeolocationPosition object, which doesn't have a protocol property. This will cause a runtime error and prevent geolocation from ever working.

Fix: Rename the callback parameter to position to avoid shadowing window.location.


2. marker Undefined in Info Window Handler (Bug)

File: js/map-frontend.js:81

marker.addEventListener( 'gmp-click', function () {

If options.marker is false, the marker variable is never declared, causing a ReferenceError when the code tries to attach the event listener for info_window.

Fix: Wrap the info window block inside the if ( options.marker ) block, or add a null check.


3. Invalid Property gmpClickable on AdvancedMarkerElement

File: js/map-frontend.js:68-69

if ( options.info_window ) {
    markerOptions.gmpClickable = true;
}

gmpClickable is not a valid option for AdvancedMarkerElement. Advanced markers are clickable by default. This property does nothing and may cause unexpected behavior or be ignored.

Fix: Remove gmpClickable or conditionally add event listeners only when needed.


4. Redundant/Incorrect MapId Fallback

File: js/map-frontend.js:42-44

if ( mapOptions.mapId === undefined && options.map_id ) {
    mapOptions.mapId = options.map_id;
}

mapOptions.mapId was just checked for undefined, but its value was already set from options.js_options which comes from $args['js_options'] in PHP. This fallback doesn't properly handle the case where options.map_id (from $args['map_id']) should override the js_options version.

Fix: Simplify to if ( options.map_id ) { mapOptions.mapId = options.map_id; }.


5. Marker Position Access Before Initialization

File: js/map.js:122-124

google.maps.event.addListener( this.map, 'zoom_changed', function ( event ) {
    var pos = that.marker.position;

this.marker may be undefined if setCenter() was never called (e.g., no saved coordinate and no address field). Accessing .position on undefined throws an error.

Fix: Add a null check: if ( !that.marker ) return;


6. AutocompleteService Variable Declared But Never Used

File: js/map.js:10 (removed)

The code removed the instantiation var autocomplete = new google.maps.places.AutocompleteService(); but the variable reference might be expected elsewhere. Verify no other code depends on this variable.

New%20session%20-%202026-05-12T02%3A05%3A53.836Z
opencode session  |  github run

Comment thread inc/fields/map.php
'info_window' => '', // Content of info window (when click on marker). HTML allowed.
'js_options' => [],
'zoom' => $zoom,
'map_id' => 'DEMO_MAP_ID',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sao lại để là DEMO_MAP_ID? Phải là 1 ID unique được generate tự động chứ?

Comment thread js/map.js Outdated
position: location,
map: this.map,
draggable: this.$canvas.data( 'marker_draggable' ),
gmpDraggable: this.$canvas.data( 'marker_draggable' ) === 'true' || this.$canvas.data( 'marker_draggable' ) === true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Có cần phải check true hay 'true' ko? Vì jQuery.data() tự convert sang boolean rồi. Nếu ko thì làm tương tự như cũ nhé.

Comment thread js/map.js Outdated

initMapElements: function () {
this.map = new google.maps.Map( this.canvas, {
var mapOptions = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dùng let, const, không dùng var.

@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 26, 2026
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 26, 2026
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 26, 2026
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 26, 2026
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 26, 2026
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 27, 2026
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 27, 2026
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 27, 2026
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot May 27, 2026
@opencode-agent

Copy link
Copy Markdown

opencode session  |  github run

@opencode-agent

Copy link
Copy Markdown

User opencode-agent[bot] does not have write permissions

github run

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.

2 participants