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 fails in classic mode #588

Open
gossi opened this issue Jul 13, 2023 · 4 comments
Open

instanceof fails in classic mode #588

gossi opened this issue Jul 13, 2023 · 4 comments

Comments

@gossi
Copy link

gossi commented Jul 13, 2023

I'm rewriting ember-command as v2 addon. The check I have there to test for links are:

if (something instanceof Link) { ... }

if (something instanceof LinkCommand) { ... }

To ensure embroider compatibility I'm using ember-try for with embroider scenarios. By default, when starting locally, it uses classic mode.

Now I've realized the checks above are failing in classic mode. As these are two different imports under the hood for Link and LinkCommand between the transpiled addon and the host app, thus the tests are failing. My theory is, due to the different locations and two different memory pointers, that's why the checks fail.

My workaround was to use a symbol, attach it to the LinkCommand and check for the existence of the symbol... it is failing, too (I think for the same reason).

When starting the test app in embroider mode: EMBROIDER_TEST_SETUP_FORCE='embroider' ember s the checks work as expected.

@NullVoxPopuli
Copy link
Contributor

NullVoxPopuli commented Jul 14, 2023

Do you have a PR where this is easily reproducible?

Potentially related:

@gossi
Copy link
Author

gossi commented Jul 15, 2023

Here is a PR: gossi/ember-command#22

But I think, I failed on CI setup for github, so must be done locally:

  1. Checkout
  2. pnpm install
  3. pnpm --filter ember-command run build
  4. cd test-app/ && ember s

Notes:

Also, I left a comment to this issue within the code to see when I left workarounds. Search for https://github.com/embroider-build/ember-auto-import/issues/588 inside the code.

My workaround: duck-typing and __***__ properties instead of symbols 😞

@mansona
Copy link
Member

mansona commented Jul 15, 2023

@NullVoxPopuli that is exactly the issue. The module graph essentially creates two different copies of the module so when you import something from a test file it can never be === something that is imported in an app 😞

@raycohen
Copy link

raycohen commented Aug 5, 2023

I am trying to convert a legacy addon into a v2 addon in a project using ember-auto-import and I think I am running into this as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants