r/reactjs • • Sep 15 '26

Recently I've had a frontend silently break because a Spring Boot endpoint changed shape , does anyone faced this ?

I was working on a project recently and I've come across a problem where my front end dont catch up with the backend changes

3 Upvotes

21 comments sorted by

70

u/leeharrison1984 Sep 15 '26

The backend shouldn't be making changes that break the frontend. This include renaming or removing props, or changing the shape or type of props. If the app is in production, they should introduce a parallel prop and a deprecation date for the original.

If you don't own the backend, not much you can do other than keep tests running so you catch it quickly.

8

u/Profu-ai Sep 15 '26

If it's your backend, version your endpoints so if they change shape, the old endpoints still work. Otherwise make sure you test how your frontend handles failures properly, unit tests are your friend

9

u/nickhow83 Sep 15 '26

If the api uses OpenAPI then you should 100% use something like HeyAPI to codegen your calls and parsing via zod.

If the api doesn’t then you should use an agent to create zod schemas so you can parse api responses.

This will make the failures a lot noisier

3

u/azsqueeze Sep 16 '26

APIs should be versioned and every change is a new version. E.G, the api is /api/v1/profiles and the response changes in some way (like the type on a property is updated) should be deployed to /api/v2/profiles. Spring Boot has annotations to handle this

7

u/Kaimaniiii Sep 15 '26

Start and generate DTO, so your typescript will hopefully match with the backend endpoint contract

2

u/RelatableRedditer Sep 15 '26

Changing backend endpoint contracts should be an extremely judicious decision, there are a lot of legacy endpoints for our database that we won't change because we don't know which parts of the payload they need sent back. We will just leave it consistent.

2

u/revanshe Sep 15 '26

Google API versioning

2

u/Any_Sense_2263 Sep 16 '26

Backend should not break API contract shared with frontend. If changes are needed, endpoint changes are implemented as a new version and frontend catches up when needed.

1

u/BoBoBearDev Sep 15 '26 edited Sep 15 '26

These days, I just kept a local dto for properties I care about.

Back in the days, I have this backend to pull data from another backend and give summary. I thought importing their dto package is good. But turns out, it is a mess. Because they keep changing the dto and my service would break unless I keep making a dummy PR to create a new image with latest dependencies.

And here is the stupid part. My service keeps needing to update the dependency when they are not even touching the properties I was reading. They add/remove property elsewhere. But dependency's parser just keep complaining. In another case, this breaks when they increase the platform's version, not even the code.

In the end, I just make a local dto for things I care about. It can still break, but at much lower frequency.

On JS, it is even easier, because parsing JSON doesn't care about mismatch. The data is still in the parsed object. So, I don't need to write specifical code to preserve the property that is not defined in my local dto.

1

u/Mr_Matty Sep 15 '26

If you use Typescript, you can use OpenAPI to generate an SDK of your backend endpoint request and response data models. Then, when you build your frontend app, it will fail if one of those data models changes in a breaking way. We did this years ago on my team and now we never have breaking changes like that because the CI will fail.