-
Notifications
You must be signed in to change notification settings - Fork 20
Fix 'require.js' load issue while loading web page + add explanation on how to use on web + make it easier to integrate this lib on a project #13
Conversation
…web page Without this fix, the web page will not load the 'require.js' before the 'sqflite_web.js' which had bad behavior on web pages: """ sqflite_web.js:1 Uncaught ReferenceError: requirejs is not defined at sqflite_web.js:1 """ This commit will fix this as it will now add a console log to warn developer they forget to include the 'require.js' in their index.html file This change doesn't break existing behavior (except giving a warning in log and improving include logic to use less ressources)
…external 'sql-wasm.wasm' and 'sql-wasm.js' were taken from cloudflare source. This commit changes this logic in order to have all files in the library to not depend to any other website than the one hosting the project. This is currently using version 1.4.0 (latest for the moment)
Example of project using this fix (link may not work sometimes, just here for showing it is working without issue): https://www.funnyapps.funnylabz.com/facts/web/ |
Thanks, let's discuss this first. There was an issue with RequireJS and I lost track of how it stands now: dart-lang/sdk#33979 Do you think the problem has been solved in the meantime? |
Also see this: flutter/flutter#56659 but this seems to be determined not to be supported, definitively. |
As I understand after some Flutter/Dart repo fast verifications:
Not sure if this helps you ? |
After some thinking, I have some doubt about puting sql-wasm internally (assets may be added on "non web" platform assets...) |
What the pull request is doing now
Why did I reversed the
|
Help me before I decide on this. I have an ongoing problem that I think is related to what you suggest here. Every time I use any of my plugins that wants to bring any other standard JS AMD module, I get the "requirejs not defined" error. It seems that you have to deal with the same problem. However, I have another solution that might or might not be relevant. In my experience, the real problems is that CanvasKit itself is packaged as an anonymous module. I suggested the Flutter team to make it named many moons ago, I lost track, the issue is still there, and even not supposed to be fixed. I found the link: flutter/flutter#58428 A solution I found was to use my own CanvasKit JS and WASM instead of the standard one, host it on my website and modify So, in some ways, this definitely seems related, in other ways, I have to get up to speed with how things are now because it was a couple of months ago that I last looked into anything similar. |
And now that I checked with the current Flutter, this whole manual change might not be needed at all any more. What might well mean that things have overtaken me in the meantime. :-) I'm particulary interested in "but this will imply users do a 'refresh' of the web page every time they want to access it because of dynamic include issues" because I use the same scheme in at least three other internal plugins of mine. I never saw this until yesterday when I started to include the app of one of those in an IFRAME. There I need to reload but I don't need it in the main app itself. I'd very much like to avoid the need to force to change the |
I merged it and will experiment with the differences in the approach. Yes, no probem with the formatting, my Android Studio using |
Including the requirejs directly from <script src="assets/packages/sqflite_web/assets/require.js" type="application/javascript"></script> It is only what I see while doing my test. There is no proof there. But from what I see on other issues you created on Flutter repo + answers + repo content, my solution is the only one if we want it to be working in long term... (no support from Flutter on this)
When not including require.js directly in index.html and doing it in the dart script instead, I got the "requirejs not defined" error in the first page load. When we refresh the web page, it then works fine (browser cache maybe). In the other hand, if I include it directly in the index.html, then I never have such an issue. I think this behavior is due to the fact the require.js is "heavy" (1MB) and will then load not fast enough before the lib needs require.js when you do it from dart.
:) |
Note that testing in local will make it hard to reproduce the issue I tried to fix here. |
Yes, this is what I saw, too. First, I tried to play with various As to |
Sqflite is already ready for null safety:
It seems to be quite boring to handle both as it means maintain 2 branches. |
Oh, well, I didn't even check, just saw that my project didn't pull them for some reason... No, I would be perfectly happy with a single version... :-) |
Here are all the improvements: