railmapgen / rmp

Design your own rail map by freely dragging stations from different cities and connecting them with 135-degree rounded corners or perpendicular lines!
https://railmapgen.org/?app=rmp
GNU General Public License v3.0
93 stars 18 forks source link

Accidentally change the previous color #473

Open thekingofcity opened 11 months ago

thekingofcity commented 11 months ago

Colors of previous open unchanged color fields will be changed after confirmation.

Reproduce steps:

  1. Click on any element that has a color field input.
  2. Click the color field at the top of the left tools panel.
  3. Close the panel without any interaction.
  4. Click the color field in the details panel.
  5. Select a color and confirm.
  6. Note both color in the tools and details panel changed.
langonginc commented 8 months ago

I found the reason.

https://github.com/railmapgen/rmp/blob/fa207eaea4b38982a53c932ce81bf123ae8705f2/src/redux/runtime/runtime-slice.ts#L105-L115

In Runtime-slice.ts, when we open palette App Clip and change the color, it will trigger onPaletteAppClipEmit() and change the key of output .

But, when we open palette app clip without any change, it will trigger closePaletteAppClip() and the key of output won't be changed.

In tools.tsx,

https://github.com/railmapgen/rmp/blob/fa207eaea4b38982a53c932ce81bf123ae8705f2/src/components/panels/tools/tools.tsx#L69-L74

The problem comes out here. When you open the app clip, isThemeRequested is set to true. When you close the app clip without any changes, the output do NOT be changed, so this function won't be run, and isThemeRequested is still true.

If you open app clip from other place and pick up a color after that, the output is changed and the function is run and set the wrong key to runtime.theme.

To sum up, we should identify who call the app clip and pass the key ONLY to it.

And also set isThemeRequested back to false on time to avoid receiving the key not for itself.

langonginc commented 8 months ago

Colors of previous open unchanged color fields will be changed after confirmation.

Reproduce steps:

  1. Click on any element that has a color field input.
  2. Click the color field at the top of the left tools panel.
  3. Close the panel without any interaction.
  4. Click the color field in the details panel.
  5. Select a color and confirm.
  6. Note both color in the tools and details panel changed.

In fact, if we swap the step 2 and step 4, the color in details panel will be accidentally changed too.