Skip to content

fix: use raw Markdown editor instance when refreshing - #20320

Merged
danharrin merged 1 commit into
filamentphp:4.xfrom
people-sea:fix/issues/20313
Aug 4, 2026
Merged

fix: use raw Markdown editor instance when refreshing#20320
danharrin merged 1 commit into
filamentphp:4.xfrom
people-sea:fix/issues/20313

Conversation

@people-sea

@people-sea people-sea commented Aug 2, 2026

Copy link
Copy Markdown
Member

Description

Fixes: #20313

Supersedes: #20314

The CodeMirror instance was refreshed through Alpine's reactive proxy.

Use Alpine.raw() to refresh the underlying editor instance.

Visual changes

Before

before.mov

After

after.mov

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

@hamdyelbatal122

Copy link
Copy Markdown
Contributor

@people-sea, thanks for taking a look at this issue!

I noticed a couple of things that might be worth discussing:

  1. Source file not updated The changes here only touch the compiled dist/ file. The source at packages/forms/resources/js/components/markdown-editor.js is unchanged, which means the fix would be overwritten on the next npm run build.

  2. The root cause is still there The core issue is that CodeMirror tries to measure character coordinates while the editor is inside a hidden container (collapsed section, inactive tab, etc.). Adding Alpine.raw() to the refresh() call helps avoid the proxy issue, but the editor still initializes eagerly inside the hidden container and CodeMirror will still throw when it can't measure anything.

For example, if you put a MarkdownEditor inside a collapsed Section and load the page — CodeMirror will still fire up immediately and try to call getBoundingClientRect() on elements that have zero dimensions. That's where the TypeError comes from, and Alpine.raw() alone doesn't prevent that from happening.

In #20314, I took a different approach: the editor simply doesn't initialize until its container is actually visible. This way CodeMirror never runs into the measurement problem in the first place.

Happy to discuss if you see it differently!

@danharrin danharrin added bug Something isn't working pending review labels Aug 4, 2026
@danharrin danharrin added this to the v4 milestone Aug 4, 2026
@danharrin
danharrin merged commit b9e8e1d into filamentphp:4.x Aug 4, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught TypeError: Cannot read properties of undefined (reading 'map') on markdown-editor.js

3 participants