# Race condition between change and load hooks

**URL:** <https://community.forestadmin.com/t/race-condition-between-change-and-load-hooks/7794>\
**Category:** Help me!\
**Created:** [January 29, 2025, 10:12am UTC](https://community.forestadmin.com/t/race-condition-between-change-and-load-hooks/7794 "2025-01-29T10:12:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoineww](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@antoineww](https://community.forestadmin.com/u/antoineww)\
**Post date:** [January 29, 2025, 10:12am UTC](https://community.forestadmin.com/t/race-condition-between-change-and-load-hooks/7794/1 "2025-01-29T10:12:15Z")

</div>

## Feature(s) impacted

Hooks in a smart action.

## Observed behavior

```javascript
    {
      name: 'Example',
      endpoint: '/forest/actions/example',
      type: 'single',
      fields: [
        {
          field: 'ok',
          type: 'Boolean',
          isRequired: true,
          defaultValue: true,
          hook: 'onOkChange',
        },
        {
          field: 'displayName',
          type: 'String',
        },
      ],
      hooks: {
        load: async function ({ fields }) {
          console.log('LOAD START');
          await sleep(1000);
          console.log('LOAD DONE');
          return fields;
        },
        change: {
          onOkChange: async function ({ fields }) {
            console.log('OK START');
            await sleep(1000);
            console.log('OK DONE');
            return fields;
          },
        },
      },
    },

```

When I open the smart action form, both load and change hooks are fired concurrently. Depending on the order they complete, one overwrites the other.

## Expected behavior

- No change hook should be fired when opening the form.
- If both really need to be fired, I would expect the change hook to wait for the load hook to complete before starting.

## Context

- Project name: Evy
- Team name: Operations
- Environment name: Dev
- Agent technology: nodejs
- Agent (forest package) name & version: forest-express-sequelize 9.5.4
- Database type: PostgreSQL

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [January 29, 2025, 1:59pm UTC](https://community.forestadmin.com/t/race-condition-between-change-and-load-hooks/7794/2 "2025-01-29T13:59:24Z")

</div>

Hello @antoineww

Sorry for the late reply, we were able to reproduce the issue, it occurs when the defaultValue and hook properties are defined on a field. A bug report has been created and will be fixed ASAP.

I’ll keep you updated when the fix has been released.

Thanks for the report.

Best regards,

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [February 4, 2025, 1:47pm UTC](https://community.forestadmin.com/t/race-condition-between-change-and-load-hooks/7794/3 "2025-02-04T13:47:54Z")

</div>

Hello @antoineww,

The fix has been merged, could you refresh your browser and confirm that it solves your issue ?
