-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix language loading problems #6123
Comments
Ok, I think I understand the issue here. Modules BackgroundInside For example:
The global Before we moved to And now, things inside compressed only look at the module junk not the tree. TimelineSo in the "just one tree period" of Blockly, when we did But now in the "tree + module junk period" of Blockly, when we did Then after #6060 However, because
This means that SolutionMy suggestion is that:
|
We've submitted a fix for this that we hope should work for all methods of loading (module systems, and script tags). For anyone following this issue, could you try this beta version: If we get feedback that it works, then we can release an actual patch for the wider world! Thanks, |
@Maribeth created PR #6060 to solve a problem with language loading. The problem was that, prior to that PR:
The wrappers generated for
dist/msg/*.js
:Blockly
object to thefactory
function,Blockly
local variable set to{Msg: {}}
,Blockly.Msg
object from the factory function,Blockly.Msg
with theMsg
object created in step 2.Overwriting the global
Blockly.Msg
object with a new object was really wrong but pretty much worked:goog.provides
days all accesses to this dictionary were via the globalBlockly.Msg
, so they would see the replacement object.core/msg.js
: use named export, removedeclareLegacyNamespace
#5768, closure compiler would compile accesses to theMsg
dictionary object into$.Blockly.Msg.MESSAGE_NAME
, and since$.Blockly
was the globalBlockly
object these would see the replacement object. Oh yes: and the compiler doesn't bother runningObject.freeze
on module export objects, so the overwrite would not blow up.*After refactor: convert some block generators to goog.module #5769, in uncompiled mode, the exports object of
Blockly.Msg
was frozen, but the.Msg
property on thecore/blockly.js
exports object was not. OverwritingBlockly.Msg
would have had no effect (no messages would have been loaded in to the dictionary object used bycore/
code)—but uncompiled mode users (e.g. the playground) load messages frommsg/messages.js
which does not have the wrapper code that does this overwrite but instead just sets individual properties on theBlockly.Msg
object (which is presumed already to exist), so everything worked fine here too.After refactor: convert some block generators to goog.module #5769, closure compiler compiles accesses to the
Msg
dictionary object into$.module$exports$Blockly$Msg.Msg.MESSAGE_NAME
, which would not have been affected by overwritingBlockly.Msg
(which would only set the value of$.module$exports$Blockly.Msg
, not used by any core code)—and so message loading fails.PR #6060 will fix the immediate problem, but may have some unintended consequences:
goog.provides
days—it may have been possible to load the language file first, then load Blockly, and have everything work. That has probably not been the case for a while, but it will definitely not be the case now.dist/msg/*.js
files could be loaded as CJS modules just for their exports (though they have the unfortunate side effect of not just overwritingBlockly.Msg
as noted), but now—though they will continue to export the (original, unique and correct)Blockly.Msg
dictionary object, it will no longer be possible to useBlockly.setLocale
to switch between languages, because if you load multiple language files (e.g. by usingrequire
in Node.js), each one will not only setBlockly.Msg
(as one would want) but would thereby overwrite the properties on the common "exports object".The latter is probably going to upset some folks.
So I think we need to find a way of having the language files do two of the three thing they did prior to #6060:
Blockly.Msg
as a side effect of the language file being loaded.Replace the.Blockly.Msg
dictionary with their export objectI think this should be done with a view to eventually making the language files side-effect free, as we are doing with the library blocks. Further, I think it would be preferable, if possible, to put as much of the code to effect all this in files generated in
msg/js/*.js
, which could perhaps become actualgoog.module
s (or failing that at least in the "compiled" files inbuild/msg/js/*.js
) rather than in the wrappers added indist/
, if for no other reason than to help avoid problems like this going unnoticed so easily.Originally posted by @cpcallen in #6060 (comment)
The text was updated successfully, but these errors were encountered: