Skip to content

svelte:component doesn't work on build mode #6980

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
ifraixedes opened this issue Dec 2, 2021 · 8 comments
Closed

svelte:component doesn't work on build mode #6980

ifraixedes opened this issue Dec 2, 2021 · 8 comments

Comments

@ifraixedes
Copy link

Describe the bug

We have a small frontend that used svelte:component directive to render some components dynamically.

In development mode (i.e. npm run dev) the frontend worked perfectly, however, when it's compiled for production (i.e npm run build) it doesn't work.

The frontend doesn't report any error but it doesn't render the dynamic component; it is like if the svelte:component isn't there.

Reproduction

Repository with the specific tag version and the directory where the frontend is that allows reproducing the bug: https://github.com/storj/storj/tree/v1.44.1/satellite/admin/ui

In order to reproduce, you can clone the repository, checkout the commit, and go to the satellite/admin/ui directory.

First, try with npm run dev and then with npm run build and serve the assets with a simple HTTP server (e.g. https://github.com/projectdiscovery/simplehttpserver).

  1. Visit the page
  2. Enter whatever thing in the input box and press enter or click the confirm button
  3. It will appear a select box, select something (e.g. user)
  4. It will appear another select box next to the previous one, select something (e.g. get)
  5. Some description and input elements will appear below.

While you will see that 5 it's what happens when running in dev mode, it doesn't happen when serving the build assets, only the text will be there but no input element will be rendered.

The component that uses the svelte:component directive is src/UIGenerator.svelte, line 56

Logs

Nothing is reported in the web console in any of the modes (`dev` and `build`).

System Info

The linked repo in that commit contains everything.

Severity

annoyance

@storjBuildBot
Copy link

Change https://review.dev.storj.io/c/storj/storj/+/6435 mentions this issue.

@ifraixedes
Copy link
Author

The above comment is autogenerated by a bot because I've sent a commit, which mentions this issue, with a workaround until this bug (in case that it's) is fixed.

@kevmodrome
Copy link
Contributor

Can you make a reduced reproduction showing when it breaks? This doesn't sound like an issue with Svelte but more of an error in your application

@Prinzhorn
Copy link
Contributor

constructor.name will not be what you expect, see #6537

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Dec 2, 2021

There is no error message because https://svelte.dev/docs#svelte_component

If this is falsy, no component is rendered.

@Conduitry
Copy link
Member

👍 As @Prinzhorn indicated, you will either need to rely on something other than the constructor name, or make sure that when you minify things, you tell Terser not to mangle names.

@ifraixedes
Copy link
Author

ifraixedes commented Dec 2, 2021

not to mangle names

that's the point that I needed for understanding why it worked in dev and didn't with build, which made me believe that there was a bug in the build process.

Thanks, @Conduitry, and the rest, and my apologies for the noise.

@storjBuildBot
Copy link

Change https://review.dev.storj.io/c/storj/storj/+/6439 mentions this issue.

storjBuildBot pushed a commit to storj/storj that referenced this issue Dec 17, 2021
I introduced a change in the UI that was a better way to dynamically
render Svelte components
(https://review.dev.storj.io/c/storj/storj/+/5931/4..5) during the
review of the first version of it, however, while it works perfectly
on development mode it doesn't work when the assets are built for
production, failing silently, because the constructor name get renamed
due to the name mangling caused by the minifyer as stated in the
following issue: sveltejs/svelte#6980

This commit use a different alternative not based on the constructor
name and it works fine with the production build.

Change-Id: I643c405f877a9206cf0e51b44d5138e5a9756a79
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

No branches or pull requests

5 participants