-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Preserve Class/Component.name or introduce a new displayName property #6537
Comments
What would this give you that |
Thanks for the reply.
A guarantee that it's always consistent with the name. I just tried the <script context="module">
export const displayName = 'MyComponent';
</script> This will not make But I think I can solve this by switching my logic around and having a Unless you have some insights on how I could make that work with |
I don't really have further insights since I don't know your exact situation, and if you say you don't have access to the module context then that's probably not a way to go. |
Another idea is to have a preprocessor to auto add the |
Describe the problem
I have a system that allows Svelte components to be opened in a new window (Electron app). Let's say I have a
Details
component, then I have a config which maps the name to the component{ "Details": Details }
and "blesses" this component so it can be used in a new window. This mapping is needed becauseDetails.name
will not beDetails
after minification.Now this system has reached it's limit. I need to make contents of a generic TabGroup component compatible with the window system. They are rendered via
<svelte:component this={TabComponent} />
. This means I need to access the name of the component at runtime in order to render it in the new window as I cannot know beforehand (the component name and props are passed via URL parameter andpostMessage
).Take this REPL as an example https://svelte.dev/repl/af0f92d5cb5f4dbfb9518287baa81497?version=3.38.3
In dev (
npm run dev
):In production (
npm run build
):Describe the proposed solution
On a per-component basis I'd like to enable a new static property of the component class, e.g.
displayName
so that I can access the name at runtime likeMyComponent.displayName === 'MyComponent'
This needs to be per-component because otherwise with hundreds of components this would increase bundle size even if you don't need it for every single component.
Alternatives considered
I guess I could manually maintain this in a
<script context="module">
block?Importance
would make my life easier
The text was updated successfully, but these errors were encountered: