feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

Error in patch: RangeError: Maximum call stack size exceeded #3466

Closed abhijithbabu closed 2 months ago

abhijithbabu commented 2 months ago

Steps to reproduce

When calling patch, the react client using feathers gives Maximum call stack size exceeded error.

How its called

import type {Application, Params, TransportConnection} from '@feathersjs/feathers'
import {feathers} from '@feathersjs/feathers'
import type {SocketService} from '@feathersjs/socketio-client'
import socketio from '@feathersjs/socketio-client'
import io from 'socket.io-client'
import {GenerateData, NewPresentationResponse} from "../components/prompt/type";

type ServiceTypes = {
    presentation: SocketService & {
        generate(data: GenerateData, params: Params): Promise<NewPresentationResponse>
    }
}

const socket = io('http://localhost:3030/')
const client: Application<ServiceTypes, any> = feathers<ServiceTypes>()
const socketClient: TransportConnection<ServiceTypes> = socketio<ServiceTypes>(socket)

client.configure(socketClient)

client.use('presentation', socketClient.service('presentation'), {
    methods: ['find', 'get', 'create', 'patch', 'remove', 'generate'],
    events: ['generate']
})

export {client}
client.service('presentation').patch("661da91c28f1f722821100ab", {status: 'edited'})
            .then((response: NewPresentationResponse) => {
                console.log('Patch response:', response);
            }).catch((error) => {
            console.error('Error in patch:', error);
});

Backend

export const presentation = (app: Application) => {
  // Register our service on the Feathers application
  app.use(presentationPath, new PresentationService(getOptions(app), app), {
    // A list of all methods this service exposes externally
    methods: presentationMethods,
    // You can add additional custom events to be sent to clients here
    events: presentationMethods
  })
  // Initialize hooks
  app.service(presentationPath).hooks({
    around: {
      all: [
        //authenticate('jwt'),
        schemaHooks.resolveExternal(presentationExternalResolver),
        schemaHooks.resolveResult(presentationResolver)
      ]
    },
    before: {
      all: [
        schemaHooks.validateQuery(presentationQueryValidator),
        schemaHooks.resolveQuery(presentationQueryResolver)
      ],
      find: [],
      get: [],
      create: [
        schemaHooks.validateData(presentationDataValidator),
        schemaHooks.resolveData(presentationDataResolver)
      ],
      patch: [
        schemaHooks.validateData(presentationPatchValidator),
        schemaHooks.resolveData(presentationPatchResolver)
      ],
      remove: []
    },
    after: {
      all: []
    },
    error: {
      all: []
    }
  })
}

// Add this service to the service type index
declare module '../../declarations' {
  interface ServiceTypes {
    [presentationPath]: PresentationService
  }
}

Expected behavior

No errors

Actual behavior

index.tsx:56 Error in patch: RangeError: Maximum call stack size exceeded
    at hasBinary (is-binary.js:24:1)
    at hasBinary (is-binary.js:45:1)
    at hasBinary (is-binary.js:45:1)
    at hasBinary (is-binary.js:45:1)
    at hasBinary (is-binary.js:45:1)
    at hasBinary (is-binary.js:45:1)
    at hasBinary (is-binary.js:45:1)
    at hasBinary (is-binary.js:45:1)
    at hasBinary (is-binary.js:45:1)
    at hasBinary (is-binary.js:45:1)

System configuration

Tell us about the applicable parts of your setup.

Backend package.json

"dependencies": {
    "@feathersjs/adapter-commons": "^5.0.24",
    "@feathersjs/authentication": "^5.0.24",
    "@feathersjs/authentication-client": "^5.0.24",
    "@feathersjs/authentication-local": "^5.0.24",
    "@feathersjs/authentication-oauth": "^5.0.24",
    "@feathersjs/configuration": "^5.0.24",
    "@feathersjs/errors": "^5.0.24",
    "@feathersjs/feathers": "^5.0.24",
    "@feathersjs/koa": "^5.0.24",
    "@feathersjs/mongodb": "^5.0.24",
    "@feathersjs/schema": "^5.0.24",
    "@feathersjs/socketio": "^5.0.24",
    "@feathersjs/transport-commons": "^5.0.24",
    "@feathersjs/typebox": "^5.0.24",
    "mongodb": "^6.5.0",
    "openai": "^4.32.1",
    "uuid": "^9.0.1",
    "winston": "^3.13.0"
  }

Frontend

  "@feathersjs/feathers": "^5.0.24",
  "@feathersjs/socketio-client": "^5.0.24",
abhijithbabu commented 2 months ago

I found the issue, I had

export const presentationClient = (client: ClientApplication) => {
    const connection = client.get('connection')

    client.use(presentationPath, connection.service(presentationPath), {
        methods: presentationMethods,
        events: presentationMethods
    })
}

When I changed to below its now fine. Thanks

export const presentationClient = (client: ClientApplication) => {
    const connection = client.get('connection')

    client.use(presentationPath, connection.service(presentationPath), {
        methods: presentationMethods
    })
}