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

Markdown previewScripts new rendering behavior #136255

Closed
mjbvz opened this issue Nov 1, 2021 · 1 comment
Closed

Markdown previewScripts new rendering behavior #136255

mjbvz opened this issue Nov 1, 2021 · 1 comment
Assignees
Labels
api markdown Markdown support issues
Milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Nov 1, 2021

This issue documents the new rendering behavior of the markdown preview, specifically how it may effect previewScripts

Existing Behavior (Pre 1.63)

VS Code's markdown preview updates lives as the user types. To support this, we currently re-render the entire webview.

This means that any scripts on the page are restarted every time the preview contents are updated. These scripts could always count on running in a fresh environment with freshly rendered markdown content

This approach has a number of problems:

  • It is difficult to correctly maintain the original scroll position
  • Resources on the page are reloaded on every update
  • Scripts need to re-initialize themselves on every update

New behavior

Starting in 1.63, we'd like to migrate to use incremental dom updates for updating the markdown preview.

For preview scripts, this means that they are initialized once when the page first loads, but then are expected to handle any future markdown content updates that happen in the existing document. This change in behavior isn't a change for some scripts, but may cause unexpected behavior for others

Updating your preview scripts to support 1.63

The most common issue you may see after updating is that your script runs for the initial page render, but does not kick in for subsequent page updates. This is because preview scripts were written assuming the markdown on the page would only ever be rendered once, which is no longer true

To workaround this, add a new listener in your preview for the 'vscode.markdown.updateContent' custom event. This event is fired when the markdown content on the page has been updated:

window.addEventListener('vscode.markdown.updateContent', () => {
    // Update based on the new markdown content in the file
});
@mjbvz mjbvz added api markdown Markdown support issues labels Nov 1, 2021
@mjbvz mjbvz added this to the November 2021 milestone Nov 1, 2021
@mjbvz mjbvz self-assigned this Nov 1, 2021
mjbvz added a commit that referenced this issue Nov 2, 2021
@mjbvz
Copy link
Contributor Author

mjbvz commented Dec 6, 2021

Closing as this was just a notification for extension authors. Will also note this in the release notes

@mjbvz mjbvz closed this as completed Dec 6, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api markdown Markdown support issues
Projects
None yet
Development

No branches or pull requests

1 participant