Don't let it rewrite from memory, it doesn't have memory of yesterday's code, only what's in the files now.
- Since you're on GitHub: open the repo, go to the history of the checkout file (e.g.
src/pages/Checkout.tsx→ History). Find the commit from yesterday evening where shipping worked. Copy the shipping function from there. - Paste it back yourself in Lovable's code editor (Dev Mode), or give it to Lovable as "replace
calculateShippingwith exactly this code, change nothing else".
Don't use the full-project revert in the history panel for this: that would also undo today's 6 changes.
To prevent it: move the rates out of the page. Ask for a separate file src/lib/shipping.ts with the rates as a plain object. Small, isolated files get touched much less when you ask for unrelated UI changes. And for UI tweaks, start the prompt with "Only edit the button styles in Checkout.tsx".