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

fix(nuxt): skip payload extraction for island context #20590

Merged
merged 1 commit into from Apr 30, 2023

Conversation

harlan-zw
Copy link
Contributor

πŸ”— Linked issue

nuxt-modules/og-image#35

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

When prerendering a Nuxt app that uses Nuxt Islands components, the home page payload will be reset whenever an Island component is rendered.

The consequence of this for prerendered static Nuxt apps is that any data fetching required for the home page won't work, potentially breaking the page.

Reproduction

https://stackblitz.com/edit/nuxt-starter-iqevpt?file=pages/z.vue

  • nuxi generate
  • cat .output/public/_payload.js (you'll see export default {data:{},prerenderedAt:1682833083825} which is not correct)
  • npx sirv-cli .output/public/, you'll see the posts can't load

The expected output for the payload is:

export default {data:{T6SB1FMcRf:[{title:"10 Tips for Writing Clean JavaScript Code",slug:"10-tips-for-writing-clean-javascript-code"},{title:"How to Build a Responsive Website with Bootstrap 5",slug:"how-to-build-a-responsive-website-with-bootstrap-5"},{title:"Introduction to Machine Learning with Python",slug:"introduction-to-machine-learning-with-python"}]},prerenderedAt:1682833610711}

Issue / Solution

The issue seems to be related to the island context being given the / path and allowed to generate payloads. By ignoring payload extraction for island components we can get around this issue.

An alternative solution may be to change the given path, but not sure if this will have unexpected consequences.

There may be a better solution than these two so please advise.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Apr 30, 2023

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@danielroe danielroe merged commit d2170b8 into main Apr 30, 2023
17 checks passed
@danielroe danielroe deleted the fix/island-prerendering-payload-bug branch April 30, 2023 09:10
@github-actions github-actions bot mentioned this pull request Apr 30, 2023
@github-actions github-actions bot mentioned this pull request May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants