You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My understanding is that this would cause the About component to only be imported on the client side and thus never executed on the server side. However I have a console.log statement in the About component that prints out on the server side.
My imported.js file looks like this:
/* eslint-disable */
/* tslint:disable */
// generated by react-imported-component, DO NOT EDIT
import {assignImportedComponents} from 'react-imported-component/macro';
// all your imports are defined here
// all, even the ones you tried to hide in comments (that's the cost of making a very fast parser)
// to remove any import from here
// 1) use magic comment `import(/* client-side */ './myFile')` - and it will disappear
// 2) use file filter to ignore specific locations (refer to the README)
const applicationImports = assignImportedComponents([
[() => import(/* client-side */'./About'), '', './app/About', true],
]);
export default applicationImports;
// @ts-ignore
if (module.hot) {
// these imports would make this module a parent for the imported modules.
// but this is just a helper - so ignore(and accept!) all updates
// @ts-ignore
module.hot.accept(() => null);
}
I find the following confusing. In the imported.js comment number 1), it says if I use the magic comment /* client-side */ it would disappear from the file, however as you can see it doesn't.
On the other hand if I understood correctly, in __tests__/utils.spec.tsline 21 the test checks that a client-side import should be mapped to the value at line 30.
Can you please advise as to which behaviour from the above is expected, and how to get client-side only imports to work? Thank you
The text was updated successfully, but these errors were encountered:
"client-side" magic comment is suppressing import auto execution on the server side - by default all found import would be called before the render, so you will be able to render your application synchronously, and not all components could be run on a server.
However that would not block those modules/components from being used - you still can try to render them, and they will be rendered.
Here you need something like NoSSR in Material-UI.
constNoSSR=({children})=>{const[locked,setLocked]=useState(true);useEffect(()=>setLocked(false),[]);// unlock on the client-sidereturnlocked ? null : children;}
I'm trying out react-imported-component in a demo app before using it in a production app, and hit the following block.
I have an
About
component that I'm importing as follows:My understanding is that this would cause the
About
component to only be imported on the client side and thus never executed on the server side. However I have aconsole.log
statement in the About component that prints out on the server side.My
imported.js
file looks like this:I find the following confusing. In the
imported.js
comment number 1), it says if I use the magic comment/* client-side */
it would disappear from the file, however as you can see it doesn't.On the other hand if I understood correctly, in
__tests__/utils.spec.ts
line 21 the test checks that a client-side import should be mapped to the value at line 30.Can you please advise as to which behaviour from the above is expected, and how to get client-side only imports to work? Thank you
The text was updated successfully, but these errors were encountered: