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

Don't export PrimerMultiInputElement #1731

Closed
wants to merge 1 commit into from

Conversation

safeforge
Copy link
Contributor

Exporting a component can cause errors when used as an npm package. Please see #1560

/cc @jonrohan

@safeforge safeforge requested review from a team and camertron December 24, 2022 06:57
@changeset-bot
Copy link

changeset-bot bot commented Dec 24, 2022

🦋 Changeset detected

Latest commit: 9dade03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jonrohan
Copy link
Member

Is there some kinda linting we could introduce to avoid this in the future?

@camertron
Copy link
Contributor

camertron commented Dec 28, 2022

Just popping in here to say that this time I actually need to reference the PrimerMultiInputElement class in another file, so it has to be exported. Last time it didn't matter because I didn't need to use ToggleSwitchElement anywhere. I didn't dig into why the error reported by @safeforge in #1440 occurs, so I don't understand it at all. @keithamus mentioned here that it should be possible to export custom elements, perhaps he can chime in below. It probably has something to do with how Catalyst manages custom elements.

@safeforge
Copy link
Contributor Author

Thank you for explaining. I had the chance to investigate another way to use the library as an npm and seems to work properly. Instead of using import '@primer/view-components'; I tried with full path and I'm able to compile and use all components.

diff --git a/app/javascript/application.js b/app/javascript/application.js
index 524536c..c4f2aa4 100644
--- a/app/javascript/application.js
+++ b/app/javascript/application.js
@@ -1,3 +1,3 @@
 import '@hotwired/turbo-rails';
-import '@primer/view-components';
+import '@primer/view-components/app/assets/javascripts/primer_view_components.js';
 import './stimulus.js';

Removing the module from package.json is possible to import @primer/view-components without errors and I'm wondering if it's necessary to keep both main and module

diff --git a/package.json b/package.json
index 5e8086f7..4ad29a34 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,6 @@
   "version": "0.0.116",
   "description": "ViewComponents for the Primer Design System",
   "main": "app/assets/javascripts/primer_view_components.js",
-  "module": "app/components/primer/primer.js",
   "types": "app/components/primer/primer.d.ts",
   "repository": "primer/view_components",
   "keywords": [

@safeforge
Copy link
Contributor Author

Thank you for your support, I'm going to close the issue since importing the full path seems to work properly.

@safeforge safeforge closed this Jan 12, 2023
@safeforge safeforge deleted the dont-export-elements branch January 19, 2023 07:49
writercoder added a commit to writercoder/view_components that referenced this pull request Jul 13, 2023
Use the full import path in documentation as recommended in the PR here primer#1731 (comment) to avoid `Uncaught DOMException` errors around double registration of web components.
@writercoder
Copy link
Contributor

I've opened a PR with an update to the install documentation as I spent a while chasing this one down.

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.

4 participants