Skip to content

errorLoadRemote runtime hook is getting overridden in nextjs-mf plugin #2039

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

Closed
5 tasks done
ryok90 opened this issue Jan 26, 2024 · 4 comments
Closed
5 tasks done

errorLoadRemote runtime hook is getting overridden in nextjs-mf plugin #2039

ryok90 opened this issue Jan 26, 2024 · 4 comments
Assignees
Labels
nextjs-mf nextjs-mf package identifier no-issue-activity

Comments

@ryok90
Copy link
Contributor

ryok90 commented Jan 26, 2024

Describe the bug

I am trying to use the new errorLoadRemote hook with the latest nextjs-mf plugin but I think the hook is getting overridden here and I am not being able to return a simple custom text to replace the component that failed to load.

image

I don't fully understand all the things that the internal runtimePlugin definition is doing but I would be willing to help if anyone can point me in the right direction.

Reproduction

https://github.com/ryok90/nextjs-mf-examples/tree/main/next14.1.0-mf8.1.7-error-hook

Used Package Manager

npm

System Info

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 55.41 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 8.14.2 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
  Browsers:
    Chrome: 120.0.6099.234
    Safari: 17.2.1

Validations

@benmarch
Copy link
Contributor

benmarch commented Feb 14, 2024

I'm curious what happens if there are two plugins that both declare a errorLoadRemote hook. This hook appears to be intended to resolve with a fallback module, but it doesn't appear to pass the module to the next handler like a middleware would. Does it just take the first/last one it finds and return it?

I'm wondering because I would like to add some custom logging for when a remote module doesn't load, but I can see that the default runtime plugin defined in nextjs-mf is already returning a fake module and I don't want to override that behavior.

UPDATE: it looks like it just takes the last one because I'm seeing the logs but I'm not returning a fake module so I'm getting a TypeError. Is there a way to pass the returned module from the previous plugin into the next so that I can use that if it's available?

UPDATE 2: I was able to do this, and it appears to work, but it makes the console pretty noisy due to the log statements in the nextjs-mf runtime plugin (could those be removed or put behind a flag?):

  async errorLoadRemote(args) {
    const { id, error, origin } = args

    // get the remote ID from the module ID
    const [remoteID] = id.split('/')

    // log the error
    log(remoteID, `Failed to get module "${id}". Returning empty module.`)
    console.log(error)

    // find the built-in NextJS runtime plugin
    const nextInternalPlugin = origin?.options?.plugins?.find?.(plugin => plugin.name === 'next-internal-plugin')    

    // if it's there, defer to the default error handling
    return nextInternalPlugin?.errorLoadRemote?.(args)
  }, 

@ScriptedAlchemy
Copy link
Member

yeah send me a pr removing them, happy to silence it.

also @2heal1 what are your thoughts about chaining or calling next() on runtime plugins if there's a case like this where multiple plugins call the same hooks?

Copy link
Contributor

github-actions bot commented May 6, 2024

Stale issue message

@ryok90
Copy link
Contributor Author

ryok90 commented May 6, 2024

Closing this one since my PR got merged.

@ryok90 ryok90 closed this as completed May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nextjs-mf nextjs-mf package identifier no-issue-activity
Projects
None yet
Development

No branches or pull requests

4 participants