Skip to content

Instantly share code, notes, and snippets.

@jkrems
Last active February 27, 2020 15:51
Show Gist options
  • Save jkrems/6875ca31c00686c78f8119f59b852e05 to your computer and use it in GitHub Desktop.
Save jkrems/6875ca31c00686c78f8119f59b852e05 to your computer and use it in GitHub Desktop.
Observe compilation cache collision

Repro

  1. Start the server via node server.js.
  2. Open http://localhost:3000.
  3. If the compilation cache leads to bad meta data in dynamic import, the message should only be logged once. ‎‎​
document.getElementById('target').innerText += `running ${import.meta.url}\n`;
if (import.meta.url.length < 100) {
import('./x/a.mjs');
}
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
</head>
<pre id="target"></pre>
<script type="module" src="./a.mjs"></script>
</html>
const { createServer } = require('http');
const { readFileSync } = require('fs');
createServer((req, res) => {
const url = new URL(`http://${req.headers.host}/${req.url}`);
let filename = url.pathname.split('/').pop();
let contentType = 'application/javascript';
if (!filename.endsWith('.mjs')) {
filename = 'index.html';
contentType = 'text/html';
}
res.setHeader('Content-Type', contentType);
res.end(readFileSync(filename));
}).listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment