infinite while loop checking if a gameObject is in the air

I’m trying to code a push/pull mechanic, and when the player pushes the box off the ledge I want to keep it not kinematic while it doesn’t reach the floor.
For that, I’m using a while loop inside Update() that checks, with raycasts, if the box is still in the air, but it crashes the unity.

void Update()
    {    

        if (Input.GetKeyDown(KeyCode.LeftShift) && PushableObject() && GroundCheck())
        {
            box.GetComponent<Rigidbody>().isKinematic = false;
            box.gameObject.transform.parent = player.transform;
            isPushing = true;
           
        }

        if ((Input.GetKeyUp(KeyCode.LeftShift) && isPushing) || (isPushing && PushableObject() == false))
        {

            if (BoxGroundCheck(box) == false)
            {
               bool onGround = false;

                while(onGround == false)                 
                {
                    box.GetComponent<Rigidbody>().isKinematic = false;
                    onGround = BoxGroundCheck(box);
                 }            
            }

            box.GetComponent<Rigidbody>().isKinematic = true;
            box.gameObject.transform.parent = null;
            isPushing = false;
        }
    }

bool BoxGroundCheck(GameObject bx)
    {
        RaycastHit hit;
        float distance = 0.5f;
        Vector3 dir = new Vector3(0, -1);
        bool isGrounded;

        if (Physics.Raycast(bx.transform.position, dir, out hit, distance) || Physics.Raycast(bx.transform.position + new Vector3(-0.2f, 0, 0), dir, out hit, distance) || Physics.Raycast(bx.transform.position + new Vector3(+0.2f, 0, 0), dir, out hit, distance))
        {
            isGrounded = true;
        }
        else
        {
            isGrounded = false;
        }

        return isGrounded;
    }

bool PushableObject()
    {
        RaycastHit hit;
        float distance = 1f;
        bool isPushable;

        if (Physics.Raycast(player.transform.position, new Vector3(x, y, z), out hit, distance))
        {
            if (hit.collider.gameObject.tag == "Box")
            {
                isPushable = true;
                box = hit.collider.gameObject;
            }
            else
            {
                isPushable = false;
            }
        }
        else
        {
            isPushable = false;
        }

        return isPushable;
    }

When you do a loop, unity needs to finish it before it can do anything else. Maybe you can just do that each Update() or each FixedUpdate(), without putting it in a while loop. Maybe you need to start a coroutine where the while loop is.

While you’re fixing this, to avoid crashes, you could add a variable to which you add 1 in the while loop, and stop the loop & Debug.Log(“infinite loop”) if it’s over like 1000.