Grid-based hydrodynamics simulations of circumstellar disks are often performed in the curvilinear coordinate system, in which the center of the computational domain coincides with the motionless star. However, the center of mass may be shifted from the star due to the presence of any non-axisymmetric mass distribution. As a result, the system exerts a gravity force on the star, causing the star to move in response, which can affect the evolution of the circumstellar disk. We aim at studying the effects of stellar motion on the evolution of protostellar and protoplanetary disks. In protostellar disks, a non-axisymmetric distribution of matter in the form of spiral arms or massive clumps can form due to gravitational instability. Protoplanetary disks can also feature non-axisymmetric structures caused by a high-mass planet or a large-scale vortex. We use 2D grid-based hydrodynamic simulations to explore the effect of stellar motion. We adopt a non-inertial polar coordinate system centered on the star, in which the stellar motion is taken into account by calculating the indirect potential caused by the non-axisymmetric disk, a high-mass planet, or a large-scale vortex. We found that the stellar motion has a moderate effect on the evolution history in protostellar disks, reducing somewhat the disk size and mass, while having a profound effect on the collapsing envelope, changing its inner shape from an initially axisymmetric to a non-axisymmetric configuration. Protoplanetary disk simulations show that the stellar motion slightly reduces the width of the gap opened by a high-mass planet, decreases the planet migration rate, and strengthens the large-scale vortices formed at the viscosity transition. We conclude that the inclusion of the indirect potential is recommended in grid-based hydrodynamics simulations of circumstellar disks which use the curvilinear coordinate system.