[Bug] Prop `style` does not unset properties that become `undefined`

オープン
#2,595 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

@MohammadYusif がすでに取り組んでいます。

2026年7月14日 から。

  • #2596 @MohammadYusif による — オープン
  • #2601 @chrisgervang による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
66/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
react, typescript
領域
frontend

調査の方向性

Marker コンポーネントのエントリーポイントから始め、更新時にその style prop がどのように適用されるかを追跡します。リンクされた CodeSandbox の再現を実行し、その後、定義済みの background から undefined または空のオブジェクトへの遷移がないか、style の更新経路を調べます。条件が false に変わったときに background 属性が削除されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug
Description

In the following snippet:

<MapGLMarker
        latitude={location.coordinates.latitude}
        longitude={location.coordinates.longitude}
        anchor="bottom"
        style={{
          ...(condition
            ? { background: 'red', }
            : { background: undefined, }), // Note: similar problem if just passing {}
        }}
      >
Expected Behavior

When condition goes from true to false, the background attribute is un-set on the element.

Steps to Reproduce

Reproduction: https://codesandbox.io/p/sandbox/long-rgb-6f4mdv

Code snippet
import * as React from "react";
import { createRoot } from "react-dom/client";
import Map, { Marker } from "react-map-gl";

import "mapbox-gl/dist/mapbox-gl.css";

function Root() {
  const [state, setState] = React.useState(false);
  return (
    <>
      <button onClick={() => setState(!state)}>
        background: {state ? "on" : "off"}
      </button>
      <Map
        initialViewState={{
          latitude: 37.8,
          longitude: -122.4,
          zoom: 14,
        }}
        style={{ width: "100vw", height: "100vh" }}
        mapStyle="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json"
      >
        <Marker
          longitude={-122.4}
          latitude={37.8}
          style={{
            ...(state ? { background: "red" } : { background: undefined }), // Note: similar problem if just passing {}
          }}
        />
      </Map>
    </>
  );
}

/* global document */
createRoot(document.getElementById("app")).render(<Root />);
Environment
Logs

No logging produced

主要言語
TypeScript
スター
8.5k
フォーク
1.3k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

visgl/react-map-gl のほかの issue

visgl/react-map-gl の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。