vitejs / vite-plugin-react

The all-in-one Vite plugin for React projects.
MIT License
546 stars 102 forks source link

test: test SSR after HMR #326

Closed hi-ogawa closed 1 month ago

hi-ogawa commented 1 month ago

Description

I added a test to check ssrLoadModule correctly reflects the same change as client HMR. I verified this fails on 6.0.0-alpha.17 but passes on v5. cc @patak-dev @sheremet-va

Technically this is purely a ssrLoadModule concern (probably I can write a similar failing test without React), but I think it's still nice to test it in the context of React SSR (for example, on RSC framework, it also requires framework side code to make sure server side module is invalidated correctly on top of ssrLoadModule or new module runner).

Additional context


What is the purpose of this pull request?

Before submitting the PR, please make sure you do the following

ArnaudBarre commented 1 month ago

It's already failing! Maybe there is already an issue in v5?

hi-ogawa commented 1 month ago

Oh well, it looks like hmr test is also running in test-build, so it's expected to fail. I added test.skipIf(isBuild) to skip this. https://github.com/vitejs/vite-plugin-react/pull/326/commits/11250e078a21a826fe47cabfcb7a69b187bafb86

The reason why it was passing before is because untilUpdated assertion is actually no-op during build: https://github.com/vitejs/vite-plugin-react/blob/11250e078a21a826fe47cabfcb7a69b187bafb86/playground/test-utils.ts#L92-L97

ArnaudBarre commented 1 month ago

Thanks a lot @hi-ogawa!