filestack / filestack-js

Official Javascript SDK for the Filestack API and content ingestion system.
https://www.filestack.com
MIT License
206 stars 76 forks source link

`i.sent` is not a constructor? #422

Closed andrewmartin closed 3 years ago

andrewmartin commented 3 years ago

Seeing this funky error.

I'm using some very basic Filestack code. Breaks on NextJS app during compilation cycles.

filestack.esm.js?c299:41 Uncaught (in promise) TypeError: i.sent(...) is not a constructor
    at t.eval (filestack.esm.js?c299:41)
    at eval (filestack.esm.js?c299:40)
    at Object.eval [as next] (filestack.esm.js?c299:40)
    at a (filestack.esm.js?c299:40)

My invocation is fairly simple, but I'll try to exclude the React stuff. Basically:

export const defaultPickerOptions = {
  accept: ['image/*'],
}

const buildPicker  = (options: filestack.PickerOptions) {
    if (isBrowser()) {
      return client.picker({
        ...defaultPickerOptions,
        ...options,
      })
    }
}

I might have something funky going on here:

const getPicker =  buildPicker({
      onUploadDone: setPickerResponse, // basically, just passing this thru to setState.
    });

I'm using a NextJS app with SSR, so I'm trying to wrap things around that isBrowser() check. Any ideas?

Here's the whole file, hopefully this doesn't add to the confusion:


import * as filestack from 'filestack-js'
import { useState } from 'react'
import { isBrowser } from 'src/util/env'

const key = process.env.NEXT_PUBLIC_FILESTACK_API_KEY
export const client = filestack.init(key as string)

export const defaultPickerOptions = {
  accept: ['image/*'],
}

// hooks

export const usePickerState = () => {
  const picker = (options: filestack.PickerOptions) => {
    if (isBrowser()) {
      return client.picker({
        ...defaultPickerOptions,
        ...options,
      })
    }
  }

  const [pickerResponse, setPickerResponse] = useState<filestack.PickerResponse | undefined>(
    undefined,
  )

  const [pickerClient] = useState<filestack.PickerInstance | undefined>(
    picker({
      onUploadDone: setPickerResponse,
    }),
  )

  return {
    pickerClient,
    pickerResponse,
  }
}

// the consumer has `pickerClient` and `pickerResponse` available on the React state.

Should mention the upload does work fine, it just borks out from time to time when I'm compiliing.

andrewmartin commented 3 years ago

I'm also noticing this wonkiness, where it appends the script tag every time.

Why does this inject JS on the page if we already have the source? Seems like a bug on your end.

client.picker({ ...defaultPickerOptions, ...options, }) `

Image 2021-02-28 at 11 36 08 PM

pcholuj commented 3 years ago

Yup its look like problem with our loader, we need to check it.

pcholuj commented 3 years ago

@andrewmartin can you provide some example ie in https://stackblitz.com/ or contact our support? I was trying to reproduce this, but on my example it's working as it should.

smundro commented 3 years ago

I was seeing a similar issue in React, refactoring seemed to fix the i.sent issue, upgrading to 3.22.1 seemed to resolve the multiple fs-loader-picker script tags, but I'm still seeing multiple fs-loader-cropper script tags being added: image

pcholuj commented 3 years ago

yup, we checked our loader, and its seems to work ok, need to dive into nextjs and ssr rendering for that

pcholuj commented 3 years ago

we foud the problem causing this issue, it will be released in next version ~7days

pcholuj commented 3 years ago

Hi, Fix for multiple adding script to body was released with newest version.