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

Crossorigin on styles not getting set #7953

Closed
perljusback opened this issue Aug 21, 2020 · 1 comment · Fixed by #7954
Closed

Crossorigin on styles not getting set #7953

perljusback opened this issue Aug 21, 2020 · 1 comment · Fixed by #7954

Comments

@perljusback
Copy link

Error on credentials on preload for stylesheets in Chrome 84

image

Versions

  • nuxt: 2.14.3
    Mode: Universal
    Target: Server
  • node: 14.6.0

Reproduction

when using these render settings:

  render: {
    compressor: false,
    crossorigin: 'anonymous',
    http2: {
      push: true
    },
    resourceHints: true
  },

crossorigin gets set to the link header and to the preload link in the html:
image

image

but the stylesheet itself doesn't get the crossorigin markup:
image

Looking through the code it seems a replace is done for all the scripts:
https://github.com/nuxt/nuxt.js/blob/dev/packages/vue-renderer/src/renderers/ssr.js#L23

  renderScripts (renderContext) {
    const scripts = renderContext.renderScripts()
    const { render: { crossorigin } } = this.options
    if (!crossorigin) {
      return scripts
    }
    return scripts.replace(
      /<script/g,
      `<script crossorigin="${crossorigin}"`
    )
  }

and if we add a similar one for Styles

  renderStyles (renderContext) {
    const styles = renderContext.renderStyles();
    const { render: { crossorigin } } = this.options;
    if (!crossorigin) {
      return styles
    }
    return styles.replace(
      /<link/g,
      `<link crossorigin="${crossorigin}"`
    )
  }

and change:
https://github.com/nuxt/nuxt.js/blob/dev/packages/vue-renderer/src/renderers/ssr.js#L147

    // Inject styles
    HEAD += renderContext.renderStyles()

into

    // Inject styles
    HEAD += this.renderStyles(renderContext);

The error goes away

Thanks for all the great work.

@pi0
Copy link
Member

pi0 commented Aug 27, 2020

fixed by v2.14.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants