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

imported modules in API routes not reloading changes in development mode #1104

Closed
thescientist13 opened this issue May 1, 2023 · 0 comments · Fixed by #1105
Closed

imported modules in API routes not reloading changes in development mode #1104

thescientist13 opened this issue May 1, 2023 · 0 comments · Fixed by #1105
Assignees
Labels
bug Something isn't working CLI P0 Critical issue that should get addressed ASAP SSR v0.28.2
Milestone

Comments

@thescientist13
Copy link
Member

Type of Change

Bug

Summary

While editing an API route and changing its contents works, if there is a module loaded in that API route that gets changed, the contents won't change.

api-routes-full-live-reloading-broken.mov

Details

This seems to be an ESM related caching issue, similar to the one we ran into when implementing the same feature for SSR pages, since we are using import programmatically for API routes too

async serve(url, request) {
  const api = this.compilation.manifest.apis.get(url.pathname);
  const apiUrl = new URL(`.${api.path}`, this.compilation.context.userWorkspace);
  // https://github.com/nodejs/node/issues/49442
  const href = process.env.__GWD_COMMAND__ === 'develop' // eslint-disable-line no-underscore-dangle
    ? `${apiUrl.href}?t=${Date.now()}`
    : apiUrl.href;

  const { handler } = await import(href);
  const req = new Request(new URL(`${request.url.origin}${url}`), {
    ...request
  });

It seems like we'll have to do some sort of Workers related work around here as well, at least until a more robust ESM cache busting solution is available in NodeJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CLI P0 Critical issue that should get addressed ASAP SSR v0.28.2
Projects
No open projects
1 participant