Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/ssr/ssr-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export const SSRModule = (config: string | InjectableConfig & { name: string })
let name: string
if (typeof config === 'string') {
if (configSets.has(config)) {
throw new Error(`Duplicated Module name: ${config}`)
reportDuplicated(config)
}
name = config
configSets.add(config)
} else if (config && typeof config.name === 'string') {
if (configSets.has(config.name)) {
throw new Error(`Duplicated Module name: ${config.name}`)
reportDuplicated(config.name)
}
configSets.add(config.name)
name = config.name
Expand All @@ -33,3 +33,11 @@ export const SSRModule = (config: string | InjectableConfig & { name: string })
return Injectable(injectableConfig)(target)
}
}

function reportDuplicated(moduleName: string) {
if (process.env.NODE_ENV === 'production') {
throw new Error(`Duplicated Module name: ${moduleName}`)
}
// avoid to throw error after HMR
console.warn(`Duplicated Module name: ${moduleName}`)
}
5 changes: 5 additions & 0 deletions test/specs/ssr.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ describe('SSR specs:', () => {
beforeAll(() => {
// @ts-ignore
process.env.ENABLE_AYANAMI_SSR = 'true'
process.env.NODE_ENV = 'production'
})

afterAll(() => {
// @ts-ignore
process.env.ENABLE_AYANAMI_SSR = 'false'
delete process.env.NODE_ENV
})

it('should throw if module name not given', () => {
Expand Down Expand Up @@ -172,6 +174,9 @@ describe('SSR specs:', () => {
expect(generateException1).toThrow()
expect(generateException2).toThrow()
expect(generateException3).toThrow()
process.env.NODE_ENV = 'development'
expect(generateException1).not.toThrow()
expect(generateException2).not.toThrow()
})

it('should run ssr effects', async () => {
Expand Down