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.

The `inject`/`injectProperty` settings aren't causing an object to be injected.

See original GitHub issue

I’m trying to use the plugin with the following configuration.

    new PrerenderSPAPlugin({
      injectProperty: 'prerenderSettings',
      inject: {
        myProperty: true,
      },
    }),

My understanding of these settings is that window.prerenderSettings should be set to { myProperty: true } before rendering my pages during the build. My pages are otherwise prerendering correctly, but window.prerenderSettings is undefined. I double checked this by adding the following code to my application.

document.body.innerHTML = `${document.body.innerHTML}<p id="prerender-settings">${window.prerenderSettings}</p>`;

After building with WebPack, the generated HTML includes a <p id="prerender-settings">undefined</p> tag. To clarify, this is the raw HTML file that’s being output by prerender-spa-plugin, I’m not opening the file in another web browser and causing a second tag to get injected.

This is with version 3.1.0.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
JoshTheDerfcommented, May 24, 2018

Hi @sangaline, prerender-spa-plugin 3.x introduces pluggable renderers with distinct features. inject is one such feature, so you need to configure it on the specific renderer rather than the root plugin config, like so:

new PrerenderSPAPlugin({
  renderer: new PrerenderSPAPlugin.PuppeteerRenderer({
    injectProperty: 'prerenderSettings',
    inject: { myProperty: true, },
  }),
})

Hope that helps!

1reaction
JoshTheDerfcommented, Jun 5, 2018

Noted. I’ll probably address it in the next update then. Thanks for the input!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Method Injection - Manning
This article delves into the Method Injection DI Pattern: how it works, and when and why you might want to use it.
Read more >
Injecting Property Values Into Configuration Beans
Spring Framework has a good support for injecting property values found from properties files into bean or @Configuration classes.
Read more >
What exactly is Field Injection and how to avoid it?
The reasons why field injection is frowned upon are as follows: You cannot create immutable objects, as you can with constructor injection ...
Read more >
Dependency injection guidelines - .NET | Microsoft Learn
This article provides general guidelines and best practices for implementing dependency injection in .NET applications.
Read more >
3.4.1.1 Constructor-based dependency injection - Spring
Configuration metadata can be specified via XML, Java code or annotations. For each bean, its dependencies are expressed in the form of properties,...
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