Skip to content

Conversation

@ditman
Copy link
Member

@ditman ditman commented Jun 16, 2023

Flutter web uses requireJS in debug mode to assemble a DDC-compiled app from a bunch of small files ("modules").

This caused that canvaskit.js (and all other modules that used a browserify-like loading header) didn't work because they attempted to use the define function provided by Flutter's instance of requireJS (which kept the defined modules private, rather than as globals on the page, as the users of the JS expected).

A fix was added to flutter/engine to trick loaders into not using the requireJS module loader, but a recent change in the fix's js-interop layer subtly changed its JS output on the page (objects went from undefined to null), causing this:

This PR hides a bit of code that is commonly used by module loaders to decide that they may use the define function provided by requireJS (so the engine workaround can be removed).

Next steps

Issues

Partially addresses: #126131 (and others)

Tests

  • Added a unit test to ensure the delete stays
  • Manually tested with the Gallery app in debug mode with a bunch of user-supplied scripts that currently fail to load.
    • Also tested hot restart as suggested by @nshahan

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jun 16, 2023
// Prevent DDC's requireJS to interfere with modern bundling.
if (typeof define === 'function' && define.amd) {
// Preserve a copy just in case...
define._amd = define.amd;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit is probably unnecessary. I'm not sure how anybody could be relying on this, when this is only exposed in debug mode (unless they're publishing the debug version of their web app, 😱)

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ditman added a commit to ditman/flutter-engine that referenced this pull request Jun 16, 2023
After flutter/flutter#129032, this shouldn't be needed anymore.
@christopherfujino
Copy link
Contributor

@ditman is this one ready to merge?

@ditman
Copy link
Member Author

ditman commented Jun 22, 2023

@christopherfujino yes, but I'm gardening for flutter/packages and was waiting until monday to land this, so I can pay attention to potential breakages caused by this. I'll add the autosubmit label and let the bot do its thing :P

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 22, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Jun 23, 2023

auto label is removed for flutter/flutter, pr: 129032, Mergeability of pull request flutter/flutter/129032 could not be determined at time of merge..

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2023
@ditman

This comment was marked as outdated.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Jun 23, 2023

auto label is removed for flutter/flutter, pr: 129032, due to - The status or check suite Windows build_tests_1_4 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2023
@ditman
Copy link
Member Author

ditman commented Jun 23, 2023

Try again, again, my beloved bot!

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 26, 2023
ditman added a commit to ditman/flutter-engine that referenced this pull request Jun 26, 2023
After flutter/flutter#129032, this shouldn't be needed anymore.
auto-submit bot pushed a commit to flutter/engine that referenced this pull request Jun 27, 2023
**This must land _after_ flutter/flutter#129032

Flutter web uses requireJS in `debug` mode to assemble a DDC-compiled app from a bunch of small files ("modules").

This caused that `canvaskit.js` (then, but probably all other modules that used a browserify-like loading header) didn't work because it attempted to use the `define` function provided by Flutter's instance of `requireJS` (which kept the defined modules private, rather than as globals on the page, as the users of the JS expected).

A [fix](#27342) was added to `flutter/engine` to trick loaders into *not* using the `requireJS` module loader, but a recent change in the fix's js-interop layer *subtly* changed its JS output on the page (objects went from `undefined` to `null`), causing this:

* flutter/flutter#126131 (and others)

After flutter/flutter#129032, the engine fix shouldn't be required anymore, so this PR removes it.

## Issues

* Fixes flutter/flutter#126131 (and possibly others)

## Testing

* Manually tested with some test apps, and miscellanous JS scripts as reported by users.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
kjlubick pushed a commit to kjlubick/engine that referenced this pull request Jul 14, 2023
**This must land _after_ flutter/flutter#129032

Flutter web uses requireJS in `debug` mode to assemble a DDC-compiled app from a bunch of small files ("modules").

This caused that `canvaskit.js` (then, but probably all other modules that used a browserify-like loading header) didn't work because it attempted to use the `define` function provided by Flutter's instance of `requireJS` (which kept the defined modules private, rather than as globals on the page, as the users of the JS expected).

A [fix](flutter#27342) was added to `flutter/engine` to trick loaders into *not* using the `requireJS` module loader, but a recent change in the fix's js-interop layer *subtly* changed its JS output on the page (objects went from `undefined` to `null`), causing this:

* flutter/flutter#126131 (and others)

After flutter/flutter#129032, the engine fix shouldn't be required anymore, so this PR removes it.

## Issues

* Fixes flutter/flutter#126131 (and possibly others)

## Testing

* Manually tested with some test apps, and miscellanous JS scripts as reported by users.

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants