Open NessDan opened 1 year ago
In theory Parcel should process srcdoc with this change:
diff --git packages/transformers/html/src/inline.js packages/transformers/html/src/inline.js
index 9cecc7d2f..b542094ca 100644
--- packages/transformers/html/src/inline.js
+++ packages/transformers/html/src/inline.js
@@ -146,6 +146,40 @@ export default function extractInlineAssets(
}
}
+ if (node.tag === 'iframe') {
+ let value = node.attrs?.srcdoc;
+ if (value != null) {
+ if (!node.attrs) {
+ node.attrs = {};
+ }
+ // allow a script/style tag to declare its key
+ if (node.attrs['data-parcel-key']) {
+ parcelKey = node.attrs['data-parcel-key'];
+ }
+ node.attrs['data-parcel-key'] = parcelKey;
+ asset.setAST(ast); // mark dirty
+
+ asset.addDependency({
+ specifier: parcelKey,
+ specifierType: 'esm',
+ });
+
+ parts.push({
+ type: 'html',
+ content: value,
+ uniqueKey: parcelKey,
+ bundleBehavior: 'inline',
+ meta: {
+ type: 'tag',
+ // $FlowFixMe
+ node,
+ startLine: node.location?.start.line,
+ },
+ });
+ asset.setAST(ast);
+ }
+ }
+
// Process inline style attributes.
let attrs = node.attrs;
let style = attrs?.style;
But that leads to an infinite loop currently...
π bug report
This is a very popular way to lazy load a YouTube video.
The problem is that after Parcel runs on an HTML page doing this strategy of content-stuffing in the
<iframe srcdoc="...">
, the image that acts as the poster won't get compiled into the distribution, leading to a broken image.π Configuration (.babelrc, package.json, cli command)
π€ Expected Behavior
It should parse over the image in question (
/media/images/social-media-share.webp
) and should update that reference and copy the file to thedist/
folder.π― Current Behavior
The reference to the image stays the same on the iframe and the image is never copied over to the
/dist
folder.π Possible Solution
Since this is a popular way to lazy load YouTube iframes, maybe parse and support this.
π¦ Context
Trying to parcel my site (all vanilla HTML / JS) so that I can tree-shake for things like Firebase. Can't because this breaks the homepage iframe.
π» Code Sample
Make sure to create an image file named
/social-media-share.webp
as a sibling to the HTML file below:π Your Environment