Canvasのwidthを変更すると描画設定がリセットされる場合
Canvasに描いた内容や fillStyle などの設定は、canvas.width を変更すると消えて初期状態に戻ります。同じ値を代入しても同じです。
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'red';
canvas.width = canvas.width; // 描画クリア+設定リセット
console.log(ctx.fillStyle); // '#000000'対策は、width / height は最初に決めて、設定と描画はその後に行うことです。内容を残したい場合は、変更前に getImageData() で退避してください。