js: track document.currentScript instead of hardcoding it to null - #159
Merged
Merged
Conversation
document.currentScript was unconditionally null, so the standard Webpack/Turbopack idiom of reading document.currentScript.src to compute a chunk-loading base path always got an empty result outside a Worker. Found live on tailwindcss.com: its Turbopack runtime threw "chunk path empty but not in a worker" for every one of 10 lazily- loaded chunks. Fixed by tracking the synchronously-executing <script> node (binder.currentScript), set immediately before and cleared immediately after each execute() call in runScripts -- matching the real spec exactly, including going back to null inside a later timer callback. A pre-existing test had encoded the old always-null behaviour as its own expectation; updated to check `instanceof HTMLScriptElement` instead of relying on incidental string output. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
document.currentScriptwas unconditionally hardcoded tonull, so the standard Webpack/Turbopack idiom of readingdocument.currentScript.srcto compute a chunk-loading base path always got an empty result outside a Worker.Engine.JSLogsweep: its Turbopack runtime threwError: chunk path empty but not in a workerfor every one of 10 lazily-loaded chunks.<script>node (binder.currentScript), set immediately before and cleared immediately after eachexecute()call inrunScripts— matching the real spec exactly: non-null only for a synchronously-running classic script, null again inside a later timer/callback.TestDocumentMisc) had encoded the old always-null behaviour as its own expectation (asserting the running script's owncurrentScriptstringifies to"null"); updated it to checkinstanceof HTMLScriptElementinstead, which is both correct and more informative.Engine.JSLogsweep shows all 10 "chunk path empty" failures gone with nothing else on any of the ten corpus pages affected.Test plan
TestDocumentCurrentScriptIdentifiesTheRightScriptAndClearsAfterwardsadded (js/js_test.go) — covers identifying the right script among several, and going back to null inside a timer callbackTypeErrorwhen the source fix is revertedgo test ./...green; css/layout/paint/dom/paginate coverage floors re-checked (99.5%/100.0%/100.0%/98.1%/100.0%, unaffected — this fix lives injs, not itself coverage-gated)bench/cmd/comparerun against real headless Chrome; tailwindcss.com SSIM essentially flat (0.7053→0.7038, expected — the newly-loading chunks are plausibly lazy/deferred content outside the compared region)🤖 Generated with Claude Code