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

bundle-text: returns file hash (or something like it) instead of contents for HMR updates. #8481

Open
benmosher opened this issue Sep 16, 2022 · 2 comments
Labels

Comments

@benmosher
Copy link

🐛 bug report

When using bundle-text:, hot reloading results in the text being a hash instead of the file content after the file is modified.

🎛 Configuration (.babelrc, package.json, cli command)

{
  "extends": [
    "@parcel/config-default",
    "../icons/.parcelrc" // for sprites
  ],
  "compressors": {
    "*.{html,css,js,svg,map}": [
      "...",
      "@parcel/compressor-gzip"
    ]
  }
}

icons/.parcelrc: (shouldn't matter but just in case?)

{
  "transformers": {
    "sprite:*.svg": ["parcel-transformer-svg-sprite"],
    "sprite:*.js": ["..."],
  },
  "packagers": {
    "*.html": "parcel-packager-svg-sprite"
  }
}

🤔 Expected Behavior

import contents from "bundle-text:./file.xml"

contents is a string containing the file content on initial render, and after HMR updates.

😯 Current Behavior

contents is the file contents at initial page load, but is presented as a hash string of the contents if the file is modified. Refreshing the page results in contents containing the file contents inline again.

💁 Possible Solution

Could be crosstalk between react-fast-refresh and HMR, perhaps?

Creating my own module.hot?.accept() didn't seem to make any difference.

🔦 Context

I have a handful of XML files (not RSS/Atom!) that I am loading and parsing. Eventually these will be requested from the backend but for the moment I'm prototyping with them locally.

I was hoping to use import * as files from 'bundle-text:./*.xml' which, again, works great on the initial page load but as I'm tweaking the XML I'd like to get hot reloads.

I am working around this with e.g.:

const BEN_TEST = fs.readFileSync(__dirname + '/ben-test.xml', 'utf8')
const HELLO_WORLD = fs.readFileSync(__dirname + '/hello-world.xml', 'utf8')

These do update via HMR correctly, as expected, when modified.

💻 Code Sample

🌍 Your Environment

Software Version(s)
Parcel 2.7.0
Node v18.7.0
npm/Yarn Yarn 3.1.1
Operating System macOS Monterey 12.5.1 (21G83)
@mischnic mischnic added 🐛 Bug HMR Hot Module Reloading labels Oct 14, 2022
@cairomassimo
Copy link

Same issue here.
Seems to occur with data-url: as well. After HMR, the entire URL is replaced with a hash string (not a valid URL anymore).

@cairomassimo
Copy link

Made a couple of tests:

  • issue affects [email protected] as well
  • issue occurs also with the following configuration
{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.md": [
      "@parcel/transformer-inline-string"
    ]
  }
}

and

import content from "./file.md";

export function Component() {
    return <>{content}</>;
}

@github-actions github-actions bot added the Stale Inactive issues label Apr 16, 2023
@mischnic mischnic removed the Stale Inactive issues label Apr 16, 2023
@parcel-bundler parcel-bundler deleted a comment from github-actions bot Apr 16, 2023
@github-actions github-actions bot added the Stale Inactive issues label Oct 13, 2023
@mischnic mischnic removed the Stale Inactive issues label Oct 16, 2023
@parcel-bundler parcel-bundler deleted a comment from github-actions bot Oct 16, 2023
@github-actions github-actions bot added the Stale Inactive issues label Apr 13, 2024
@mischnic mischnic added ✔️ Confirmed Bug and removed Stale Inactive issues labels Apr 22, 2024
@parcel-bundler parcel-bundler deleted a comment from github-actions bot Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants