-
Notifications
You must be signed in to change notification settings - Fork 6k
Add the ability to change the CanvasKit url at runtime. #27342
Add the ability to change the CanvasKit url at runtime. #27342
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| /// | ||
| /// This calls `CanvasKitInit` and assigns the global [canvasKit] object. | ||
| Future<void> initializeCanvasKit() { | ||
| Future<void> initializeCanvasKit({String? canvasKitBase}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where to we get and pass the value of canvasKitBase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking either pass it in setUpCanvasKitTests or read it from a <meta> tag in index.html
yjbanov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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](flutter/engine#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:
* #126131 (and others)
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
* flutter/engine#42941
## 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
**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
**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

Allows setting the CanvasKit URL at runtime. Useful in tests to allow using a local version of CanvasKit and reducing flakiness.
This will allow us to cache the CanvasKit files on LUCI: flutter/flutter#86125
Pre-launch Checklist
writing and running engine tests.
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.