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: allow building the app in prerendering by faking the page store during building #68

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

paoloricciuti
Copy link
Owner

@paoloricciuti paoloricciuti commented Feb 16, 2024

Closes #67

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue to enable app building in prerendering mode by simulating the page store.

Copy link

changeset-bot bot commented Feb 16, 2024

🦋 Changeset detected

Latest commit: a513350

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
sveltekit-search-params Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Feb 16, 2024

Walkthrough

This update introduces a significant enhancement to the handling of query parameters in SvelteKit applications, particularly focusing on improving the developer experience during prerendering. By adjusting the importation and usage of page stores and introducing a conditional assignment based on the build environment, the changes aim to address crashes related to accessing url.searchParams during prerendering, ensuring a smoother build process.

Changes

File Path Change Summary
src/lib/sveltekit-search-params.ts - Imported building flag and type { Page }
- Renamed page to page_store
- Added conditional assignment for page
.changeset/seven-hounds-help.md - Introduced documentation for fixing prerendering issue by faking the page store during build

Assessment against linked issues

Objective Addressed Explanation
Bug Description and Expected SSR Behavior (#67)
Reproduction Steps (#67) The PR does not include steps to reproduce the issue, as it focuses on code changes.
Error Logs and Environment (#67) The PR addresses the error indirectly through code changes but does not explicitly handle HTTP errors in configuration.

Poem

🐰 Oh hark! A fix so bright and keen,
Through code and logic, now unseen.
Prerender woes, they fade away,
With searchParams fixed, we say "Hooray!"
🌟 In SvelteKit lands, where bugs do roam,
A rabbit's work makes it feel like home.
🚀 So off we go, with code so spright,
To build, to dream, into the night.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

netlify bot commented Feb 16, 2024

Deploy Preview for sveltekit-search-params ready!

Name Link
🔨 Latest commit a513350
🔍 Latest deploy log https://app.netlify.com/sites/sveltekit-search-params/deploys/65cf7a3df09f2100081aab15
😎 Deploy Preview https://deploy-preview-68--sveltekit-search-params.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f4e0b9a and a513350.
Files selected for processing (2)
  • .changeset/seven-hounds-help.md (1 hunks)
  • src/lib/sveltekit-search-params.ts (1 hunks)
Additional comments: 6
.changeset/seven-hounds-help.md (1)
  • 1-5: The changeset description is clear and effectively communicates the purpose and impact of the patch. It succinctly explains how the fix allows building the app with prerendering by faking the page store during the building process.
src/lib/sveltekit-search-params.ts (5)
  • 3-3: The import of building from $app/environment is correctly implemented to determine if the app is in the build process. This is crucial for the conditional logic introduced later to fake the page store during building.
  • 5-5: Renaming page to page_store in the import statement improves clarity and avoids potential confusion with the page variable used later in the code. This is a good practice for code readability and maintainability.
  • 6-6: The addition of type imports for Page from @sveltejs/kit enhances type safety and clarity in the code, aligning with best practices for TypeScript development in SvelteKit projects.
  • 13-14: Importing Readable and readable from svelte/store is necessary for the implementation of the fake page store and adheres to Svelte's reactive programming model. This ensures the code remains consistent with Svelte's design principles.
  • 21-33: The conditional assignment of page based on the building flag is a clever solution to the prerendering issue. By faking the page store during the build process, it prevents the application from crashing due to inaccessible url.searchParams. This approach maintains client-side behavior post-build and addresses the core issue effectively. However, it's important to ensure that this workaround does not introduce unexpected side effects in the application's behavior during development or after deployment.

@paoloricciuti paoloricciuti merged commit cfe743d into master Feb 16, 2024
5 checks passed
@github-actions github-actions bot mentioned this pull request Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes with enabled prerendering
1 participant