Skip to content

htmx extension without globals #38

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

Closed
silverwind opened this issue Feb 14, 2024 · 4 comments · Fixed by #121
Closed

htmx extension without globals #38

silverwind opened this issue Feb 14, 2024 · 4 comments · Fixed by #121

Comments

@silverwind
Copy link

silverwind commented Feb 14, 2024

The htmx init code here relies on a htmx global:

htmx.defineExtension('morph', {

While reliance on globals is probably okay with <script> usage, in a scenario with a bundler it is not necessary and undesired to have any globals. How about allowing something like this?

import htmx from 'htmx.org';
import idiomorph from 'idiomorph/dist/idiomorph-ext-bundler.min.js';
htmx.defineExtension('morph', idiomorph);

Related: bigskysoftware/htmx-extensions#128

@silverwind silverwind changed the title htmx extension init without globals htmx extension without globals Feb 14, 2024
@botandrose
Copy link
Collaborator

@silverwind I like the idea in theory! However, the reality of the current state of the JS module system is that its a paralyzing mess. We are currently supporting several different ways of combining source files: server-side bundlers, client-side importmaps, ESM, CJS, AMD, and <script src>. Ensuring that Idiomorph continues to work via all of these is priority one.

That said, I'm open to any proposal you might put forward to address the issue you raise, without breaking compatibility for other inclusion methods. Got any ideas?

@silverwind
Copy link
Author

silverwind commented Feb 10, 2025

I would consider going pure ES modules and deprecating the other module systems at some point. Every major browser released since around 2020 supports ES modules. See https://caniuse.com/es6-module.

The vite bundler defaults to this as well via its default target: "modules".

@botandrose
Copy link
Collaborator

@silverwind Just an update here. We're getting ready to release v0.5.0, which adds the export key to package.json for the main Idiomorph module. I think we might be able to leverage that to export the right thing for the htmx extension too. Once v0.5.0 is out the door, let's look into making that happen.

Additionally, I would love to deprecate (or remove entirely) some of the older targets, as you suggest. Let's look into that as well.

@botandrose
Copy link
Collaborator

@silverwind https://www.npmjs.com/package/idiomorph/v/0.7.2 should resolve this. You can import "idiomorph/htmx" now, which give you an Idiomorph that is already registered with htmx as an extension.

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 a pull request may close this issue.

2 participants