swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Getting UNSAFE_componentWillReceiveProps error when using Next.js 15 / React 19

Open petergoldstein opened this issue 1 year ago • 21 comments

Q&A (please complete the following information)

  • OS: macOS
  • Browser: Chrome 130.0.6723.117
  • Method of installation: pnpm
  • Swagger-UI version: 5.18.2
  • Swagger/OpenAPI version: Swagger 2.0, OpenAPI 3.1.0

Content & configuration

I'm using a vanilla Swagger Page inside a Next.js 15 / React 19 application:

"use client";

import { useEffect, useState } from "react";
import SwaggerUI from "swagger-ui-react";
import "swagger-ui-react/swagger-ui.css";

function SwaggerPage() {
  const [spec, setSpec] = useState<any>(null);

  useEffect(() => {
    fetch("/api/swagger")
      .then((response) => response.json())
      .then((data) => setSpec(data));
  }, []);

  if (!spec) {
    return <div>Loading...</div>;
  }

  return <SwaggerUI spec={spec} />;
}

export default SwaggerPage;

Describe the bug you're encountering

I'm seeing the following error starting in Swagger-UI 5.18.0 and continuing through 5.18.2 on my Swagger page:

Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://react.dev/link/unsafe-component-lifecycles for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://react.dev/link/derived-state

Please update the following components: OperationContainer

To reproduce...

Steps to reproduce the behavior:

  1. Go to the Swagger UI page
  2. Page throws an error

Expected behavior

No error

Screenshots

Screenshot 2024-11-11 at 10 36 22 AM

petergoldstein avatar Nov 11 '24 15:11 petergoldstein

Next.js 15 uses Strict Mode by default, which is why we encountered this issue. swagger-ui-react still uses the deprecated UNSAFE_componentWillReceiveProps in several places.

Is there a possibility to refactor them?

tazo90 avatar Nov 15 '24 20:11 tazo90

Same problem as well

harmonicaCz avatar Dec 05 '24 17:12 harmonicaCz

Bump here.

javierlinked avatar Dec 17 '24 11:12 javierlinked

bump!

sbbu avatar Feb 03 '25 10:02 sbbu

Double bump 😎

GreatPotato avatar Feb 12 '25 13:02 GreatPotato

More bump 🫡

unclebay143 avatar Feb 19 '25 11:02 unclebay143

bump too!

70nyIT avatar Feb 19 '25 17:02 70nyIT

Any news on this?

thorsten avatar Mar 09 '25 16:03 thorsten

Bump x 3

Stanley-Jovel avatar Mar 24 '25 18:03 Stanley-Jovel

Bump

jbh-eva avatar Mar 26 '25 22:03 jbh-eva

Bump

rr-jino-jose avatar Apr 03 '25 17:04 rr-jino-jose

👋 This would be a great one to fix!

kmelve avatar Apr 03 '25 22:04 kmelve

BUMP.

basrioglumehmet avatar May 12 '25 01:05 basrioglumehmet

Same issue, Any news on this?

lesliechueng1996 avatar May 26 '25 15:05 lesliechueng1996

Hi all,

I see we have a partial community fix in https://github.com/swagger-api/swagger-ui/pull/10373. I'll review and merge that. Please do help with more PR porting to UNSAFE_ life cycle hooks to new alternatives.

char0n avatar May 27 '25 09:05 char0n

Bump

jszsj avatar Jul 03 '25 05:07 jszsj

@petergoldstein as a alternative you can check next-openapi-gen. It uses scalar as a default UI which supports latest versions of nextjs and react.

tazo90 avatar Jul 25 '25 09:07 tazo90

Bump - Still applicable as of 5th of October 2025 with latest version.

UtilExe avatar Oct 05 '25 11:10 UtilExe

Reopening this issue as it was only partially addressed by https://github.com/swagger-api/swagger-ui/pull/10373. There are still some components using the deprecated lifecycle methods.

glowcloud avatar Oct 07 '25 06:10 glowcloud

:tada: This issue has been resolved in version 5.29.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

swagger-bot avatar Oct 10 '25 11:10 swagger-bot