Repository navigation
Serve ES modules with a wrapper the browser accepts - #892
Open
karenrasmussen wants to merge 1 commit into
Open
karenrasmussen wants to merge 1 commit into
karenrasmussen wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Kanopy rebuilt its frontend and now ships it as an ES module. The page loads through Via but never boots: the browser discards the bundle before running a line of it, leaving Kanopy's loading screen up forever.
pywbwraps every script it serves in a block which redeclareswindow,locationand the rest so wombat can proxy them.A module rejects that wrapper twice over, it declares
let arguments, which strict mode forbids, and it encloses the module'sexportin a block.pywbhas no notion of modules at all: every<script src>maps to the classic JS modifier whatever its type. This is a knownpywbbug, open since 2022 (webrecorder/pywb#771 for the strict mode error, #964 for the enclosedexport, #764 tracking the fix). 2.10.0 doesn't address it, so upgrading isn't a way out.Changes
A modifier of our own,
esm_, applied to<script type="module">and<link rel="modulepreload">, and a rewriter which serves what carries it:pywb's own wrapper minuslet argumentsand minus the block. The block can go because a module's outermost scope is already its own, a classic script's is the global scope, which is whypywbneeds one. Dropping it also leaves theexportat the top level, where it must be.