Skip to content

fix blocks rendering for code eval tool#11420

Open
srietkerk wants to merge 1 commit into
masterfrom
srietkerk/fix-code-svg-render
Open

fix blocks rendering for code eval tool#11420
srietkerk wants to merge 1 commit into
masterfrom
srietkerk/fix-code-svg-render

Conversation

@srietkerk

Copy link
Copy Markdown
Contributor

Fixes microsoft/pxt-microbit#6936

Via copilot, because I think it's a nice summary:
The code was looking up the renderer style element using document.getElementById('blockly-renderer-style-pxt-classic'), but Blockly (since the v11/v13 upgrades) creates this element with className="blockly-renderer-style", not an id. So, the lookup returned null, and the critical CSS rules for text fill color and font-family were silently omitted from the rendered SVG.

Without these CSS rules:
Text defaults to fill: black (SVG default) instead of white
Font falls back to the browser default instead of the configured monospace font

I also looked at the other blocks-svg scenarios with this change and they all look good!

Upload target: https://makecode.microbit.org/app/e5b98b20f43e1b7a1f340e51bb8818e4f3b613d8-a84451c729--eval

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes block rendering in the code-eval tool’s SVG export path by correctly including Blockly’s renderer-injected CSS after the Blockly v11/v13 changes, ensuring text color and font-family rules are preserved in the rendered SVG output.

Changes:

  • Update renderer style lookup to use the style.blockly-renderer-style class (instead of a non-existent blockly-renderer-style-pxt-classic id).
  • Correct the DOM element type used when reading blockly-common-style CSS.

Comment thread pxtblocks/layout.ts
Comment on lines +410 to +413
customCss.unshift((document.getElementById(`blockly-common-style`) as HTMLStyleElement)?.innerText || "");
// Blockly injects renderer styles with className="blockly-renderer-style", not an id
const rendererStyle = document.querySelector(`style.blockly-renderer-style`) as HTMLStyleElement;
customCss.unshift(rendererStyle?.innerText || "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Evaluation] Block style in block-picker modal is inconsistent with Block editor

2 participants