Skip to content

Conversation

parlough
Copy link
Member

@parlough parlough commented Aug 29, 2025

Previously web/inject_dartpad.dart was just written as a script for dart.dev and docs.flutter.dev, but the logic wasn't really reusable in other contexts and didn't have much error handling. This PR rewrites and moves the core logic into a new library and class at lib/inject_dartpad.dart that other clients can take advantage of through using this package as a git dependency.

Besides being a public library, the new library also makes a few improvements over the original script.

  • Each embed independently handles its initialization and code update, resulting in shorter delays.
  • Lazily loads embeds outside the current viewport.
  • Replaces usage of jsify with directly constructing the appropriate JS object.
  • Adds handling and helpful error messages for when the embed isn't successfully added to the DOM.

The script in web/inject_dartpad.dart was then updated to use the new library, with a few additional improvements:

  • Concurrently initializes multiple embeds rather than one at a time.
  • Gracefully falls back to showing the code if DartPad fails to load in each iframe.
  • Reuses an embed's index compared to others on the page for its iframe ID, simplifying the set up logic.

\cc @craiglabenz Since I can't assign you as a reviewer. I guess you don't have write access to this repo.

@parlough parlough requested a review from johnpryan August 29, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant