gregberge / loadable-components

The recommended Code Splitting library for React ✂️✨
https://loadable-components.com
MIT License
7.7k stars 382 forks source link

Server is caching old request split chunks, and these are not being re-requested when a new request is made to the server. #1007

Open RishabJS opened 7 months ago

RishabJS commented 7 months ago

🐛 Bug Report

Server is not emitting fresh split chunks on new requests; instead, it is caching the chunks from previous requests and merging them with the new ones

Project Dependencies React: 18 React-router: 6.18 Loadable: 5.16 Node: 16.17 NPM: 8.15

To Reproduce

Steps to reproduce the behavior: when server is made up on first request all the split chunks are emitted correctly (url:http://localhost:5000/artist/unknown/6214cdf1f83bd744e8ab2851?pageId=artistDetail) ->

Screenshot 2024-04-23 at 2 38 54 PM

on second request to different url (http://localhost:5000/account-deletion), previous req chunk () is also made with new chunks ->

Screenshot 2024-04-23 at 2 53 50 PM

Implementation Details->

SSR implementation:

Screenshot 2024-04-23 at 3 02 04 PM

Element Render component

Screenshot 2024-04-23 at 3 02 56 PM

CSR Implementation

Screenshot 2024-04-23 at 3 04 36 PM

It has been observed that in chunkExtractor.js of @loadable/server, the class variable this.chunks retains the previous chunks in its list when a new HTML is returned upon requesting a new URL

Screenshot 2024-04-23 at 3 07 15 PM

Expected behavior

The server should emit all necessary split chunks on each new request, and it should not cache the chunks from previous requests

In the above snippets static/js/artist.a7a73238.js chunk should not be emitted by the server as it doesn't belong to the currently requested url

Link to repl or repo (highly encouraged)

Please provide a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --system --binaries --npmPackages @loadable/component,@loadable/server,@loadable/webpack-plugin,@loadable/babel-plugin --markdown --clipboard

Paste the results here: