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

instanceof breaks in dev mode #9528

Closed
7 tasks done
bryanmylee opened this issue Aug 4, 2022 · 6 comments
Closed
7 tasks done

instanceof breaks in dev mode #9528

bryanmylee opened this issue Aug 4, 2022 · 6 comments
Labels
duplicate This issue or pull request already exists

Comments

@bryanmylee
Copy link

Describe the bug

I am building a table library for Svelte which uses classes and instanceof checks quite extensively. I've noticed that the behaviour of instanceof is different between yarn dev and yarn build && yarn preview. More specifically, instanceof returns false in cases where I expect it to return true.

My core library (svelte-headless-table) exposes an argument that accepts an object of plugins. These plugins are exported from svelte-headless-table/plugins that can extend the library's functionality. Some plugins use instanceof checks for their logic, but instanceof results in incorrect behaviour.

The issue persists with npm and pnpm.

Catching the issue

The issue does not surface if I use npm link or pnpm.overrides to debug the package. I've only been able to catch the issue by adding console.log statements to the packaged library files in node_modules/. I've added instructions to the reproduction repo on how to do so.

Dev mode

dev mode instanceof check

Preview mode

preview mode instanceof check

Relevant discussion

An existing issue thread exists here.

Reproduction

https://github.com/bryanmylee/svelte-headless-table-vite-instanceof-check

System Info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
    Memory: 111.06 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v16.15.0/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
    Watchman: 2022.07.04.00 - /Users/bryanmylee/homebrew/bin/watchman
  Browsers:
    Chrome: 103.0.5060.134
    Safari: 15.5

Used Package Manager

yarn

Logs

No errors are thrown and the library fails silently in dev.

Validations

@rohanrajpal
Copy link

Here's a modification of the above minimum reproduction repo, but it uses rollup

https://github.com/rohanrajpal/svelte-headless-table-rollup

instanceof works as expected in this repo, so the issue is probably with Vite.

Since Vite uses Rollup, I was just canceling the possibility of an error there. Tho, I have little knowledge of how Vite works, so not sure if this experiment was actually of any help.

@ilmpc
Copy link

ilmpc commented Nov 2, 2022

I can confirm that this bug exists. In my case it appeared in JSBI lib. There's instanceof check in JSBI object methods that fails, because object has o3 class instead JSBI.
I have found this bug when connected @uniswap/widgets to react 18 app bootstrapped with Vite

@fabian-hiller
Copy link

fabian-hiller commented May 21, 2023

We also have the problem that instanceof does not work. Probably the classes in dev mode exist several times.

Comment in issue: fabian-hiller/modular-forms#59 (comment)
PR with workaround: fabian-hiller/modular-forms#66

@fabian-hiller
Copy link

Any news on this issue?

@aorumbayev
Copy link

Any updates on the potential fixes?

Tried with:

import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  esbuild: {
    minifyIdentifiers: false,
    keepNames: true,
  },
})

same results

@sapphi-red
Copy link
Member

Duplicate of #3910

@sapphi-red sapphi-red marked this as a duplicate of #3910 Nov 7, 2023
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Nov 7, 2023
@github-actions github-actions bot locked 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
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

6 participants