parcel icon indicating copy to clipboard operation
parcel copied to clipboard

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

Open benmosher opened this issue 2 years ago • 0 comments

🐛 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)

benmosher avatar Sep 16 '22 18:09 benmosher