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(trpc): adding host and port env variables to nitro dev process & … #695

Merged
merged 1 commit into from
Oct 21, 2023

Conversation

goetzrobin
Copy link
Member

@goetzrobin goetzrobin commented Oct 5, 2023

…using them for trpc during dev

$fetch is smart enough to infer the host and port for our trpc client
when it is used on the server. However, $fetch is only available during
the pre-render phase and during SSR of the prod nitro server. It is not
available during development when we work with the vite server. This PR
adds the host & port from the vite server as env variables and uses them
as fallbacks. It also adjusts the Nx plugin's and trpc-app's vite config
files to make sure that the index page is server side rendered, but not
pre-rendered to avoid not displaying the latest data.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Which package are you modifying?

  • vite-plugin-angular
  • vite-plugin-nitro
  • astro-angular
  • create-analog
  • router
  • platform
  • content
  • nx-plugin
  • trpc

What is the current behavior?

Closes #

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

[optional] What gif best describes this PR or how it makes you feel?

@netlify
Copy link

netlify bot commented Oct 5, 2023

Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit 7df4901
🔍 Latest deploy log https://app.netlify.com/sites/analog-docs/deploys/6532cb83ca8e86000873aea9
😎 Deploy Preview https://deploy-preview-695--analog-docs.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.

@netlify
Copy link

netlify bot commented Oct 5, 2023

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit 7df4901
🔍 Latest deploy log https://app.netlify.com/sites/analog-blog/deploys/6532cb8331718b0008466b9b
😎 Deploy Preview https://deploy-preview-695--analog-blog.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.

@netlify
Copy link

netlify bot commented Oct 5, 2023

Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit 7df4901
🔍 Latest deploy log https://app.netlify.com/sites/analog-app/deploys/6532cb836390b40008817659
😎 Deploy Preview https://deploy-preview-695--analog-app.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.

packages/trpc/src/lib/client/client.ts Outdated Show resolved Hide resolved
packages/trpc/src/lib/client/client.ts Outdated Show resolved Hide resolved
packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts Outdated Show resolved Hide resolved
packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts Outdated Show resolved Hide resolved
…using them for trpc during dev

$fetch is smart enough to infer the host and port for our trpc client
when it is used on the server. However, $fetch is only available during
the pre-render phase and during SSR of the prod nitro server. It is not
available during development when we work with the vite server. This PR
adds the host & port from the vite server as env variables and uses them
as fallbacks. It also adjusts the Nx plugin's and trpc-app's vite config
files to make sure that the index page is server side rendered, but not
pre-rendered to avoid not displaying the latest data.
@goetzrobin goetzrobin marked this pull request as ready for review October 20, 2023 19:08
@goetzrobin
Copy link
Member Author

@brandonroberts I am not crazy and this should finally allow for relative paths to be used with trpc as well as giving you a setup that by default server renders the index page with tRPC so the latest data is always shown...

Copy link
Member

@brandonroberts brandonroberts left a comment

Choose a reason for hiding this comment

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

🚀

@brandonroberts brandonroberts merged commit bd013fe into main Oct 21, 2023
19 checks passed
@brandonroberts brandonroberts deleted the trpc-fetch-improvements branch October 21, 2023 02:51
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.

None yet

2 participants