Skip to content
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

Headless Workspaces Require a Theme to Be Defined #2575

Closed
BeksOmega opened this issue Jun 13, 2019 · 3 comments
Closed

Headless Workspaces Require a Theme to Be Defined #2575

BeksOmega opened this issue Jun 13, 2019 · 3 comments
Assignees
Labels
component: themes issue: bug Describes why the code or behaviour is wrong

Comments

@BeksOmega
Copy link
Collaborator

Problem statement

Headless workspaces require a theme to be defined, even though they are not rendered.

Expected Behavior

I can create themed blocks on a headless workspace.

Actual Behavior

I recieve an error.

Steps to Reproduce

  1. Disable the changeTheme function of the playground.
  2. Remove all of the code from the start function and replace it with the below:
  var altWorkspace = new Blockly.Workspace();
  // JSON block def.
  var block = new Blockly.Block(altWorkspace, 'controls_if');
  // JS block def.
  var block = new Blockly.Block(altWorkspace, 'text_getSubstring');

Stack Traces

block.js:1520 Block "controls_if": Style does not exist:  logic_blocks
  Blockly.Block.jsonInitStyle_ @ block.js:1520
  Blockly.Block.jsonInit @ block.js:1426
  (anonymous) @ blockly.js:414
  Blockly.Block @ block.js:181
  start @ playground.html:146
  onload @ playground.html:429

block.js:975 Uncaught Error: Trying to set block style to text_blocks before theme was defined via Blockly.setTheme().
    at Blockly.Block.setStyle (block.js:975)
    at Blockly.Block.init (text.js:224)
    at new Blockly.Block (block.js:181)
    at start (playground.html:147)
    at onload (playground.html:429)

Additional Information

Just noticed this when I was writing some unit tests, and thought I should send it in.

Oh I also noticed that colour functions (some of them my own additions) are defined on the block rather than the rendered block, not sure if this is intensional.

@alschmiedt alschmiedt added affects: develop component: themes issue: bug Describes why the code or behaviour is wrong labels Jun 13, 2019
@alschmiedt alschmiedt self-assigned this Jun 13, 2019
@alschmiedt
Copy link
Contributor

I think this and #2540 are related

@kbruneel
Copy link

I have the same problem. Is there a workaround?

code:

var Blockly = require('node-blockly/browser');
var xml = Blockly.Xml.textToDom(xml_text);
var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace);
var code = Blockly.JavaScript.workspaceToCode(workspace);

error:

Error: Trying to set block style to procedure_blocks before theme was defined via Blockly.setTheme().
    at module.exports.Blockly.Block.setStyle (blockly_compressed_browser.js:1460)
    at module.exports.Blockly.Block.init (blocks_compressed_browser.js:106)
    at new module.exports.Blockly.Block (blockly_compressed_browser.js:1440)
    at module.exports.Blockly.Workspace.newBlock (blockly_compressed_browser.js:1029)
    at Object.module.exports.Blockly.Xml.domToBlockHeadless_ (blockly_compressed_browser.js:993)
    at Object.module.exports.Blockly.Xml.domToBlock (blockly_compressed_browser.js:990)
    at Object.module.exports.Blockly.Xml.domToWorkspace (blockly_compressed_browser.js:986)

@kbruneel
Copy link

The following seems to work:

var Blockly = require('node-blockly/browser');
Blockly.setTheme(Blockly.Themes.Classic);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: themes issue: bug Describes why the code or behaviour is wrong
Projects
None yet
Development

No branches or pull requests

4 participants