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

Using the defintionsFromContext webpack helper does not mark controllers as registered #127

Closed
SleeplessByte opened this issue May 12, 2024 · 0 comments · Fixed by #128
Closed
Labels
bug Something isn't working

Comments

@SleeplessByte
Copy link

We are using Debian Rails which is at 6.1 for the time being. Note that this Rails version isn't deprecated and will continue to receive security fixes even after Rails stops supporting it, unless there is a new stable Debian.

Using definitionsFromContext from the @hotwired/stimulus-webpack-helpers package does not mark Stimulus controllers as registered.

import { definitionsFromContext } from '@hotwired/stimulus-webpack-helpers';

const application = Application.start(document.documentElement);

// Normally you'd need to add the webpack env types, but since we'll migrate
// away (in Rails 7), and we know the signatures here, it's ignored and casted
// as any instead.

// @ts-ignore
// eslint-disable-next-line no-undef
const context = require.context('../controllers', true, /_controller\.ts$/);
application.load(definitionsFromContext(context));

declare const window: Window & { Stimulus: Application };
window.Stimulus = application;

The result in the Stimulus Controllers view:

52 controllers showing as unregistered

I don't know if this is related, but I don't see any autocompletion in .html.erb files. I would expect them to not show for unregistered controllers, hence me opening this issue.

Trying to circumvent it by using the Register controller definition on the stimulus application yields the following error message:

Cannot read properties of undefined (reading 'isImportable')

@marcoroth marcoroth transferred this issue from marcoroth/stimulus-lsp May 15, 2024
@marcoroth marcoroth added the bug Something isn't working label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants