Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem With OpenAPI Private Identifiers #56612

Closed
1 task done
dashty94 opened this issue Oct 9, 2023 · 5 comments · Fixed by #57904
Closed
1 task done

Problem With OpenAPI Private Identifiers #56612

dashty94 opened this issue Oct 9, 2023 · 5 comments · Fixed by #57904
Assignees
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked SWC Related to minification/transpilation in Next.js.

Comments

@dashty94
Copy link

dashty94 commented Oct 9, 2023

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/competent-swartz-l9zwsj

To Reproduce

  1. Use openapi-typescript-codegen@0.25.0 to generate typescript based on on OpenAPI specifications
  2. Build the application (yarn build)
  3. Start the production server (yarn start)
  4. Open the application
  5. Gets success responses of 200
  6. The promise is not resolved in try and catch

Current vs. Expected behavior

The generated files work well when running the application locally with yarn dev. But when running the build, the requests do not get resolved. The only difference compared to the previous versions is that it uses private identifiers.

Downgrading to next@13.4.5 resolves the issue and has no problem. The issue is with using the latest next versions (13.5.4).

Request example:

const getUser = async () => {
        try {
            const currentUser: any = await UsersSelfService.getSelf({}) // request is successfully made
           // But Does not reach here
        } catch (err) {
            // Does not reach here
        } 
    }

CancelablePromise generated from the codegen:

/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export class CancelError extends Error {

    constructor(message: string) {
        super(message);
        this.name = 'CancelError';
    }

    public get isCancelled(): boolean {
        return true;
    }
}

export interface OnCancel {
    readonly isResolved: boolean;
    readonly isRejected: boolean;
    readonly isCancelled: boolean;

    (cancelHandler: () => void): void;
}

export class CancelablePromise<T> implements Promise<T> {
    #isResolved: boolean;
    #isRejected: boolean;
    #isCancelled: boolean;
    readonly #cancelHandlers: (() => void)[];
    readonly #promise: Promise<T>;
    #resolve?: (value: T | PromiseLike<T>) => void;
    #reject?: (reason?: any) => void;

    constructor(
        executor: (
            resolve: (value: T | PromiseLike<T>) => void,
            reject: (reason?: any) => void,
            onCancel: OnCancel
        ) => void
    ) {
        this.#isResolved = false;
        this.#isRejected = false;
        this.#isCancelled = false;
        this.#cancelHandlers = [];
        this.#promise = new Promise<T>((resolve, reject) => {
            this.#resolve = resolve;
            this.#reject = reject;

            const onResolve = (value: T | PromiseLike<T>): void => {
                if (this.#isResolved || this.#isRejected || this.#isCancelled) {
                    return;
                }
                this.#isResolved = true;
                this.#resolve?.(value);
            };

            const onReject = (reason?: any): void => {
                if (this.#isResolved || this.#isRejected || this.#isCancelled) {
                    return;
                }
                this.#isRejected = true;
                this.#reject?.(reason);
            };

            const onCancel = (cancelHandler: () => void): void => {
                if (this.#isResolved || this.#isRejected || this.#isCancelled) {
                    return;
                }
                this.#cancelHandlers.push(cancelHandler);
            };

            Object.defineProperty(onCancel, 'isResolved', {
                get: (): boolean => this.#isResolved,
            });

            Object.defineProperty(onCancel, 'isRejected', {
                get: (): boolean => this.#isRejected,
            });

            Object.defineProperty(onCancel, 'isCancelled', {
                get: (): boolean => this.#isCancelled,
            });

            return executor(onResolve, onReject, onCancel as OnCancel);
        });
    }

     get [Symbol.toStringTag]() {
            return "Cancellable Promise";
     }

    public then<TResult1 = T, TResult2 = never>(
        onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
        onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
    ): Promise<TResult1 | TResult2> {
        return this.#promise.then(onFulfilled, onRejected);
    }

    public catch<TResult = never>(
        onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
    ): Promise<T | TResult> {
        return this.#promise.catch(onRejected);
    }

    public finally(onFinally?: (() => void) | null): Promise<T> {
        return this.#promise.finally(onFinally);
    }

    public cancel(): void {
        if (this.#isResolved || this.#isRejected || this.#isCancelled) {
            return;
        }
        this.#isCancelled = true;
        if (this.#cancelHandlers.length) {
            try {
                for (const cancelHandler of this.#cancelHandlers) {
                    cancelHandler();
                }
            } catch (error) {
                console.warn('Cancellation threw an error', error);
                return;
            }
        }
        this.#cancelHandlers.length = 0;
        this.#reject?.(new CancelError('Request aborted'));
    }

    public get isCancelled(): boolean {
        return this.#isCancelled;
    }
}

tsconfig.json:

{
    "compilerOptions": {
        "baseUrl": ".",
        "target": "es6",
        "lib": ["dom", "dom.iterable", "esnext"],
        "allowJs": true,
        "skipLibCheck": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "strict": false,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": true,
        "noEmit": true,
        "jsx": "preserve",
        "incremental": true
    },
    "include": ["src"],
    "exclude": ["node_modules", ".next"]
}

next.config.js

const nextConfig = {
    swcMinify: true,
    reactStrictMode: false,
}

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #34~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep  7 13:12:03 UTC 2
Binaries:
  Node: 18.16.0
  npm: 9.5.1
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.5-canary.4
  eslint-config-next: 13.5.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

No response

WEB-1743

@dashty94 dashty94 added the bug Issue was opened via the bug report template. label Oct 9, 2023
@balazsorban44 balazsorban44 added the SWC Related to minification/transpilation in Next.js. label Oct 9, 2023
@balazsorban44
Copy link
Member

Seems to be a regression in #51943 (v13.4.8-canary.10), we will have a look, thanks!

@balazsorban44 balazsorban44 added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Oct 9, 2023
@kdy1 kdy1 self-assigned this Oct 9, 2023
@kdy1
Copy link
Member

kdy1 commented Oct 10, 2023

This is a regression between swc_core@v0.76.46 and swc_core@v0.78.24

@kdy1
Copy link
Member

kdy1 commented Oct 10, 2023

Range: swc-project/swc@3fe1236...b4ae28b

@hadrian625
Copy link

I am having the exact same issue. Last nextjs version which works for me is 13.4.7

kdy1 added a commit to swc-project/swc that referenced this issue Nov 2, 2023
@kodiakhq kodiakhq bot closed this as completed in #57904 Nov 7, 2023
kodiakhq bot pushed a commit that referenced this issue Nov 7, 2023
### What?

* vercel/turborepo#6286 
* vercel/turborepo#6367 
* vercel/turborepo#6354 
* vercel/turborepo#6343 

---

 - Update `swc_core` to `v0.86.40`

 - Revert #56281 and fix `node-fetch` by disabling inlining
   - Use `inline: 2` instead of `keep_fnames: true`

### Why?

`keep_fnames` increases the bundle size too much.

### How?

 - Fixes #56612

 - Fixes #57886 

 - Fixes #55682 (by swc-project/swc#8205)

 - Reverts #56281


 - Closes PACK-1902
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants