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.

Custom components not allowed in dynamic rendering

See original GitHub issue

OS: Mac OS 10.13.6

React-pdf version: 1.0.0-alpha.25

Description: When trying to use my own custom components within a dynamic render, I get the following error:

Error: Invalid element of type <TYPE>
    at createInstance (/node_modules/@react-pdf/renderer/src/elements/index.js:30:9)
    at Page$1.createInstance [as addDynamicChild] (/node_modules/@react-pdf/renderer/src/elements/Page.js:114:26)
    at Page$1.addDynamicChild (/node_modules/@react-pdf/renderer/src/elements/Page.js:118:20)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Looking at the source code, I see that only the basic components included with the library are whitelisted for use within dynamic rendering. I’m not sure what the constraints are there but it feels very limiting to not allow custom components, given the prevalence of this pattern in React.

How to replicate issue including code snippet (if applies): Put any custom component inside a dynamic render function:

const MyCustomComponent = props => <Text>{props.children}</Text>;
const DynamicallyRenderedComponent = props => (
  <View
    render={({ pageNumber }) => (
      <MyCustomComponent>
         This will throw an error 
      </MyCustomComponent>
    )}
  />
);

You can make use of react-pdf REPL to share the snippet

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
aautemcommented, Jan 28, 2020

Unfortunately the way we are doing dynamic rendering right now does support that, it’s true. That’s because we have to create elements in render time and it’s only possible to create primitives nodes.

@diegomura Any update on this? Would be an awesome feature. I’d love to help but don’t completely understand the issue. Why is it only possible to create primitive nodes in render time? My custom component just renders a few primitives so there’s something I’m missing here.

3reactions
diegomuracommented, Nov 20, 2018

😓 sorry. I missed the fact that this was happening on dynamic render. My bad haha. I have too many things in my head.

Unfortunately the way we are doing dynamic rendering right now does support that, it’s true. That’s because we have to create elements in render time and it’s only possible to create primitives nodes.

Maybe what we can do is running the reconciler only over that part of the tree, but not sure how it will work. I can’t promise either when I’ll be able to test it.

I understand that dynamic rendering may be handy for a bunch different scenarios, but it’s very trick to set up for all of them. It was created mainly for page numbers and if statements, but not thinking of rendering custom components. Would be great to make it more powerful. If you like, you can give it a shot 😄 I’ll be happy to assist you on the process

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to dynamically render custom react components ...
I am trying to fetch data from the backend and then render a custom component with props as the data fetched from ...
Read more >
Lightning component not rendering dynamically created ...
The problem is that it is very slow to render when I click the "Create Component" button, if I'm lucky. Usually nothing shows...
Read more >
Dynamic Rendering | Google Search Central | Documentation
Dynamic rendering is a workaround for websites where JavaScript-generated content is not available to search engines. A dynamic rendering server detects ...
Read more >
Dynamic Lightning Pages - Salesforce Help
No need to do anything to your custom components. It's all handled by the Lightning App Builder. On record pages, you can choose...
Read more >
Customizing CMS Components - Spartacus Documentation
CMS components are dynamically added at runtime. ... This allows you to configure a custom component to render a specific CMS component.
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