Skip to content

Virtual fix for ember-inspector #2455

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

BlueCutOfficial
Copy link
Collaborator

@BlueCutOfficial BlueCutOfficial commented Apr 18, 2025

Fixes #2484

Context

As part of the Ember Initiative, @mansona and I are trying to get ember-inspector to work for Vite apps. Two draft PRs have been opened in ember.js and ember-inspector as proof of concept of a new protocol that would allow the inspector to communicate with the Ember Vite app on the page.

Changes in ember.js will require going through an RFC process though, and meanwhile, Vite users are stuck with a non-functional inspector.

Changes

This PR proposes a temporary solution to have ember-inspector work for Vite apps:

  • a vite plugin creates the file that should be ultimately provided by ember.js: a globalThis.emberInspectorLoader.load() that returns everything the inspector needs to know to show information about the page.
  • a compat-adapter for ember-source < 4.8 returns more or less the same thing but for these versions @ember/enumerable/mutable didn't exist yet, and EnumerableMutable must be imported from another place.

How to test

  • Serve the app-template on http://localhost:4200/
  • Clone mansona/ember-inspector and switch to vite-support branch
  • Follow the section of ember-inspector's README about pnpm serve:bookmarklet to run the local inspector against http://localhost:4200/
Capture d’écran 2025-04-24 à 18 46 18

Copy link
Member

@mansona mansona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So looking at this PR I figured it looked strange that a virtual file would have a namespace that really exists in a ember-source 🤔 and also one that we expect to make a real file in some future version of ember-source

I know I kept saying "Virtual file" when we talked about this but with the fact that it's something that could change with different Ember versions and exists in a real namespace I think we should add this to the ember-source compat adapter

I'm pretty sure the replaceFile() function that I created should be able to create new files 🤔 https://github.com/embroider-build/embroider/blob/main/packages/compat/src/compat-adapters/ember-source.ts#L320C5-L320C16

@BlueCutOfficial BlueCutOfficial force-pushed the virtual-fix-ember-inspector branch from 7fea563 to 0d6967f Compare April 24, 2025 16:42
@BlueCutOfficial BlueCutOfficial force-pushed the virtual-fix-ember-inspector branch 5 times, most recently from 7a7b232 to d916978 Compare April 25, 2025 14:17
@BlueCutOfficial BlueCutOfficial force-pushed the virtual-fix-ember-inspector branch from d916978 to 43f44d7 Compare April 25, 2025 14:45
@patricklx
Copy link
Contributor

hi, I saw that this work started 👍
also consider possible race conditions for the loading part.
especially when a window is reloaded and inspector was already opended, the order of script loading is not guaranteed .
so inspector debug inject vs ember app scripts.
in previous ember source there was a dispatched event ember, which inspector uses

@mansona
Copy link
Member

mansona commented Apr 25, 2025

@patricklx yes that was at the bottom of the barrel file which is now deprecated, likely won't be included if you're using vite and will be removed in Ember 7 👍 so we can't rely on that for our architecture

@patricklx
Copy link
Contributor

patricklx commented Apr 28, 2025

Here is also a similar implementation directly in ember.js.
It contains the full list of all used classes and functions used by inspector.

https://github.com/emberjs/ember.js/pull/20580/files

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

Successfully merging this pull request may close these issues.

Virtual fix for ember-inspector
3 participants