Skip to content

Don't use global variables in scripts/package/node/core.js and core/utils/xml.ts #6725

@cpcallen

Description

@cpcallen

Describe the bug

Due to the use of global variables to pass some (but not all) items obtained from the jsdom package from scripts/package/node/core.js to core/utils/xml.ts, XML serialisation (and therefore Blockly generally) is broken if:

  1. Blockly is being loaded in node.js (or another runtime that does not have a native DOM implementation), and
  2. more than one copy of Blocly is loaded.

Normally modules cannot be loaded more than once, but multiple copies of a module with different paths, or a single copy that is included in more than one (e.g. webpack) bundle, can defeat the usual deduping of loads to satisfy imports and requires.

Specifically, due to this bug, the @blockly/dev-scripts's test script, used by plugin developers (including us), is broken when used to test a project with more than one test/*.mocha.js test harness when using Blockly v9.2.0.

To Reproduce

Steps to reproduce the behavior:

  1. Clone blockly-samples.
  2. Choose any plugin with more than one test script in its test/ drirectory, where at least one of those tests creates a block.
  3. Run npm upgrade blockly to bump blockly to 9.2.0.
  4. Run npm test
  5. Observe test errors.

Expected behaviour

Test should pass; no errors should occur.

Stack Traces

     TypeError: Failed to execute 'serializeToString' on 'XMLSerializer': parameter 1 is not of type 'Node'.
      at Object.exports.convert (webpack-internal:///./node_modules/jsdom/lib/jsdom/living/generated/Node.js:25:9)
      at XMLSerializer.serializeToString (webpack-internal:///./node_modules/jsdom/lib/jsdom/living/generated/XMLSerializer.js:111:23)
      at domToText$$module$build$src$core$utils$xml (webpack-internal:///./node_modules/blockly/blockly_compressed.js:74:333)

Additional context

See this lengthy discussion for more detail about the issue.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions