Skip to content

Commit

Permalink
chore: try window object
Browse files Browse the repository at this point in the history
  • Loading branch information
JBR90 committed Dec 17, 2024
1 parent e6add52 commit c4a5ac5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
2 changes: 2 additions & 0 deletions apps/nextjs/src/hooks/useReactScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const useReactScan = <T extends object>(
const isRenderScanEnabled =
(typeof process !== "undefined" &&
process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN === "true") ||
(typeof window !== "undefined" &&
window.NEXT_PUBLIC_ENABLE_RENDER_SCAN === "true") ||
(typeof window !== "undefined" &&
window.process?.env?.NEXT_PUBLIC_ENABLE_RENDER_SCAN === "true");
if (isRenderScanEnabled) {
Expand Down
64 changes: 37 additions & 27 deletions apps/nextjs/tests-e2e/tests/chat-performance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,34 @@ test.describe("Component renders during lesson chat", () => {
const login = await prepareUser(page, "typical");

await page.addInitScript(() => {
window.process = {
...window.process,
env: {
...window.process?.env,
NEXT_PUBLIC_ENABLE_RENDER_SCAN: "true",
},
};
window.NEXT_PUBLIC_ENABLE_RENDER_SCAN = "true";
});
await page.addInitScript(() => {
console.log("Window object:", typeof window);
console.log("Process object:", typeof window.process);
console.log("Existing env:", window.process?.env);

if (typeof window !== "undefined") {
window.process = window.process || {};
window.process.env = window.process.env || {};
window.process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN = "true";
}
// await page.addInitScript(() => {
// window.process = {
// ...window.process,
// env: {
// ...window.process?.env,
// NEXT_PUBLIC_ENABLE_RENDER_SCAN: "true",
// },
// };
// });
// await page.addInitScript(() => {
// console.log("Window object:", typeof window);
// console.log("Process object:", typeof window.process);
// console.log("Existing env:", window.process?.env);

console.log(
"Set env:",
window.process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN,
);
});
// if (typeof window !== "undefined") {
// window.process = window.process || {};
// window.process.env = window.process.env || {};
// window.process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN = "true";
// }

// console.log(
// "Set env:",
// window.process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN,
// );
// });

await page.goto(`${TEST_BASE_URL}/aila/${login.chatId}`);
await isFinished(page);
Expand All @@ -58,12 +62,18 @@ test.describe("Component renders during lesson chat", () => {
});

async function verifyChatInputRenders(page: Page) {
console.log("env.", process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN);
if (typeof window !== "undefined") {
window.process = window.process || {};
window.process.env = window.process.env || {};
window.process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN = "true";
}
// console.log("env.", process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN);
// if (typeof window !== "undefined") {
// window.process = window.process || {};
// window.process.env = window.process.env || {};
// window.process.env.NEXT_PUBLIC_ENABLE_RENDER_SCAN = "true";
// }

console.log("Checking injected flag...");
const renderScanEnabled = await page.evaluate(
() => window.NEXT_PUBLIC_ENABLE_RENDER_SCAN,
);
console.log("Render Scan Enabled:", renderScanEnabled); // Debug check

await page.waitForFunction(
() =>
Expand Down

0 comments on commit c4a5ac5

Please sign in to comment.