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

@module-federation/node doesn't revalidate express #397

Closed
ilyassab opened this issue Nov 25, 2022 · 3 comments
Closed

@module-federation/node doesn't revalidate express #397

ilyassab opened this issue Nov 25, 2022 · 3 comments
Labels
no-issue-activity Node Node package identifier

Comments

@ilyassab
Copy link

ilyassab commented Nov 25, 2022

Hello
Awesome node plugin but I have troubles while revalidation.

Steps to reproduce problem:

  1. Download this repo https://github.com/module-federation/module-federation-examples/tree/master/server-side-rendering.
  2. Update @module-federation/node to 0.9.4
  3. Change webpack output from
output: {
    path: path.resolve(__dirname, "../dist/server"),
    filename: "[name].js",
    libraryTarget: "commonjs-module",
  }

to

output: {
    path: path.resolve(__dirname, "../dist/server"),
    filename: "[name].[chunkhash].js",
    libraryTarget: "commonjs-module",
  }

in remote1 and remote2 projects
4) Add new route '/revalidate' to shell like this:

app.get('/revalidate', async (req, res, next) => {
    revalidate();
    res.send();
  });
  1. Build and serve all the repos -> All is fine localhost:3000 starts serve all remotes and local files
  2. Change code in remote1 and rebuild remote1 project
  3. If you go to route '/revalidate', you will see this in server console
remote1 hash is different - must hot reload server

but nothing happens.
Only "fail while hydrating" errors in browser console

If I add route '/revalidation' like this

global.clearRoutes = () => {
    app._router.stack = app._router.stack.filter(
        k => !(k && k.route && k.route.path)
    )
  }

revalidate().then((shouldReload) => {
      if(shouldReload) {
        global.clearRoutes()
      }
    });

Express starts shows Get errors, because it has no routes after clearRoutes :)
image

What am I doing wrong?

@pavandv pavandv added the Node Node package identifier label Nov 27, 2022
@ScriptedAlchemy
Copy link
Member

You need to implement your own revalidation mechanism - I just provide the hook

@ScriptedAlchemy
Copy link
Member

If youre hitting revalidation after hot reload happens then you might be clearing the route stack out of sync so nothing gets reloaded into express. I do have standard ssr apps that demo this reloading concept, might be worth looking at those or sending me a repo

@github-actions
Copy link
Contributor

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-issue-activity Node Node package identifier
Projects
None yet
Development

No branches or pull requests

3 participants