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

HMR code is added to stringified JavaScript in markup #1653

Closed
milkbump opened this issue Jun 8, 2021 · 2 comments
Closed

HMR code is added to stringified JavaScript in markup #1653

milkbump opened this issue Jun 8, 2021 · 2 comments

Comments

@milkbump
Copy link

milkbump commented Jun 8, 2021

Describe the bug
When JavaScript is in a string, HMR code is inserted into it.

<code>
{`
const product = 1 * 1;

export default product;
`.trim()}
</code>

is displayed in the browser as

const product = 1 * 1; import * as ___SVELTE_HMR_HOT_API from '/sveltekit-javascript-repro/node_modules/svelte-hmr/runtime/hot-api-esm.js';import { adapter as ___SVELTE_HMR_HOT_API_PROXY_ADAPTER } from '/sveltekit-javascript-repro/node_modules/svelte-hmr/runtime/proxy-adapter-dom.js';if (import.meta && import.meta.hot) { if (false) import.meta.hot.accept(); product = ___SVELTE_HMR_HOT_API.applyHmr({ m: import.meta, id: "/sveltekit-javascript-repro/src/routes/index.svelte", hotOptions: {"preserveLocalState":false,"noPreserveStateKey":["@hmr:reset","@!hmr"],"preserveAllLocalStateKey":"@hmr:keep-all","preserveLocalStateKey":"@hmr:keep","noReload":false,"optimistic":true,"acceptNamedExports":true,"acceptAccessors":true,"injectCss":false,"cssEjectDelay":100,"native":false,"importAdapterName":"___SVELTE_HMR_HOT_API_PROXY_ADAPTER","noOverlay":true}, Component: product, ProxyAdapter: ___SVELTE_HMR_HOT_API_PROXY_ADAPTER, acceptable: true, preserveLocalState: false, emitCss: true, }); } export default product;

Repro
https://github.com/kwangure/sveltekit-javascript-repro

Expected behavior
HMR code should not be injected into strings.

SvelteKit installation information

System:
OS: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
CPU: (4) x64 Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
Memory: 1.56 GB / 3.05 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 16.2.0 - /usr/bin/node
npm: 7.13.0 - /usr/bin/npm
npmPackages:
@sveltejs/adapter-static: ^1.0.0-next.13 => 1.0.0-next.13
@sveltejs/kit: ^1.0.0-next.113 => 1.0.0-next.113
svelte: ^3.38.2 => 3.38.2

  • Chrome

Severity
It's not severe, but it it annoying. It's possible to work around it by escaping/HTML-encoding the JS text.

I'm not sure whether this is something to be solved at the vite-plugin-svelte or svelte-hmr level. I can move the issue to the appropriate repro as needed.

Somewhat related issue: #1654

@Conduitry
Copy link
Member

svelte-hmr is responsible for doing its own HMR injection, and so I think that would be the best repo for this issue.

@milkbump
Copy link
Author

milkbump commented Jun 8, 2021

Noted. Issue filed. Thanks.

@milkbump milkbump closed this as completed Jun 8, 2021
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

2 participants