Skip to content

Commit

Permalink
strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alextaing committed Oct 30, 2023
1 parent fc31076 commit bbc69c3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/test-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"tailwindcss": "^3.3.4"
},
"scripts": {
"dev": "studio",
"dev": "studio --strict",
"localData": "yext pages generate-test-data -a",
"start": "craco start",
"build-test-site": "craco build"
Expand Down
2 changes: 2 additions & 0 deletions packages/studio-plugin/src/types/CliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export interface CliArgs {
port?: string;
// The project root for studio.
root?: string;
// Whether or not to run Studio in React Strict Mode
strict?: boolean;
// Any arguments present after double dashes when invoking studio, e.g.
// `npx studio -- args like these` will result in ['args', 'like', 'these']
// Not currently used for anything but always provided by the cac package
Expand Down
10 changes: 9 additions & 1 deletion packages/studio/bin/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ cli
.command("", "start dev server")
.option("--port <port>", "[number] port to run studio")
.option("--root <directory>", `[string] path to the root directory`)
.option("--strict", "Runs Studio in React Strict Mode")
.action((options: CliArgs) => {
const YEXT_STUDIO_ARGS = JSON.stringify({
"--": options["--"],
port: options.port,
root: options.root
})

spawnSync(
"npx",
[
Expand All @@ -31,7 +38,8 @@ cli
stdio: ["ignore", "inherit", "inherit"],
env: {
...process.env,
YEXT_STUDIO_ARGS: JSON.stringify(options),
YEXT_STUDIO_ARGS,
VITE_STUDIO_STRICT: String(options.strict)
},
shell: true,
}
Expand Down
9 changes: 6 additions & 3 deletions packages/studio/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ if (import.meta.hot) {
void hotReloadGitData(hmrPayload);
});
}
const WrappedApp = import.meta.env.VITE_STUDIO_STRICT === "true"
? <React.StrictMode>
<AppWithLazyLoading />
</React.StrictMode>
: <AppWithLazyLoading />

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<AppWithLazyLoading />
</React.StrictMode>
WrappedApp
);

0 comments on commit bbc69c3

Please sign in to comment.