question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Ability to render the editor in an iframe

See original GitHub issue

I’m trying to render the editor inside an iframe (via a react portal), but it’s not working and I suspect this is due to the fact that it’s referencing the global window object for selection state, etc. I’d like to be able to pass a custom window object (the iframe window)

One solution is to provide the window object in a react context. It can be passed in via an optional prop to the RichTextPlugin or PlainTextPlugin (or maybe even LexicalComposer) and would default to window.

Alternatively, Slate reads the window from the contentEditable DOM node. So if you have a ref to that DOM node, you can look up it’s parent window with something like…

contentEditableNode.current.ownerDocument.defaultView

We can expose this as a helper and replace all references to the global window with the helper like Slate…

https://github.com/ianstormtaylor/slate/blob/main/packages/slate-react/src/plugin/react-editor.ts#L54-L64

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
trueadmcommented, Dec 17, 2022
2reactions
darabuncommented, Nov 8, 2022

I’m trying to get this working but can’t seem to get it to work when it’s in the iframe.

I have it reproduced here: https://codesandbox.io/s/aged-frog-iu8ff7

It works when outside of the iframe but not when inside it. Is there something obvious that I’m doing wrong?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rendering in an iframe in a React app - DEV Community ‍ ‍
The normal way to do it is to add the src attribute with the URL of the app that will run in it....
Read more >
The ultimate guide to iframes - LogRocket Blog
We'll go through most of the features the iframe element provides and talk about how you use them, as well as how iframe...
Read more >
Create-React-App creates this <iframe> that prevents me from ...
I have to delete this iframe to edit the elements directly from the browser but can't think why this is rendering each time...
Read more >
IFrame Rendering in JavaScript RichTextEditor control
The editor allows you to pass an additional attribute to body tag of a <iframe> element using attributes fields of iframeSettings property. The...
Read more >
From object to iframe — other embedding technologies
<iframe> s are for embedding other web pages, and the other two allow you to embed external resources such as PDF files. Prerequisites:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found