-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Create non-auto-registering routes #1450
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! Left some initial suggestions.
this PR is awesome! I'm definitely waiting on this to merge so that I can install and re-register a few shoelace comps like sl-popup. I have some question about the self-definition feature in here:
Looking at the code, it seems like all an extending class would need to do is reset |
…o konnorrogers/dont-auto-define
Honestly, I keep going back and forth on this. I want to be able to use the
It shouldn't. You'll get console warnings if the global element already exist, but you should still be able to scope if you need to.
Correct. |
I get it. We use scoped elements everywhere and its definitely a pain. It makes the React Wrappers less worth it because it requires those wrappers be imported client-side and i think that folks using react wrappers (especially in nextjs) might just assume that the react wrappers work server-side because they have react structure/syntax. Also the polyfill is a bit of a pain because its an application responsibility to make sure it gets imported before any WCs and some existing apps here are super complex and nested apps in weird monorepos and that can be hard to get all the imports into the root index so that the polyfill comes first. That said, I think i'd still keep with scoped elements because scoping enables multiple versions of the same component to exist on the same page at the same time even if those components are internal to some other component. If alerts uses icon, then the version of icon in alert doesnt have to be the same as the version of icon in the app using alert. Thats a major benefit imo. Let me know if you want to talk shop about scoped elements and the approach. I use the polyfill and the ScopedElementsMixin from open-wc. I've thought about switching to the Lit one, but they arent that much different |
These are the exact pains I don't know if we're ready to dump onto consumers.
Yup. I believe this is a major benefit. However, I'm not sure we've even worked out what happens when Shoelace is loaded across different versions on the same page. Particularly around styles which currently register to EDIT: Perhaps we consider this a step in the direction towards scoped elements, at least we now have the option of not always auto-registering on import. |
So in talking with @claviska it appears we may have another use-case to support for tree-shaking for non-react users without needing to cherry-pick. This would be a breaking change, so perhaps in the 2.x release cycle it would live at The key use-case being around easy integrations with things like Vue / Svelte, etc Will report back as we discuss this more! |
so does that mean that this PR has more work before getting merged? no rush, but I'm waiting on this PR to pull in some shoelace components into my project that I want to re-register :) |
Yes, it requires a bit more work. Also, while you will be able to re-register, we still don’t support changing tag names and I’d consider that an unsupported use case for the time being. |
"sideEffects": [ | ||
"./dist/shoelace.js", | ||
"./dist/shoelace-autoloader.js", | ||
"./dist/components/**/*.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your work, but the sideEffects settings here seems to break the cherry picking usage such as:
import '@shoelace-style/shoelace/dist/components/button/button.js';
Since the dist/components/button/button.js
also imports dist/chunks/*.js
which are not marked as sideEffects
, which will be tree-shaked in production mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a repo by chance?
What bundler are you using? I tested mainly with Vite, Webpack (via CRA), and Parcel.
In Stackblitz using NPM + Vite, it seems to work.
https://stackblitz.com/edit/vitejs-vite-42iegf?file=main.js,package.json,index.html&terminal=dev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using Webpack. But your demo is just ok to reproduce it. Try npm run build && npm run preview
. Tree-shaking only happens in production mode by default, so npm run dev
is not the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the docs for 2.6.0 version suggest to import for bundler like so import '@shoelace-style/shoelace/dist/components/button/button.component.js';
but by doing this you also break the dev environment.
Using the same demo @KonnorRogers provided I've just changed the import for the button.
https://stackblitz.com/edit/vitejs-vite-n3cvck?file=main.js
Not sure if this is related to the problem or it's a docs error. @claviska
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Antony92 Good call on the new import docs. Its probably pulling from the manifest 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Antony92 🤔 where in the docs does it say to use the .component.js
import? There's a note about auto-registering, but thats different.
Alright. This is a massive PR addressing many things.
Fixes #1437 #1431 #1375 #874 #705
Summary of changes:
displayName
to React Wrappers for better debugging.sideEffects
key inpackage.json
.<sl-tree>
where it was auto-defining<sl-tree-item>
.shoelace.js
andshoelace-autoloader.js
to exportmaps.