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 #34

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

HMR code is added to stringified JavaScript in markup #1653 #34

milkbump opened this issue Jun 8, 2021 · 3 comments

Comments

@milkbump
Copy link

milkbump commented Jun 8, 2021

Moving here from sveltejs/kit#1653

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.

@rixo
Copy link
Collaborator

rixo commented Jun 8, 2021

Good catch. I'll fix the regex doing that.

@rixo rixo closed this as completed in 0981070 Jul 16, 2021
@rixo rixo reopened this Jul 16, 2021
@rixo
Copy link
Collaborator

rixo commented Jul 16, 2021

@kafwangure This should be fixed with latest [email protected]. Can you confirm?

@rixo
Copy link
Collaborator

rixo commented Nov 15, 2021

Well... Let's say it is fixed. Feel free to reopen if not.

@rixo rixo closed this as completed Nov 15, 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