anse icon indicating copy to clipboard operation
anse copied to clipboard

`requestWithBackend` always defaults to `true`, not as expected

Open CNSeniorious000 opened this issue 1 year ago • 0 comments

How is Anse deployed?

Node

Describe the bug

As is commented in src/types/app.ts:

export interface GeneralSettings {
  /** Default request directly, can choose to request via proxy */
  requestWithBackend: boolean
}

And in src\components\settings\AppGeneralSettings.tsx:

<SettingsUIComponent
  value={() => props.settingsValue()[item.key] || false}
/>

I think the default value of requestWithBackend was intended to be false. But for now it always be true after mounting. I have tried to troubleshoot the issue by console.logging everything but still failed. I only found that resetting checked to false after first rendering solves (but I think there may be better ways).

This solves the problem (in inelegant way):

export const Toggle = (inputProps: Props) => {
  const props = mergeProps({}, inputProps)
  let hack_FirstTimeRender = true
  const [state, send] = useMachine(zagSwitch.machine({
    id: createUniqueId(),
    readOnly: props.readOnly,
    value: props.value(),
    onChange({ checked }) {
      if (hack_FirstTimeRender) {
        hack_FirstTimeRender = false
+       props.setValue(false)
        return
      }
      props.setValue(!checked)
    },
  }))

It seems the FirstTimeRender hack doesn't work?

Or maybe it is a bug of zagSwitch, which always set checked to true after components being mounted? I'm really confused. If you have any ideas please let me know, thanks!

Participation

  • [ ] I am willing to submit a pull request for this issue.

CNSeniorious000 avatar May 10 '23 02:05 CNSeniorious000